Last active
December 15, 2015 17:29
-
-
Save rondy/5296730 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ProductsController < ApplicationController | |
def index | |
@products = Product.vitrine(34) | |
respond_with @products | |
end | |
end | |
class Product < ActiveRecord::Base | |
def self.vitrine(limit) | |
with_state(:published).limit(limit) | |
end | |
end | |
describe Product do | |
describe 'vitrine' do | |
it 'returns published products in a given limit ' do | |
published_product_1 = Factory.create(:product, :published => true) | |
published_product_2 = Factory.create(:product, :published => true) | |
published_product_3 = Factory.create(:product, :published => true) | |
unpublished_product_4 = Factory.create(:product, :published => false) | |
vitrine = Product.vitrine(2) | |
vitrine.should have(2).item | |
vitrine.should include published_product_1 | |
vitrine.should include published_product_2 | |
vitrine.should_not include unpublished_product_3 | |
vitrine.should_not include unpublished_product_4 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment