Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zishe/7095776 to your computer and use it in GitHub Desktop.
Save zishe/7095776 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe FeaturePool do
it "creates a new instance given valid attributes" do
Fabricate :feature_pool
end
it "is not valid without a name" do
Fabricate.build(:feature_pool, :name => "").should_not be_valid
end
describe "#current" do
it "returns the feature appearance whose position corresponds with #head" do
pool = Fabricate :populated_feature_pool
pool.current.featurable.user.name.should == "John Gruber"
end
it "has some feature appearances" do
pool = Fabricate :populated_feature_pool
pool.should have(5).feature_appearances
end
it "persists its appearances" do
Fabricate :populated_feature_pool, :name => "foo/bar"
pool = FeaturePool.find_by_name("foo/bar")
pool.should have(5).feature_appearances
end
end
end
Fabricator(:feature_pool) do
name "home/primary"
accepts "NewsArticle"
rotate_after 24
head 1
paused false
end
Fabricator(:populated_feature_pool, :from => :feature_pool) do
feature_appearances!(:count => 5) do |feature_pool, position|
Fabricate :feature_appearance, :feature_pool => feature_pool, :position => position
end
end
Fabricator(:feature_appearance) do
featurable! :fabricator => :news_article
position 1
end
Fabricator(:news_article) do
title "This Is the New Apple"
body "Superior products _and_ mainstream prices."
user!
end
Fabricator(:user) do
name "John Gruber"
email { sequence(:email) {|n| "user#{n}@example.com" } }
end
FactoryGirl.define do
factory :feature_pool do
name "home/primary"
accepts "NewsArticle"
rotate_after 24
head 1
paused false
factory :populated_feature_pool do
feature_appearances { FactoryGirl.build_list(:feature_appearance, 5) }
end
end
factory :feature_appearance do
association :featurable, :factory => :news_article
position 1
end
factory :news_article do
title "This Is the New Apple"
body "Superior products _and_ mainstream prices."
user
end
factory :user do
name "John Gruber"
sequence(:email) {|n| "user#{n}@example.com" }
end
end
require 'spec_helper'
describe FeaturePool do
it "creates a new instance given valid attributes" do
FactoryGirl.create(:feature_pool)
end
it "is not valid without a name" do
FactoryGirl.build(:feature_pool, :name => "").should_not be_valid
end
describe "#current" do
it "returns the feature appearance whose position corresponds with #head" do
pool = FactoryGirl.create(:populated_feature_pool)
pool.current.featurable.user.name.should == "John Gruber"
end
it "has some feature appearances" do
pool = FactoryGirl.create(:populated_feature_pool)
pool.should have(5).feature_appearances
end
it "persists its appearances" do
FactoryGirl.create(:populated_feature_pool, :name => "foo/bar")
pool = FeaturePool.find_by_name("foo/bar")
pool.should have(5).feature_appearances
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment