Skip to content

Commit

Permalink
Fixes resource specs
Browse files Browse the repository at this point in the history
The dummy apps `Event` model has a `belongs_to` `Location` relation that is mandatory since Rails 5.1. This changes the specs so we always have a location for an event.
  • Loading branch information
tvdeyen committed Sep 7, 2017
1 parent 91826f4 commit 5a0f167
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
13 changes: 7 additions & 6 deletions spec/controllers/alchemy/admin/resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController

describe '#index' do
let(:params) { Hash.new }
let!(:peter) { Event.create(name: 'Peter') }
let!(:lustig) { Event.create(name: 'Lustig') }
let!(:peter) { create(:event, name: 'Peter') }
let!(:lustig) { create(:event, name: 'Lustig') }

before do
authorize_user(:as_admin)
Expand All @@ -33,7 +33,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController
end

context "but searching for record with certain association" do
let(:bauwagen) { Location.create(name: 'Bauwagen') }
let(:bauwagen) { create(:location, name: 'Bauwagen') }
let(:params) { {q: {name_or_hidden_name_or_location_name_cont: "Bauwagen"}} }

before do
Expand All @@ -52,7 +52,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController

describe '#update' do
let(:params) { {q: 'some_query', page: 6} }
let!(:peter) { Event.create(name: 'Peter') }
let!(:peter) { create(:event, name: 'Peter') }

it 'redirects to index, keeping the current location parameters' do
post :update, params: {id: peter.id, event: {name: "Hans"}}.merge(params)
Expand All @@ -62,16 +62,17 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController

describe '#create' do
let(:params) { {q: 'some_query', page: 6} }
let!(:location) { create(:location) }

it 'redirects to index, keeping the current location parameters' do
post :create, params: {event: {name: "Hans"}}.merge(params)
post :create, params: {event: {name: "Hans", location_id: location.id}}.merge(params)
expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q=some_query")
end
end

describe '#destroy' do
let(:params) { {q: 'some_query', page: 6} }
let!(:peter) { Event.create(name: 'Peter') }
let!(:peter) { create(:event, name: 'Peter') }

it 'redirects to index, keeping the current location parameters' do
delete :destroy, params: {id: peter.id}.merge(params)
Expand Down
5 changes: 5 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
factory :event do
name 'My Event'
hidden_name 'not shown'
location
starts_at DateTime.new(2012, 03, 02, 8, 15)
ends_at DateTime.new(2012, 03, 02, 19, 30)
lunch_starts_at DateTime.new(2012, 03, 02, 12, 15)
Expand All @@ -10,4 +11,8 @@
published false
entrance_fee 12.3
end

factory :location do
name 'Awesome Lodge'
end
end
3 changes: 3 additions & 0 deletions spec/features/admin/resources_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ def reload_event_class

describe "create resource item" do
context "when form filled with valid data" do
let!(:location) { create(:location) }

before do
visit '/admin/events/new'
fill_in 'event_name', with: 'My second event'
fill_in 'event_starts_at', with: DateTime.new(2012, 03, 03, 20, 00)
select location.name, from: 'Location'
click_on 'Save'
end

Expand Down

0 comments on commit 5a0f167

Please sign in to comment.