From 714cf87d78ec630c44a894c205cbada0644fe3ef Mon Sep 17 00:00:00 2001 From: Mauro George Date: Tue, 31 Dec 2013 17:54:21 -0200 Subject: [PATCH] Add support to rails 4.1.0 --- .travis.yml | 4 + Appraisals | 8 + Gemfile | 2 +- Gemfile.lock | 4 +- features/step_definitions/rails_steps.rb | 9 +- gemfiles/3.0.gemfile | 2 +- gemfiles/3.0.gemfile.lock | 6 +- gemfiles/3.1.gemfile | 2 +- gemfiles/3.1.gemfile.lock | 5 +- gemfiles/3.2.gemfile | 2 +- gemfiles/3.2.gemfile.lock | 4 +- gemfiles/4.0.0.gemfile | 2 +- gemfiles/4.0.0.gemfile.lock | 4 +- gemfiles/4.0.1.gemfile | 2 +- gemfiles/4.0.1.gemfile.lock | 4 +- gemfiles/4.1.gemfile | 19 ++ gemfiles/4.1.gemfile.lock | 176 ++++++++++++++++++ .../set_the_flash_matcher.rb | 3 +- .../active_record/association_matcher.rb | 3 + .../association_matchers/model_reflection.rb | 21 ++- lib/shoulda/matchers/assertion_error.rb | 9 +- .../redirect_to_matcher_spec.rb | 4 +- .../render_template_matcher_spec.rb | 10 +- .../render_with_layout_matcher_spec.rb | 8 +- .../respond_with_matcher_spec.rb | 2 +- .../set_session_matcher_spec.rb | 2 +- .../set_the_flash_matcher_spec.rb | 12 +- .../model_reflection_spec.rb | 4 + spec/support/controller_builder.rb | 2 +- 29 files changed, 287 insertions(+), 48 deletions(-) create mode 100644 gemfiles/4.1.gemfile create mode 100644 gemfiles/4.1.gemfile.lock diff --git a/.travis.yml b/.travis.yml index 7976a066..13d08821 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,12 +20,16 @@ matrix: gemfile: gemfiles/4.0.0.gemfile - rvm: 1.9.3 gemfile: gemfiles/4.0.1.gemfile + - rvm: 1.9.3 + gemfile: gemfiles/4.1.gemfile - rvm: 2.0.0 gemfile: gemfiles/3.2.gemfile - rvm: 2.0.0 gemfile: gemfiles/4.0.0.gemfile - rvm: 2.0.0 gemfile: gemfiles/4.0.1.gemfile + - rvm: 2.0.0 + gemfile: gemfiles/4.1.gemfile - rvm: rbx-19mode gemfile: gemfiles/3.2.gemfile - rvm: jruby-19mode diff --git a/Appraisals b/Appraisals index 185b72c0..0d67dfc4 100644 --- a/Appraisals +++ b/Appraisals @@ -43,3 +43,11 @@ appraise '4.0.1' do gem 'sass-rails', '4.0.1' gem 'bcrypt-ruby', '~> 3.1.2' end + +appraise '4.1' do + instance_eval(&rails_4_0) + gem 'rails', '~> 4.1.0' + gem 'sass-rails', '4.0.3' + gem 'bcrypt-ruby', '~> 3.1.2' + gem "protected_attributes", '~> 1.0.6' +end diff --git a/Gemfile b/Gemfile index df7b1327..49033341 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' gemspec # For test Rails application -gem 'shoulda-context', '~> 1.1.2' +gem 'shoulda-context', '~> 1.2.0' gem 'sqlite3', :platform => :ruby # Can't wrap in platform :jruby do...end block because appraisal doesn't support diff --git a/Gemfile.lock b/Gemfile.lock index 1f223b12..772db04b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -116,7 +116,7 @@ GEM rspec-core (~> 2.14.0) rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) - shoulda-context (1.1.6) + shoulda-context (1.2.0) slop (3.4.7) sprockets (2.2.2) hike (~> 1.2) @@ -148,7 +148,7 @@ DEPENDENCIES rails (~> 3.0) rake (>= 0.9.2) rspec-rails (>= 2.13.1, < 3) - shoulda-context (~> 1.1.2) + shoulda-context (~> 1.2.0) shoulda-matchers! sqlite3 therubyrhino diff --git a/features/step_definitions/rails_steps.rb b/features/step_definitions/rails_steps.rb index 8900a1f9..431e7bb3 100644 --- a/features/step_definitions/rails_steps.rb +++ b/features/step_definitions/rails_steps.rb @@ -67,7 +67,8 @@ When 'I configure the application to use rspec-rails in test and development' do end When 'I configure the application to use shoulda-context' do - append_to_gemfile %q(gem 'shoulda-context', '~> 1.0') + append_to_gemfile %q(gem 'shoulda-context', '~> 1.2.0') + append_to_gemfile %q(gem 'pry') steps %{And I install gems} end @@ -112,7 +113,7 @@ Then /^the output should indicate that (\d+) tests? (?:was|were) run/ do |number # Rails 4 has slightly different output than Rails 3 due to # Test::Unit::TestCase -> MiniTest if rails_4? - steps %{Then the output should contain "#{number} tests, #{number} assertions, 0 failures, 0 errors, 0 skips"} + steps %{Then the output should match /#{number} (tests|runs), #{number} assertions, 0 failures, 0 errors, 0 skips/} else steps %{Then the output should contain "#{number} tests, #{number} assertions, 0 failures, 0 errors"} end @@ -125,7 +126,7 @@ Then /^the output should indicate that (\d+) unit and (\d+) functional tests? we # Rails 3 runs separate test suites in separate processes, but Rails 4 does # not, so that's why we have to check for different things here if rails_4? - steps %{Then the output should contain "#{total} tests, #{total} assertions, 0 failures, 0 errors, 0 skips"} + steps %{Then the output should match /#{total} (tests|runs), #{total} assertions, 0 failures, 0 errors, 0 skips/} else steps %{Then the output should match /#{n1} tests, #{n1} assertions, 0 failures, 0 errors.+#{n2} tests, #{n2} assertions, 0 failures, 0 errors/} end @@ -154,7 +155,7 @@ module FileHelpers end def rails_4? - match = ORIGINAL_BUNDLE_VARS['BUNDLE_GEMFILE'].match(/(\d)\.\d\.(\d\.)?gemfile$/) + match = ORIGINAL_BUNDLE_VARS['BUNDLE_GEMFILE'].match(/(\d)\.\d\.(\d\.)?(\w+\.)?gemfile$/) match.captures[0] == '4' end end diff --git a/gemfiles/3.0.gemfile b/gemfiles/3.0.gemfile index cd7a8bcf..f84b38b3 100644 --- a/gemfiles/3.0.gemfile +++ b/gemfiles/3.0.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "shoulda-context", "~> 1.1.2" +gem "shoulda-context", "~> 1.2.0" gem "sqlite3", :platform=>:ruby gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby diff --git a/gemfiles/3.0.gemfile.lock b/gemfiles/3.0.gemfile.lock index e9d34d38..c56fa3ff 100644 --- a/gemfiles/3.0.gemfile.lock +++ b/gemfiles/3.0.gemfile.lock @@ -3,7 +3,6 @@ PATH specs: shoulda-matchers (2.5.0) activesupport (>= 3.0.0) - bourne (~> 1.3) GEM remote: https://rubygems.org/ @@ -112,7 +111,7 @@ GEM rspec-core (~> 2.13.0) rspec-expectations (~> 2.13.0) rspec-mocks (~> 2.13.0) - shoulda-context (1.1.4) + shoulda-context (1.2.0) slop (3.4.7) sqlite3 (1.3.7) strong_parameters (0.2.0) @@ -133,6 +132,7 @@ DEPENDENCIES activerecord-jdbcsqlite3-adapter appraisal (~> 1.0.0.beta2) aruba + bourne (~> 1.3) bundler (~> 1.1) cucumber (~> 1.1) jdbc-sqlite3 @@ -141,7 +141,7 @@ DEPENDENCIES rails (~> 3.0.17) rake (>= 0.9.2) rspec-rails (>= 2.13.1, < 3) - shoulda-context (~> 1.1.2) + shoulda-context (~> 1.2.0) shoulda-matchers! sqlite3 strong_parameters diff --git a/gemfiles/3.1.gemfile b/gemfiles/3.1.gemfile index 71e738c5..d2e7b922 100644 --- a/gemfiles/3.1.gemfile +++ b/gemfiles/3.1.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "shoulda-context", "~> 1.1.2" +gem "shoulda-context", "~> 1.2.0" gem "sqlite3", :platform=>:ruby gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby diff --git a/gemfiles/3.1.gemfile.lock b/gemfiles/3.1.gemfile.lock index 99dba515..3e4b3a94 100644 --- a/gemfiles/3.1.gemfile.lock +++ b/gemfiles/3.1.gemfile.lock @@ -3,7 +3,6 @@ PATH specs: shoulda-matchers (2.5.0) activesupport (>= 3.0.0) - bourne (~> 1.3) GEM remote: https://rubygems.org/ @@ -127,7 +126,7 @@ GEM railties (~> 3.1.0) sass (>= 3.1.10) tilt (~> 1.3.2) - shoulda-context (1.1.4) + shoulda-context (1.2.0) slop (3.4.7) sprockets (2.0.4) hike (~> 1.2) @@ -165,7 +164,7 @@ DEPENDENCIES rake (>= 0.9.2) rspec-rails (>= 2.13.1, < 3) sass-rails - shoulda-context (~> 1.1.2) + shoulda-context (~> 1.2.0) shoulda-matchers! sqlite3 strong_parameters diff --git a/gemfiles/3.2.gemfile b/gemfiles/3.2.gemfile index 61e34495..4bdb27a1 100644 --- a/gemfiles/3.2.gemfile +++ b/gemfiles/3.2.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "shoulda-context", "~> 1.1.2" +gem "shoulda-context", "~> 1.2.0" gem "sqlite3", :platform=>:ruby gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby diff --git a/gemfiles/3.2.gemfile.lock b/gemfiles/3.2.gemfile.lock index 88bbbf0a..4d773fde 100644 --- a/gemfiles/3.2.gemfile.lock +++ b/gemfiles/3.2.gemfile.lock @@ -123,7 +123,7 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - shoulda-context (1.1.4) + shoulda-context (1.2.0) slop (3.4.7) sprockets (2.2.2) hike (~> 1.2) @@ -162,7 +162,7 @@ DEPENDENCIES rake (>= 0.9.2) rspec-rails (>= 2.13.1, < 3) sass-rails - shoulda-context (~> 1.1.2) + shoulda-context (~> 1.2.0) shoulda-matchers! sqlite3 strong_parameters diff --git a/gemfiles/4.0.0.gemfile b/gemfiles/4.0.0.gemfile index 57f517a7..00bb4bee 100644 --- a/gemfiles/4.0.0.gemfile +++ b/gemfiles/4.0.0.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "shoulda-context", "~> 1.1.2" +gem "shoulda-context", "~> 1.2.0" gem "sqlite3", :platform=>:ruby gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby diff --git a/gemfiles/4.0.0.gemfile.lock b/gemfiles/4.0.0.gemfile.lock index 6499464d..2fbb8787 100644 --- a/gemfiles/4.0.0.gemfile.lock +++ b/gemfiles/4.0.0.gemfile.lock @@ -121,7 +121,7 @@ GEM railties (>= 4.0.0.beta, < 5.0) sass (>= 3.1.10) sprockets-rails (~> 2.0.0) - shoulda-context (1.1.6) + shoulda-context (1.2.0) slop (3.4.7) sprockets (2.10.1) hike (~> 1.2) @@ -164,7 +164,7 @@ DEPENDENCIES rake (>= 0.9.2) rspec-rails (>= 2.13.1, < 3) sass-rails (= 4.0.0) - shoulda-context (~> 1.1.2) + shoulda-context (~> 1.2.0) shoulda-matchers! sqlite3 therubyrhino diff --git a/gemfiles/4.0.1.gemfile b/gemfiles/4.0.1.gemfile index 2c371e24..f82a406a 100644 --- a/gemfiles/4.0.1.gemfile +++ b/gemfiles/4.0.1.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "shoulda-context", "~> 1.1.2" +gem "shoulda-context", "~> 1.2.0" gem "sqlite3", :platform=>:ruby gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby diff --git a/gemfiles/4.0.1.gemfile.lock b/gemfiles/4.0.1.gemfile.lock index 263df179..f473c883 100644 --- a/gemfiles/4.0.1.gemfile.lock +++ b/gemfiles/4.0.1.gemfile.lock @@ -121,7 +121,7 @@ GEM railties (>= 4.0.0, < 5.0) sass (>= 3.1.10) sprockets-rails (~> 2.0.0) - shoulda-context (1.1.6) + shoulda-context (1.2.0) slop (3.4.7) sprockets (2.10.1) hike (~> 1.2) @@ -164,7 +164,7 @@ DEPENDENCIES rake (>= 0.9.2) rspec-rails (>= 2.13.1, < 3) sass-rails (= 4.0.1) - shoulda-context (~> 1.1.2) + shoulda-context (~> 1.2.0) shoulda-matchers! sqlite3 therubyrhino diff --git a/gemfiles/4.1.gemfile b/gemfiles/4.1.gemfile new file mode 100644 index 00000000..adaa5b73 --- /dev/null +++ b/gemfiles/4.1.gemfile @@ -0,0 +1,19 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "shoulda-context", "~> 1.2.0" +gem "sqlite3", :platform=>:ruby +gem "activerecord-jdbc-adapter", :platform=>:jruby +gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby +gem "jdbc-sqlite3", :platform=>:jruby +gem "jruby-openssl", :platform=>:jruby +gem "therubyrhino", :platform=>:jruby +gem "jquery-rails" +gem "activeresource", "4.0.0" +gem "rails", "~> 4.1.0" +gem "sass-rails", "4.0.3" +gem "bcrypt-ruby", "~> 3.1.2" +gem "protected_attributes", "~> 1.0.6" + +gemspec :path=>".././" diff --git a/gemfiles/4.1.gemfile.lock b/gemfiles/4.1.gemfile.lock new file mode 100644 index 00000000..dc4002f4 --- /dev/null +++ b/gemfiles/4.1.gemfile.lock @@ -0,0 +1,176 @@ +PATH + remote: .././ + specs: + shoulda-matchers (2.5.0) + activesupport (>= 3.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.1.0) + actionpack (= 4.1.0) + actionview (= 4.1.0) + mail (~> 2.5.4) + actionpack (4.1.0) + actionview (= 4.1.0) + activesupport (= 4.1.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.0) + activesupport (= 4.1.0) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.0) + activesupport (= 4.1.0) + builder (~> 3.1) + activerecord (4.1.0) + activemodel (= 4.1.0) + activesupport (= 4.1.0) + arel (~> 5.0.0) + activeresource (4.0.0) + activemodel (~> 4.0) + activesupport (~> 4.0) + rails-observers (~> 0.1.1) + activesupport (4.1.0) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + appraisal (1.0.0.beta2) + bundler + rake + thor (>= 0.14.0) + arel (5.0.0) + aruba (0.5.4) + childprocess (>= 0.3.6) + cucumber (>= 1.1.1) + rspec-expectations (>= 2.7.0) + bcrypt-ruby (3.1.2) + bourne (1.5.0) + mocha (>= 0.13.2, < 0.15) + builder (3.2.2) + childprocess (0.4.0) + ffi (~> 1.0, >= 1.0.11) + coderay (1.1.0) + cucumber (1.3.10) + builder (>= 2.1.2) + diff-lcs (>= 1.1.3) + gherkin (~> 2.12) + multi_json (>= 1.7.5, < 2.0) + multi_test (>= 0.0.2) + diff-lcs (1.2.5) + erubis (2.7.0) + ffi (1.9.3) + gherkin (2.12.2) + multi_json (~> 1.3) + hike (1.2.3) + i18n (0.6.9) + jquery-rails (3.1.0) + railties (>= 3.0, < 5.0) + thor (>= 0.14, < 2.0) + json (1.8.1) + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + metaclass (0.0.2) + method_source (0.8.2) + mime-types (1.25.1) + minitest (5.3.2) + mocha (0.14.0) + metaclass (~> 0.0.1) + multi_json (1.9.2) + multi_test (0.0.3) + polyglot (0.3.4) + protected_attributes (1.0.7) + activemodel (>= 4.0.1, < 5.0) + pry (0.9.12.6) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + rack (1.5.2) + rack-test (0.6.2) + rack (>= 1.0) + rails (4.1.0) + actionmailer (= 4.1.0) + actionpack (= 4.1.0) + actionview (= 4.1.0) + activemodel (= 4.1.0) + activerecord (= 4.1.0) + activesupport (= 4.1.0) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.0) + sprockets-rails (~> 2.0) + rails-observers (0.1.2) + activemodel (~> 4.0) + railties (4.1.0) + actionpack (= 4.1.0) + activesupport (= 4.1.0) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.2.2) + rspec-core (2.14.7) + rspec-expectations (2.14.4) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.4) + rspec-rails (2.14.1) + actionpack (>= 3.0) + activemodel (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + sass (3.2.19) + sass-rails (4.0.3) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.0) + sprockets (~> 2.8, <= 2.11.0) + sprockets-rails (~> 2.0) + shoulda-context (1.2.0) + slop (3.4.7) + sprockets (2.11.0) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.1.0) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (~> 2.8) + sqlite3 (1.3.9) + thor (0.19.1) + thread_safe (0.3.3) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + tzinfo (1.1.0) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + activerecord-jdbc-adapter + activerecord-jdbcsqlite3-adapter + activeresource (= 4.0.0) + appraisal (~> 1.0.0.beta2) + aruba + bcrypt-ruby (~> 3.1.2) + bourne (~> 1.3) + bundler (~> 1.1) + cucumber (~> 1.1) + jdbc-sqlite3 + jquery-rails + jruby-openssl + protected_attributes (~> 1.0.6) + pry + rails (~> 4.1.0) + rake (>= 0.9.2) + rspec-rails (>= 2.13.1, < 3) + sass-rails (= 4.0.3) + shoulda-context (~> 1.2.0) + shoulda-matchers! + sqlite3 + therubyrhino diff --git a/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb b/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb index 00428c31..c43cb1cb 100644 --- a/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +++ b/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb @@ -85,7 +85,8 @@ module Shoulda # :nodoc: def flash_values if @options.key?(:key) - [flash.to_hash[@options[:key]]] + flash_hash = HashWithIndifferentAccess.new(flash.to_hash) + [flash_hash[@options[:key]]] else flash.to_hash.values end diff --git a/lib/shoulda/matchers/active_record/association_matcher.rb b/lib/shoulda/matchers/active_record/association_matcher.rb index c7622fb2..8b3985f3 100644 --- a/lib/shoulda/matchers/active_record/association_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matcher.rb @@ -254,6 +254,9 @@ module Shoulda # :nodoc: def macro_correct? if reflection.macro == macro true + elsif reflection.macro == :has_many + macro == :has_and_belongs_to_many && + reflection.name == @name else @missing = "actual association type was #{reflection.macro}" false diff --git a/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb b/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb index b85b51b2..2e8edd89 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb @@ -21,7 +21,9 @@ module Shoulda def join_table join_table = - if reflection.respond_to?(:join_table) + if has_and_belongs_to_many_name_table_name + has_and_belongs_to_many_name_table_name + elsif reflection.respond_to?(:join_table) reflection.join_table else reflection.options[:join_table] @@ -73,6 +75,23 @@ module Shoulda relation end end + + def has_and_belongs_to_many_name + reflection.options[:through] + end + + def has_and_belongs_to_many_name_table_name + if has_and_belongs_to_many_reflection + has_and_belongs_to_many_reflection.table_name + end + end + + def has_and_belongs_to_many_reflection + @_has_and_belongs_to_many_reflection ||= + if has_and_belongs_to_many_name + @subject.reflect_on_association(has_and_belongs_to_many_name) + end + end end end end diff --git a/lib/shoulda/matchers/assertion_error.rb b/lib/shoulda/matchers/assertion_error.rb index 19b78a84..c1a09c35 100644 --- a/lib/shoulda/matchers/assertion_error.rb +++ b/lib/shoulda/matchers/assertion_error.rb @@ -7,8 +7,13 @@ module Shoulda # Test::Unit has been loaded already, so we use it AssertionError = Test::Unit::AssertionFailedError elsif Gem.ruby_version >= Gem::Version.new("1.9") - require 'minitest/unit' - AssertionError = MiniTest::Assertion + begin + require 'minitest' + rescue LoadError + require 'minitest/unit' + ensure + AssertionError = MiniTest::Assertion + end else raise 'No unit test library available' end diff --git a/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb b/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb index 27ec199c..83d5d7e5 100644 --- a/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +++ b/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb @@ -22,13 +22,13 @@ describe Shoulda::Matchers::ActionController::RedirectToMatcher do end def controller_redirecting_to(url) - build_response { redirect_to url } + build_fake_response { redirect_to url } end end context 'a controller that does not redirect' do it 'rejects redirecting to a url' do - controller = build_response { render text: 'hello' } + controller = build_fake_response { render text: 'hello' } expect(controller).not_to redirect_to('/some/url') end diff --git a/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb b/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb index d4054890..1114736b 100644 --- a/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +++ b/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb @@ -21,7 +21,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do end def controller_with_show - build_response(action: 'show') { render } + build_fake_response(action: 'show') { render } end end @@ -47,13 +47,13 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do end def controller_with_customer_partial - build_response(partial: '_customer') { render partial: 'customer' } + build_fake_response(partial: '_customer') { render partial: 'customer' } end end context 'a controller that does not render partials' do it 'accepts not rendering a partial' do - controller = build_response(action: 'show') { render } + controller = build_fake_response(action: 'show') { render } expect(controller).to render_template(partial: false) end @@ -61,7 +61,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do context 'a controller that renders a partial several times' do it 'accepts rendering that partial twice' do - controller = build_response(partial: '_customer') do + controller = build_fake_response(partial: '_customer') do render partial: 'customer', collection: [1,2] end @@ -71,7 +71,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do context 'a controller that does not render a template' do it 'rejects rendering a template' do - expect(build_response { render nothing: true }). + expect(build_fake_response { render nothing: true }). not_to render_template(:show) end end diff --git a/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb b/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb index 1af9028c..e7e896f4 100644 --- a/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +++ b/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb @@ -18,14 +18,14 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do def controller_with_wide_layout create_view('layouts/wide.html.erb', 'some content, <%= yield %>') - build_response { render layout: 'wide' } + build_fake_response { render layout: 'wide' } end end context 'a controller that renders without a layout' do it 'rejects rendering with a layout' do - controller_without_layout = build_response { render layout: false } + controller_without_layout = build_fake_response { render layout: false } expect(controller_without_layout).not_to render_with_layout end @@ -33,7 +33,7 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do context 'a controller that renders a partial' do it 'rejects rendering with a layout' do - controller_with_partial = build_response { render partial: 'partial' } + controller_with_partial = build_fake_response { render partial: 'partial' } expect(controller_with_partial).not_to render_with_layout end @@ -57,7 +57,7 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do end def controller_without_layout - build_response { render layout: false } + build_fake_response { render layout: false } end end end diff --git a/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb b/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb index b83bd43e..7af2b5cd 100644 --- a/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +++ b/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb @@ -24,7 +24,7 @@ describe Shoulda::Matchers::ActionController::RespondWithMatcher do end def controller_with_status(status) - build_response do + build_fake_response do render text: 'text', status: status end end diff --git a/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb b/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb index e20ddc81..49a60405 100644 --- a/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +++ b/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb @@ -41,7 +41,7 @@ describe Shoulda::Matchers::ActionController::SetSessionMatcher do end def controller_with_session(session_hash) - build_response do + build_fake_response do session_hash.each do |key, value| session[key] = value end diff --git a/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb b/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb index f55fbf57..bde5d305 100644 --- a/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +++ b/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb @@ -95,7 +95,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do context 'a controller that sets flash and flash.now' do it 'accepts setting any flash.now message' do - controller = build_response do + controller = build_fake_response do flash.now[:notice] = 'value' flash[:success] = 'great job' end @@ -105,7 +105,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do end it 'accepts setting a matched flash.now message' do - controller = build_response do + controller = build_fake_response do flash.now[:notice] = 'value' flash[:success] = 'great job' end @@ -115,7 +115,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do end it 'rejects setting a different flash.now message' do - controller = build_response do + controller = build_fake_response do flash.now[:notice] = 'value' flash[:success] = 'great job' end @@ -132,11 +132,11 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do end def controller_with_no_flashes - build_response + build_fake_response end def controller_with_flash(flash_hash) - build_response do + build_fake_response do flash_hash.each do |key, value| flash[key] = value end @@ -144,7 +144,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do end def controller_with_flash_now(flash_hash = { notice: 'hi' }) - build_response do + build_fake_response do flash_hash.each do |key, value| flash.now[key] = value end diff --git a/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb b/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb index c8dfba80..709b220c 100644 --- a/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +++ b/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb @@ -57,6 +57,10 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflection d describe '#join_table' do context 'when the association was defined with a :join_table option' do it 'returns the value of the option' do + create_table :foos, id: false do |t| + t.integer :person_id + t.integer :country_id + end define_model(:person, country_id: :integer) country_model = define_model(:country) do has_and_belongs_to_many :people, join_table: 'foos' diff --git a/spec/support/controller_builder.rb b/spec/support/controller_builder.rb index 32fc7aba..2c7a7d42 100644 --- a/spec/support/controller_builder.rb +++ b/spec/support/controller_builder.rb @@ -21,7 +21,7 @@ module ControllerBuilder end end - def build_response(opts = {}, &block) + def build_fake_response(opts = {}, &block) action = opts[:action] || 'example' partial = opts[:partial] || '_partial' block ||= lambda { render nothing: true }