diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index 961f6463..d1845584 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -13,11 +13,15 @@ describe Admin::ConferenceController do let(:participant) { create(:participant) } shared_examples 'access as administration or organizer' do + describe 'PATCH #update' do + context 'valid attributes' do + it 'locates the requested conference' do patch :update, id: conference.short_title, conference: attributes_for(:conference, title: 'Example Con') + expect(assigns(:conference)).to eq(conference) end @@ -192,7 +196,7 @@ describe Admin::ConferenceController do describe 'administrator access' do - before(:each) do + before do sign_in(admin) end diff --git a/spec/features/sponsor_spec.rb b/spec/features/sponsor_spec.rb index b6678668..24998340 100644 --- a/spec/features/sponsor_spec.rb +++ b/spec/features/sponsor_spec.rb @@ -12,6 +12,7 @@ feature Sponsor do conference = create(:conference) conference.sponsorship_levels << create(:sponsorship_level, conference: conference) sign_in create(user) + visit admin_conference_sponsors_path( conference_id: conference.short_title) # Add sponsors @@ -36,6 +37,7 @@ feature Sponsor do find(:css, "select[id^='conference_sponsors_attributes_']"\ "[id$='_sponsorship_level_id']"). find(:option, 'Platin').select_option + click_button 'Update Conference' expect(flash).to eq('Sponsorships were successfully updated.') @@ -55,7 +57,7 @@ feature Sponsor do value).to eq('http://www.example.com') expect(find('div.nested-fields:nth-of-type(1)'\ - ' div:nth-of-type(5) select:nth-of-type(1)'). + ' div:nth-of-type(5) select:nth-of-type(1)').find('option[selected]'). text).to eq('Platin') # Remove sponsor diff --git a/spec/features/volunteers_spec.rb b/spec/features/volunteers_spec.rb index df696adf..bc1e6d76 100644 --- a/spec/features/volunteers_spec.rb +++ b/spec/features/volunteers_spec.rb @@ -103,9 +103,10 @@ feature Conference do expect(find('div.vpositions div.nested-fields:nth-of-type(1)'\ ' div:nth-of-type(2) textarea'). value).to eq('Example Description') + expect(find('div.vpositions div.nested-fields:nth-of-type(1)'\ - ' div:nth-of-type(3) select:nth-of-type(1)'). - text).to eq("#{Date.today.strftime}") + ' div:nth-of-type(3) select:nth-of-type(1)').find('option[selected]'). + text).to eq(Date.today.strftime) # Remove vposition click_link 'Remove vposition' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0776c1b8..f6f3859f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,12 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' +# To avoid confusion on missed migrations - use Rails 4 checker to ensure +# all migrations applied +ActiveRecord::Migration.maintain_test_schema! + +# Add poltergeist to use it as JS driver +require 'capybara/poltergeist' # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are @@ -24,9 +30,6 @@ RSpec.configure do |config| # config.mock_with :flexmock # config.mock_with :rr - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" - # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. @@ -38,33 +41,44 @@ RSpec.configure do |config| # --seed 1234 config.order = 'random' - # Include factory_girls syntax + # Setting up DB cleaning to maintain empty rows + config.before(:suite) do + DatabaseCleaner.strategy = :transaction + DatabaseCleaner.clean_with(:truncation) + end + + config.around(:each) do |example| + DatabaseCleaner.cleaning do + example.run + end + end + + # poltergeist as a underlying mech for Capybara + Capybara.javascript_driver = :poltergeist + + # Includes helpers and connect them to specific types of tests config.include FactoryGirl::Syntax::Methods - - # Enables devise sign_in function + config.include OmniauthMacros config.include Devise::TestHelpers, type: :controller - - # Enables devise sign_in function - config.include Devise::TestHelpers, type: :view - - # Use capybara-webkit as default javascript driver - Capybara.javascript_driver = :webkit - - # Includes support/login_macros for feature tests config.include LoginMacros, type: :feature - - # Includes omniauth macro - config.include(OmniauthMacros) - - # Includes support/flash for feature tests config.include Flash, type: :feature - config.include Sidebar, type: :view + config.include Devise::TestHelpers, type: :view # As we start from scratch in April 2014, let's forbid the old :should syntax config.expect_with :rspec do |c| c.syntax = :expect end + + config.use_transactional_fixtures = true + + # Reuse rspec as mocking framework + config.mock_framework = :rspec + + # Types of tests (controller, feature, model) will + # be inferred from subfolder name + config.infer_spec_type_from_file_location! + end OmniAuth.config.test_mode = true diff --git a/spec/support/kneet_connections.rb b/spec/support/kneet_connections.rb new file mode 100644 index 00000000..7de8cc59 --- /dev/null +++ b/spec/support/kneet_connections.rb @@ -0,0 +1,10 @@ +class ActiveRecord::Base + mattr_accessor :shared_connection + @@shared_connection = nil + + def self.connection + @@shared_connection || retrieve_connection + end +end + +ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection diff --git a/spec/support/login_macros.rb b/spec/support/login_macros.rb index 1bff7302..e8f22147 100644 --- a/spec/support/login_macros.rb +++ b/spec/support/login_macros.rb @@ -1,17 +1,14 @@ module LoginMacros + + include Warden::Test::Helpers + Warden.test_mode! + def sign_in(user) - visit new_user_session_path - - fill_in 'user_email', with: user.email - fill_in 'user_password', with: user.password - find(:xpath, "//div[@id='content']//button[@type='submit']").click - - expect(page.has_content?('Signed in successfully')).to be true + login_as(user, :scope => :user) end def sign_out - Capybara.current_session.driver.browser.clear_cookies - visit root_path - expect(page.has_content?('Sign In')).to be true + logout(:user) end + end