Created
August 6, 2013 13:36
-
-
Save rkellermeyer/6164469 to your computer and use it in GitHub Desktop.
Scope that only returns users who are 21 or older
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failures: | |
1) User scopes .adult_purchases_enabled does not return users who are not at least 21 years old | |
Failure/Error: User.adult_purchases_enabled.should_not include(subject) | |
expected [#<User id: 338, first_name: "Romaine", last_name: "Mohr", address1: "87010 Derick Heights", address2: nil, city: "Welchton", state: "Arkansas", zip_code: "11561", avatar: nil, birth_date: "1993-08-06", email: "[email protected]", about: nil, created_at: "2013-08-06 13:31:54", updated_at: "2013-08-06 13:31:55", latitude: 40.5895, longitude: -73.6389, active: false>] not to include #<User id: 338, first_name: "Romaine", last_name: "Mohr", address1: "87010 Derick Heights", address2: nil, city: "Welchton", state: "Arkansas", zip_code: "11561", avatar: nil, birth_date: "1993-08-06 00:00:00", email: "[email protected]", about: nil, created_at: "2013-08-06 13:31:54", updated_at: "2013-08-06 13:31:55", latitude: 40.5895272, longitude: -73.6389038, active: false> | |
Diff: | |
@@ -1,2 +1,2 @@ | |
-[#<User id: 338, first_name: "Romaine", last_name: "Mohr", address1: "87010 Derick Heights", address2: nil, city: "Welchton", state: "Arkansas", zip_code: "11561", avatar: nil, birth_date: "1993-08-06 00:00:00", email: "[email protected]", about: nil, created_at: "2013-08-06 13:31:54", updated_at: "2013-08-06 13:31:55", latitude: 40.5895272, longitude: -73.6389038, active: false>] | |
+[#<User id: 338, first_name: "Romaine", last_name: "Mohr", address1: "87010 Derick Heights", address2: nil, city: "Welchton", state: "Arkansas", zip_code: "11561", avatar: nil, birth_date: "1993-08-06", email: "[email protected]", about: nil, created_at: "2013-08-06 13:31:54", updated_at: "2013-08-06 13:31:55", latitude: 40.5895, longitude: -73.6389, active: false>] | |
# ./spec/models/user_spec.rb:80:in `block (4 levels) in <top (required)>' | |
2) User scopes .adult_purchases_enabled returns users who are at least 21 years old | |
Failure/Error: User.adult_purchases_enabled.should include(subject) | |
expected [] to include #<User id: 339, first_name: "Romaine", last_name: "Mohr", address1: "87010 Derick Heights", address2: nil, city: "Welchton", state: "Arkansas", zip_code: "11561", avatar: nil, birth_date: "1992-08-06 00:00:00", email: "[email protected]", about: nil, created_at: "2013-08-06 13:31:55", updated_at: "2013-08-06 13:31:55", latitude: 40.5895272, longitude: -73.6389038, active: false> | |
Diff: | |
@@ -1,2 +1,2 @@ | |
-[#<User id: 339, first_name: "Romaine", last_name: "Mohr", address1: "87010 Derick Heights", address2: nil, city: "Welchton", state: "Arkansas", zip_code: "11561", avatar: nil, birth_date: "1992-08-06 00:00:00", email: "[email protected]", about: nil, created_at: "2013-08-06 13:31:55", updated_at: "2013-08-06 13:31:55", latitude: 40.5895272, longitude: -73.6389038, active: false>] | |
+[] | |
# ./spec/models/user_spec.rb:86:in `block (4 levels) in <top (required)>' | |
Finished in 11.66 seconds | |
34 examples, 2 failures | |
Failed examples: | |
rspec ./spec/models/user_spec.rb:77 # User scopes .adult_purchases_enabled does not return users who are not at least 21 years old | |
rspec ./spec/models/user_spec.rb:83 # User scopes .adult_purchases_enabled returns users who are at least 21 years old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# ... | |
scope :adult_purchases_enabled, -> { where('birth_date >= ?', 21.years.ago.midnight) } | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe User do | |
let(:user) { FactoryGirl.create(:valid_user) } | |
subject { user } | |
# ... | |
describe '.adult_purchases_enabled' do | |
it 'does not return users who are not at least 21 years old' do | |
subject.birth_date = 20.years.ago.midnight | |
subject.save! | |
User.adult_purchases_enabled.should_not include(subject) | |
end | |
it 'returns users who are at least 21 years old' do | |
subject.birth_date = 21.years.ago.midnight | |
subject.save! | |
User.adult_purchases_enabled.should include(subject) | |
end | |
end | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment