Skip to content

Commit

Permalink
Upgrade AR specs to RSpec 3 expect syntax
Browse files Browse the repository at this point in the history
TODO:

The same with the MongoDB specs.
  • Loading branch information
jonatack committed Jul 26, 2015
1 parent 40bfbdb commit 87cd36d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions spec/ransack/adapters/active_record/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,55 @@ module ActiveRecord

context 'with scopes' do
before do
Person.stub :ransackable_scopes => [:active, :over_age, :of_age]
allow(Person).to receive_messages(
ransackable_scopes: [:active, :over_age, :of_age]
)
end

it "applies true scopes" do
s = Person.ransack('active' => true)
s.result.to_sql.should include "active = 1"
expect(s.result.to_sql).to (include 'active = 1')
end

it "applies stringy true scopes" do
s = Person.ransack('active' => 'true')
s.result.to_sql.should include "active = 1"
expect(s.result.to_sql).to (include 'active = 1')
end

it "applies stringy boolean scopes with true value in an array" do
s = Person.ransack('of_age' => ['true'])
s.result.to_sql.should include "age >= 18"
expect(s.result.to_sql).to (include 'age >= 18')
end

it "applies stringy boolean scopes with false value in an array" do
s = Person.ransack('of_age' => ['false'])
s.result.to_sql.should include "age < 18"
expect(s.result.to_sql).to (include 'age < 18')
end

it "ignores unlisted scopes" do
s = Person.ransack('restricted' => true)
s.result.to_sql.should_not include "restricted"
expect(s.result.to_sql).to_not (include 'restricted')
end

it "ignores false scopes" do
s = Person.ransack('active' => false)
s.result.to_sql.should_not include "active"
expect(s.result.to_sql).not_to (include 'active')
end

it "ignores stringy false scopes" do
s = Person.ransack('active' => 'false')
s.result.to_sql.should_not include "active"
expect(s.result.to_sql).to_not (include 'active')
end

it "passes values to scopes" do
s = Person.ransack('over_age' => 18)
s.result.to_sql.should include "age > 18"
expect(s.result.to_sql).to (include 'age > 18')
end

it "chains scopes" do
s = Person.ransack('over_age' => 18, 'active' => true)
s.result.to_sql.should include "age > 18"
s.result.to_sql.should include "active = 1"
expect(s.result.to_sql).to (include 'age > 18')
expect(s.result.to_sql).to (include 'active = 1')
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/ransack/nodes/condition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Nodes
Ransack.configure { |c| c.ignore_unknown_conditions = true }
end

specify { subject.should be_nil }
specify { expect(subject).to be_nil }
end
end
end
Expand Down

0 comments on commit 87cd36d

Please sign in to comment.