Add support to rails 4.1.0

This commit is contained in:
Mauro George 2013-12-31 17:54:21 -02:00
parent cd9594603e
commit 714cf87d78
29 changed files with 287 additions and 48 deletions

View File

@ -20,12 +20,16 @@ matrix:
gemfile: gemfiles/4.0.0.gemfile gemfile: gemfiles/4.0.0.gemfile
- rvm: 1.9.3 - rvm: 1.9.3
gemfile: gemfiles/4.0.1.gemfile gemfile: gemfiles/4.0.1.gemfile
- rvm: 1.9.3
gemfile: gemfiles/4.1.gemfile
- rvm: 2.0.0 - rvm: 2.0.0
gemfile: gemfiles/3.2.gemfile gemfile: gemfiles/3.2.gemfile
- rvm: 2.0.0 - rvm: 2.0.0
gemfile: gemfiles/4.0.0.gemfile gemfile: gemfiles/4.0.0.gemfile
- rvm: 2.0.0 - rvm: 2.0.0
gemfile: gemfiles/4.0.1.gemfile gemfile: gemfiles/4.0.1.gemfile
- rvm: 2.0.0
gemfile: gemfiles/4.1.gemfile
- rvm: rbx-19mode - rvm: rbx-19mode
gemfile: gemfiles/3.2.gemfile gemfile: gemfiles/3.2.gemfile
- rvm: jruby-19mode - rvm: jruby-19mode

View File

@ -43,3 +43,11 @@ appraise '4.0.1' do
gem 'sass-rails', '4.0.1' gem 'sass-rails', '4.0.1'
gem 'bcrypt-ruby', '~> 3.1.2' gem 'bcrypt-ruby', '~> 3.1.2'
end 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

View File

@ -3,7 +3,7 @@ source 'https://rubygems.org'
gemspec gemspec
# For test Rails application # For test Rails application
gem 'shoulda-context', '~> 1.1.2' gem 'shoulda-context', '~> 1.2.0'
gem 'sqlite3', :platform => :ruby gem 'sqlite3', :platform => :ruby
# Can't wrap in platform :jruby do...end block because appraisal doesn't support # Can't wrap in platform :jruby do...end block because appraisal doesn't support

View File

@ -116,7 +116,7 @@ GEM
rspec-core (~> 2.14.0) rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0) rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0) rspec-mocks (~> 2.14.0)
shoulda-context (1.1.6) shoulda-context (1.2.0)
slop (3.4.7) slop (3.4.7)
sprockets (2.2.2) sprockets (2.2.2)
hike (~> 1.2) hike (~> 1.2)
@ -148,7 +148,7 @@ DEPENDENCIES
rails (~> 3.0) rails (~> 3.0)
rake (>= 0.9.2) rake (>= 0.9.2)
rspec-rails (>= 2.13.1, < 3) rspec-rails (>= 2.13.1, < 3)
shoulda-context (~> 1.1.2) shoulda-context (~> 1.2.0)
shoulda-matchers! shoulda-matchers!
sqlite3 sqlite3
therubyrhino therubyrhino

View File

@ -67,7 +67,8 @@ When 'I configure the application to use rspec-rails in test and development' do
end end
When 'I configure the application to use shoulda-context' do 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} steps %{And I install gems}
end 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 # Rails 4 has slightly different output than Rails 3 due to
# Test::Unit::TestCase -> MiniTest # Test::Unit::TestCase -> MiniTest
if rails_4? 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 else
steps %{Then the output should contain "#{number} tests, #{number} assertions, 0 failures, 0 errors"} steps %{Then the output should contain "#{number} tests, #{number} assertions, 0 failures, 0 errors"}
end 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 # 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 # not, so that's why we have to check for different things here
if rails_4? 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 else
steps %{Then the output should match /#{n1} tests, #{n1} assertions, 0 failures, 0 errors.+#{n2} tests, #{n2} assertions, 0 failures, 0 errors/} steps %{Then the output should match /#{n1} tests, #{n1} assertions, 0 failures, 0 errors.+#{n2} tests, #{n2} assertions, 0 failures, 0 errors/}
end end
@ -154,7 +155,7 @@ module FileHelpers
end end
def rails_4? 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' match.captures[0] == '4'
end end
end end

View File

@ -2,7 +2,7 @@
source "https://rubygems.org" source "https://rubygems.org"
gem "shoulda-context", "~> 1.1.2" gem "shoulda-context", "~> 1.2.0"
gem "sqlite3", :platform=>:ruby gem "sqlite3", :platform=>:ruby
gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbc-adapter", :platform=>:jruby
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby

View File

@ -3,7 +3,6 @@ PATH
specs: specs:
shoulda-matchers (2.5.0) shoulda-matchers (2.5.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
bourne (~> 1.3)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
@ -112,7 +111,7 @@ GEM
rspec-core (~> 2.13.0) rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0) rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0) rspec-mocks (~> 2.13.0)
shoulda-context (1.1.4) shoulda-context (1.2.0)
slop (3.4.7) slop (3.4.7)
sqlite3 (1.3.7) sqlite3 (1.3.7)
strong_parameters (0.2.0) strong_parameters (0.2.0)
@ -133,6 +132,7 @@ DEPENDENCIES
activerecord-jdbcsqlite3-adapter activerecord-jdbcsqlite3-adapter
appraisal (~> 1.0.0.beta2) appraisal (~> 1.0.0.beta2)
aruba aruba
bourne (~> 1.3)
bundler (~> 1.1) bundler (~> 1.1)
cucumber (~> 1.1) cucumber (~> 1.1)
jdbc-sqlite3 jdbc-sqlite3
@ -141,7 +141,7 @@ DEPENDENCIES
rails (~> 3.0.17) rails (~> 3.0.17)
rake (>= 0.9.2) rake (>= 0.9.2)
rspec-rails (>= 2.13.1, < 3) rspec-rails (>= 2.13.1, < 3)
shoulda-context (~> 1.1.2) shoulda-context (~> 1.2.0)
shoulda-matchers! shoulda-matchers!
sqlite3 sqlite3
strong_parameters strong_parameters

View File

@ -2,7 +2,7 @@
source "https://rubygems.org" source "https://rubygems.org"
gem "shoulda-context", "~> 1.1.2" gem "shoulda-context", "~> 1.2.0"
gem "sqlite3", :platform=>:ruby gem "sqlite3", :platform=>:ruby
gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbc-adapter", :platform=>:jruby
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby

View File

@ -3,7 +3,6 @@ PATH
specs: specs:
shoulda-matchers (2.5.0) shoulda-matchers (2.5.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
bourne (~> 1.3)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
@ -127,7 +126,7 @@ GEM
railties (~> 3.1.0) railties (~> 3.1.0)
sass (>= 3.1.10) sass (>= 3.1.10)
tilt (~> 1.3.2) tilt (~> 1.3.2)
shoulda-context (1.1.4) shoulda-context (1.2.0)
slop (3.4.7) slop (3.4.7)
sprockets (2.0.4) sprockets (2.0.4)
hike (~> 1.2) hike (~> 1.2)
@ -165,7 +164,7 @@ DEPENDENCIES
rake (>= 0.9.2) rake (>= 0.9.2)
rspec-rails (>= 2.13.1, < 3) rspec-rails (>= 2.13.1, < 3)
sass-rails sass-rails
shoulda-context (~> 1.1.2) shoulda-context (~> 1.2.0)
shoulda-matchers! shoulda-matchers!
sqlite3 sqlite3
strong_parameters strong_parameters

View File

@ -2,7 +2,7 @@
source "https://rubygems.org" source "https://rubygems.org"
gem "shoulda-context", "~> 1.1.2" gem "shoulda-context", "~> 1.2.0"
gem "sqlite3", :platform=>:ruby gem "sqlite3", :platform=>:ruby
gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbc-adapter", :platform=>:jruby
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby

View File

@ -123,7 +123,7 @@ GEM
railties (~> 3.2.0) railties (~> 3.2.0)
sass (>= 3.1.10) sass (>= 3.1.10)
tilt (~> 1.3) tilt (~> 1.3)
shoulda-context (1.1.4) shoulda-context (1.2.0)
slop (3.4.7) slop (3.4.7)
sprockets (2.2.2) sprockets (2.2.2)
hike (~> 1.2) hike (~> 1.2)
@ -162,7 +162,7 @@ DEPENDENCIES
rake (>= 0.9.2) rake (>= 0.9.2)
rspec-rails (>= 2.13.1, < 3) rspec-rails (>= 2.13.1, < 3)
sass-rails sass-rails
shoulda-context (~> 1.1.2) shoulda-context (~> 1.2.0)
shoulda-matchers! shoulda-matchers!
sqlite3 sqlite3
strong_parameters strong_parameters

View File

@ -2,7 +2,7 @@
source "https://rubygems.org" source "https://rubygems.org"
gem "shoulda-context", "~> 1.1.2" gem "shoulda-context", "~> 1.2.0"
gem "sqlite3", :platform=>:ruby gem "sqlite3", :platform=>:ruby
gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbc-adapter", :platform=>:jruby
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby

View File

@ -121,7 +121,7 @@ GEM
railties (>= 4.0.0.beta, < 5.0) railties (>= 4.0.0.beta, < 5.0)
sass (>= 3.1.10) sass (>= 3.1.10)
sprockets-rails (~> 2.0.0) sprockets-rails (~> 2.0.0)
shoulda-context (1.1.6) shoulda-context (1.2.0)
slop (3.4.7) slop (3.4.7)
sprockets (2.10.1) sprockets (2.10.1)
hike (~> 1.2) hike (~> 1.2)
@ -164,7 +164,7 @@ DEPENDENCIES
rake (>= 0.9.2) rake (>= 0.9.2)
rspec-rails (>= 2.13.1, < 3) rspec-rails (>= 2.13.1, < 3)
sass-rails (= 4.0.0) sass-rails (= 4.0.0)
shoulda-context (~> 1.1.2) shoulda-context (~> 1.2.0)
shoulda-matchers! shoulda-matchers!
sqlite3 sqlite3
therubyrhino therubyrhino

View File

@ -2,7 +2,7 @@
source "https://rubygems.org" source "https://rubygems.org"
gem "shoulda-context", "~> 1.1.2" gem "shoulda-context", "~> 1.2.0"
gem "sqlite3", :platform=>:ruby gem "sqlite3", :platform=>:ruby
gem "activerecord-jdbc-adapter", :platform=>:jruby gem "activerecord-jdbc-adapter", :platform=>:jruby
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby

View File

@ -121,7 +121,7 @@ GEM
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10) sass (>= 3.1.10)
sprockets-rails (~> 2.0.0) sprockets-rails (~> 2.0.0)
shoulda-context (1.1.6) shoulda-context (1.2.0)
slop (3.4.7) slop (3.4.7)
sprockets (2.10.1) sprockets (2.10.1)
hike (~> 1.2) hike (~> 1.2)
@ -164,7 +164,7 @@ DEPENDENCIES
rake (>= 0.9.2) rake (>= 0.9.2)
rspec-rails (>= 2.13.1, < 3) rspec-rails (>= 2.13.1, < 3)
sass-rails (= 4.0.1) sass-rails (= 4.0.1)
shoulda-context (~> 1.1.2) shoulda-context (~> 1.2.0)
shoulda-matchers! shoulda-matchers!
sqlite3 sqlite3
therubyrhino therubyrhino

19
gemfiles/4.1.gemfile Normal file
View File

@ -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=>".././"

176
gemfiles/4.1.gemfile.lock Normal file
View File

@ -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

View File

@ -85,7 +85,8 @@ module Shoulda # :nodoc:
def flash_values def flash_values
if @options.key?(:key) if @options.key?(:key)
[flash.to_hash[@options[:key]]] flash_hash = HashWithIndifferentAccess.new(flash.to_hash)
[flash_hash[@options[:key]]]
else else
flash.to_hash.values flash.to_hash.values
end end

View File

@ -254,6 +254,9 @@ module Shoulda # :nodoc:
def macro_correct? def macro_correct?
if reflection.macro == macro if reflection.macro == macro
true true
elsif reflection.macro == :has_many
macro == :has_and_belongs_to_many &&
reflection.name == @name
else else
@missing = "actual association type was #{reflection.macro}" @missing = "actual association type was #{reflection.macro}"
false false

View File

@ -21,7 +21,9 @@ module Shoulda
def join_table def join_table
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 reflection.join_table
else else
reflection.options[:join_table] reflection.options[:join_table]
@ -73,6 +75,23 @@ module Shoulda
relation relation
end end
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 end
end end

View File

@ -7,8 +7,13 @@ module Shoulda
# Test::Unit has been loaded already, so we use it # Test::Unit has been loaded already, so we use it
AssertionError = Test::Unit::AssertionFailedError AssertionError = Test::Unit::AssertionFailedError
elsif Gem.ruby_version >= Gem::Version.new("1.9") elsif Gem.ruby_version >= Gem::Version.new("1.9")
require 'minitest/unit' begin
AssertionError = MiniTest::Assertion require 'minitest'
rescue LoadError
require 'minitest/unit'
ensure
AssertionError = MiniTest::Assertion
end
else else
raise 'No unit test library available' raise 'No unit test library available'
end end

View File

@ -22,13 +22,13 @@ describe Shoulda::Matchers::ActionController::RedirectToMatcher do
end end
def controller_redirecting_to(url) def controller_redirecting_to(url)
build_response { redirect_to url } build_fake_response { redirect_to url }
end end
end end
context 'a controller that does not redirect' do context 'a controller that does not redirect' do
it 'rejects redirecting to a url' 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') expect(controller).not_to redirect_to('/some/url')
end end

View File

@ -21,7 +21,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
end end
def controller_with_show def controller_with_show
build_response(action: 'show') { render } build_fake_response(action: 'show') { render }
end end
end end
@ -47,13 +47,13 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
end end
def controller_with_customer_partial def controller_with_customer_partial
build_response(partial: '_customer') { render partial: 'customer' } build_fake_response(partial: '_customer') { render partial: 'customer' }
end end
end end
context 'a controller that does not render partials' do context 'a controller that does not render partials' do
it 'accepts not rendering a partial' 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) expect(controller).to render_template(partial: false)
end end
@ -61,7 +61,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
context 'a controller that renders a partial several times' do context 'a controller that renders a partial several times' do
it 'accepts rendering that partial twice' 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] render partial: 'customer', collection: [1,2]
end end
@ -71,7 +71,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
context 'a controller that does not render a template' do context 'a controller that does not render a template' do
it 'rejects rendering 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) not_to render_template(:show)
end end
end end

View File

@ -18,14 +18,14 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
def controller_with_wide_layout def controller_with_wide_layout
create_view('layouts/wide.html.erb', 'some content, <%= yield %>') create_view('layouts/wide.html.erb', 'some content, <%= yield %>')
build_response { render layout: 'wide' } build_fake_response { render layout: 'wide' }
end end
end end
context 'a controller that renders without a layout' do context 'a controller that renders without a layout' do
it 'rejects rendering with 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 expect(controller_without_layout).not_to render_with_layout
end end
@ -33,7 +33,7 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
context 'a controller that renders a partial' do context 'a controller that renders a partial' do
it 'rejects rendering with a layout' 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 expect(controller_with_partial).not_to render_with_layout
end end
@ -57,7 +57,7 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
end end
def controller_without_layout def controller_without_layout
build_response { render layout: false } build_fake_response { render layout: false }
end end
end end
end end

View File

@ -24,7 +24,7 @@ describe Shoulda::Matchers::ActionController::RespondWithMatcher do
end end
def controller_with_status(status) def controller_with_status(status)
build_response do build_fake_response do
render text: 'text', status: status render text: 'text', status: status
end end
end end

View File

@ -41,7 +41,7 @@ describe Shoulda::Matchers::ActionController::SetSessionMatcher do
end end
def controller_with_session(session_hash) def controller_with_session(session_hash)
build_response do build_fake_response do
session_hash.each do |key, value| session_hash.each do |key, value|
session[key] = value session[key] = value
end end

View File

@ -95,7 +95,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
context 'a controller that sets flash and flash.now' do context 'a controller that sets flash and flash.now' do
it 'accepts setting any flash.now message' do it 'accepts setting any flash.now message' do
controller = build_response do controller = build_fake_response do
flash.now[:notice] = 'value' flash.now[:notice] = 'value'
flash[:success] = 'great job' flash[:success] = 'great job'
end end
@ -105,7 +105,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
end end
it 'accepts setting a matched flash.now message' do it 'accepts setting a matched flash.now message' do
controller = build_response do controller = build_fake_response do
flash.now[:notice] = 'value' flash.now[:notice] = 'value'
flash[:success] = 'great job' flash[:success] = 'great job'
end end
@ -115,7 +115,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
end end
it 'rejects setting a different flash.now message' do it 'rejects setting a different flash.now message' do
controller = build_response do controller = build_fake_response do
flash.now[:notice] = 'value' flash.now[:notice] = 'value'
flash[:success] = 'great job' flash[:success] = 'great job'
end end
@ -132,11 +132,11 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
end end
def controller_with_no_flashes def controller_with_no_flashes
build_response build_fake_response
end end
def controller_with_flash(flash_hash) def controller_with_flash(flash_hash)
build_response do build_fake_response do
flash_hash.each do |key, value| flash_hash.each do |key, value|
flash[key] = value flash[key] = value
end end
@ -144,7 +144,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
end end
def controller_with_flash_now(flash_hash = { notice: 'hi' }) def controller_with_flash_now(flash_hash = { notice: 'hi' })
build_response do build_fake_response do
flash_hash.each do |key, value| flash_hash.each do |key, value|
flash.now[key] = value flash.now[key] = value
end end

View File

@ -57,6 +57,10 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflection d
describe '#join_table' do describe '#join_table' do
context 'when the association was defined with a :join_table option' do context 'when the association was defined with a :join_table option' do
it 'returns the value of the 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) define_model(:person, country_id: :integer)
country_model = define_model(:country) do country_model = define_model(:country) do
has_and_belongs_to_many :people, join_table: 'foos' has_and_belongs_to_many :people, join_table: 'foos'

View File

@ -21,7 +21,7 @@ module ControllerBuilder
end end
end end
def build_response(opts = {}, &block) def build_fake_response(opts = {}, &block)
action = opts[:action] || 'example' action = opts[:action] || 'example'
partial = opts[:partial] || '_partial' partial = opts[:partial] || '_partial'
block ||= lambda { render nothing: true } block ||= lambda { render nothing: true }