Skip to content

Instantly share code, notes, and snippets.

@iscott
Created March 2, 2015 18:37
Show Gist options
  • Save iscott/150ac6fe67f0265c8c4a to your computer and use it in GitHub Desktop.
Save iscott/150ac6fe67f0265c8c4a to your computer and use it in GitHub Desktop.
Testing scopes with RSPEC
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