Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
Fix ElementNotFound feature test intermittent failure
Browse files Browse the repository at this point in the history
Resolves #1514
  - Only create a second equipment model and item when necessary in
    feature specs
  - Replace nearly all AppConfig creations in tests with a mocked
    AppConfig
  - Get rid of most before(:all) callbacks
  - Minor refactor of a reservations controller spec
  • Loading branch information
Sydney Young committed May 31, 2016
1 parent 5e73c7d commit ecdf95b
Show file tree
Hide file tree
Showing 30 changed files with 160 additions and 196 deletions.
4 changes: 1 addition & 3 deletions spec/controllers/announcements_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
end

describe AnnouncementsController, type: :controller do
before(:all) do
@app_config = FactoryGirl.create(:app_config)
end
before(:each) { mock_app_config }

describe 'with admin' do
before do
Expand Down
3 changes: 0 additions & 3 deletions spec/controllers/app_configs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@
end
end
context 'app_config does not exist yet' do
before(:all) do
AppConfig.destroy_all
end
before(:each) do
sign_in FactoryGirl.create(:user)
post :update
Expand Down
4 changes: 1 addition & 3 deletions spec/controllers/blackouts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
end

describe BlackoutsController, type: :controller do
before(:all) do
@app_config = FactoryGirl.create(:app_config)
end
before(:each) { mock_app_config }

describe 'with admin' do
before do
Expand Down
7 changes: 1 addition & 6 deletions spec/controllers/categories_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require 'spec_helper'

describe CategoriesController, type: :controller do
before(:all) do
@app_config = FactoryGirl.create(:app_config)
end
before(:each) do
mock_app_config
@category = FactoryGirl.create(:category)
end

Expand Down Expand Up @@ -186,7 +184,4 @@
end
end
end
after(:all) do
@app_config.destroy
end
end
17 changes: 8 additions & 9 deletions spec/controllers/contact_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
require 'spec_helper'

describe ContactController, type: :controller do
before(:all) do
@app_config = FactoryGirl.create(:app_config)
end
before(:each) do
@category = FactoryGirl.create(:category)
sign_in FactoryGirl.create(:user)

# goes after the above to skip certain user validations
@ac = mock_app_config(contact_email: 'contact@email.com',
admin_email: 'admin@email.com',
site_title: 'Reservations Specs')
end
describe 'GET new' do
before(:each) do
Expand Down Expand Up @@ -48,8 +50,8 @@
end
context 'with contact e-mail set' do
before do
AppConfig.first
.update_attributes(contact_link_location: 'contact@example.com')
allow(@ac).to receive(:contact_link_location)
.and_return('contact@example.com')
post :create, message: FactoryGirl.attributes_for(:message)
end

Expand All @@ -60,7 +62,7 @@
end
context 'with contact e-mail not set' do
before do
AppConfig.first.update_attributes(contact_link_location: '')
allow(@ac).to receive(:contact_link_location).and_return('')
post :create, message: FactoryGirl.attributes_for(:message)
end

Expand All @@ -69,7 +71,4 @@
include(AppConfig.first.admin_email)
end
end
after(:all) do
@app_config.destroy
end
end
4 changes: 1 addition & 3 deletions spec/controllers/equipment_items_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe EquipmentItemsController, type: :controller do
before(:all) { @app_config = FactoryGirl.create(:app_config) }
before(:each) { mock_app_config }
let!(:item) { FactoryGirl.create(:equipment_item) }
let!(:deactivated_item) { FactoryGirl.create(:deactivated) }

Expand Down Expand Up @@ -342,6 +342,4 @@
end
end
end

after(:all) { @app_config.destroy }
end
4 changes: 1 addition & 3 deletions spec/controllers/equipment_models_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
end

describe EquipmentModelsController, type: :controller do
before(:all) { @app_config = FactoryGirl.create(:app_config) }
before(:each) { mock_app_config }
let!(:model) { FactoryGirl.create(:equipment_model) }

it_behaves_like 'calendarable', EquipmentModel
Expand Down Expand Up @@ -415,6 +415,4 @@
end
end
end

after(:all) { @app_config.destroy }
end
4 changes: 1 addition & 3 deletions spec/controllers/import_users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
end

describe ImportUsersController, type: :controller do
before(:all) do
@app_config = FactoryGirl.create(:app_config)
end
before(:each) { mock_app_config }

before(:each) do
sign_in FactoryGirl.create(:admin)
Expand Down
11 changes: 4 additions & 7 deletions spec/controllers/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

describe ReportsController, type: :controller do
before(:all) do
@app_config = FactoryGirl.create(:app_config)
@user = FactoryGirl.create(:user)
@banned = FactoryGirl.create(:banned)
@checkout_person = FactoryGirl.create(:checkout_person)
@admin = FactoryGirl.create(:admin)
end

after(:all) do
AppConfig.delete_all
User.delete_all
end

context 'as admin user' do
before(:each) { sign_in @admin }
before(:each) do
mock_app_config
sign_in @admin
end

describe 'PUT /reports/update' do
it 'defaults to the past year without a session or params' do
Expand Down
7 changes: 1 addition & 6 deletions spec/controllers/requirements_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
# -- namely, it was necessary to test two contexts for each method: the user
# being an admin, and not.
describe RequirementsController, type: :controller do
before(:all) do
@app_config = FactoryGirl.create(:app_config)
end
before(:each) do
mock_app_config
@requirement = FactoryGirl.create(:requirement, contact_name: 'Adam Bray')
end
describe 'GET index' do
Expand Down Expand Up @@ -212,7 +210,4 @@
end
end
end
after(:all) do
@app_config.destroy
end
end
Loading

0 comments on commit ecdf95b

Please sign in to comment.