Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for rspec 3 compatability #77

Merged
merged 1 commit into from
Jun 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Next Release
============

* Your contribution here.
* [#77](https://github.com/intridea/grape-entity/pull/77): Fix compatibility with Rspec 3 - [@justfalter](https://github.com/justfalter).

0.4.2 (2014-04-03)
==================
Expand Down
52 changes: 26 additions & 26 deletions spec/grape_entity/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class Parent < Person

it 'adds the collection: true option if called with a collection' do
representation = subject.represent(4.times.map { Object.new })
representation.each { |r| r.options[:collection].should be_true }
representation.each { |r| r.options[:collection].should be true }
end

it 'returns a serialized hash of a single object if serializable: true' do
Expand Down Expand Up @@ -909,7 +909,7 @@ class UserEntity < Grape::Entity
rep = subject.send(:value_for, :friends)
rep.should be_kind_of Array
rep.size.should == 2
rep.all? { |r| r.is_a?(EntitySpec::UserEntity) }.should be_true
rep.all? { |r| r.is_a?(EntitySpec::UserEntity) }.should be true
end

it 'class' do
Expand All @@ -920,7 +920,7 @@ class UserEntity < Grape::Entity
rep = subject.send(:value_for, :friends)
rep.should be_kind_of Array
rep.size.should == 2
rep.all? { |r| r.is_a?(EntitySpec::UserEntity) }.should be_true
rep.all? { |r| r.is_a?(EntitySpec::UserEntity) }.should be true
end
end
end
Expand Down Expand Up @@ -972,54 +972,54 @@ class UserEntity < Grape::Entity
it 'only passes through hash :if exposure if all attributes match' do
exposure_options = { if: { condition1: true, condition2: true } }

subject.send(:conditions_met?, exposure_options, {}).should be_false
subject.send(:conditions_met?, exposure_options, condition1: true).should be_false
subject.send(:conditions_met?, exposure_options, condition1: true, condition2: true).should be_true
subject.send(:conditions_met?, exposure_options, condition1: false, condition2: true).should be_false
subject.send(:conditions_met?, exposure_options, condition1: true, condition2: true, other: true).should be_true
subject.send(:conditions_met?, exposure_options, {}).should be false
subject.send(:conditions_met?, exposure_options, condition1: true).should be false
subject.send(:conditions_met?, exposure_options, condition1: true, condition2: true).should be true
subject.send(:conditions_met?, exposure_options, condition1: false, condition2: true).should be false
subject.send(:conditions_met?, exposure_options, condition1: true, condition2: true, other: true).should be true
end

it 'looks for presence/truthiness if a symbol is passed' do
exposure_options = { if: :condition1 }

subject.send(:conditions_met?, exposure_options, {}).should be_false
subject.send(:conditions_met?, exposure_options, condition1: true).should be_true
subject.send(:conditions_met?, exposure_options, condition1: false).should be_false
subject.send(:conditions_met?, exposure_options, condition1: nil).should be_false
subject.send(:conditions_met?, exposure_options, {}).should be false
subject.send(:conditions_met?, exposure_options, condition1: true).should be true
subject.send(:conditions_met?, exposure_options, condition1: false).should be false
subject.send(:conditions_met?, exposure_options, condition1: nil).should be false
end

it 'looks for absence/falsiness if a symbol is passed' do
exposure_options = { unless: :condition1 }

subject.send(:conditions_met?, exposure_options, {}).should be_true
subject.send(:conditions_met?, exposure_options, condition1: true).should be_false
subject.send(:conditions_met?, exposure_options, condition1: false).should be_true
subject.send(:conditions_met?, exposure_options, condition1: nil).should be_true
subject.send(:conditions_met?, exposure_options, {}).should be true
subject.send(:conditions_met?, exposure_options, condition1: true).should be false
subject.send(:conditions_met?, exposure_options, condition1: false).should be true
subject.send(:conditions_met?, exposure_options, condition1: nil).should be true
end

it 'only passes through proc :if exposure if it returns truthy value' do
exposure_options = { if: lambda { |_, opts| opts[:true] } }

subject.send(:conditions_met?, exposure_options, true: false).should be_false
subject.send(:conditions_met?, exposure_options, true: true).should be_true
subject.send(:conditions_met?, exposure_options, true: false).should be false
subject.send(:conditions_met?, exposure_options, true: true).should be true
end

it 'only passes through hash :unless exposure if any attributes do not match' do
exposure_options = { unless: { condition1: true, condition2: true } }

subject.send(:conditions_met?, exposure_options, {}).should be_true
subject.send(:conditions_met?, exposure_options, condition1: true).should be_false
subject.send(:conditions_met?, exposure_options, condition1: true, condition2: true).should be_false
subject.send(:conditions_met?, exposure_options, condition1: false, condition2: true).should be_false
subject.send(:conditions_met?, exposure_options, condition1: true, condition2: true, other: true).should be_false
subject.send(:conditions_met?, exposure_options, condition1: false, condition2: false).should be_true
subject.send(:conditions_met?, exposure_options, {}).should be true
subject.send(:conditions_met?, exposure_options, condition1: true).should be false
subject.send(:conditions_met?, exposure_options, condition1: true, condition2: true).should be false
subject.send(:conditions_met?, exposure_options, condition1: false, condition2: true).should be false
subject.send(:conditions_met?, exposure_options, condition1: true, condition2: true, other: true).should be false
subject.send(:conditions_met?, exposure_options, condition1: false, condition2: false).should be true
end

it 'only passes through proc :unless exposure if it returns falsy value' do
exposure_options = { unless: lambda { |_, options| options[:true] == true } }

subject.send(:conditions_met?, exposure_options, true: false).should be_true
subject.send(:conditions_met?, exposure_options, true: true).should be_false
subject.send(:conditions_met?, exposure_options, true: false).should be true
subject.send(:conditions_met?, exposure_options, true: true).should be false
end
end

Expand Down