Skip to content

Instantly share code, notes, and snippets.

@iscott iscott/item_spec.rb
Created Mar 2, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.