Created
March 2, 2015 18:37
-
-
Save iscott/150ac6fe67f0265c8c4a to your computer and use it in GitHub Desktop.
Testing scopes with RSPEC
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
require 'rails_helper' | |
RSpec.describe Item, :type => :model do | |
before(:each) do | |
@purchased_item = Item.create( | |
:name => "Item1", | |
:qty => 1, | |
:is_purchased => true | |
) | |
@unpurchased_item = Item.create( | |
:name => "Item2", | |
:qty => 1, | |
:is_purchased => false | |
) | |
end | |
it "displays only purchased items in ':purchased' scope" do | |
expect(Item.purchased).to include(@purchased_item) | |
expect(Item.purchased).not_to include(@unpurchased_item) | |
end | |
it "displays only unpurchased items in ':not_purchased' scope" do | |
expect(Item.not_purchased).to include(@unpurchased_item) | |
expect(Item.not_purchased).not_to include(@purchased_item) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment