Skip to content

Instantly share code, notes, and snippets.

@erez-rabih
Created September 25, 2013 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erez-rabih/6698414 to your computer and use it in GitHub Desktop.
Save erez-rabih/6698414 to your computer and use it in GitHub Desktop.
describe FindReaction do
before :all do
@post = build :post, locale: "en", type: "basic"
end
before :each do
@post.reaction = nil
end
describe :reaction do
#Spec 1
it "should return no reaction template when there are no reaction templates" do
reaction = FindReaction.for(@post).reaction
reaction.should be_blank
end
#Spec 2
it "should return no reaction template if reaction templates exist, but non fitting" do
reaction1 = ReactionTemplate.create! locale: "de", subtypes: ["basic", "top_x"]
reaction2 = ReactionTemplate.create! locale: "en", subtypes: ["slideshow", "top_x"]
reaction = FindReaction.for(@post).reaction
reaction.should be_blank
end
#Spec 3
it "should return the right reaction if it exists" do
reaction1 = ReactionTemplate.create! locale: @post.locale, subtypes: [@post.type, "top_x"]
reaction2 = ReactionTemplate.create! locale: @post.locale, subtypes: [@post.type, "top_x"]
reaction3 = ReactionTemplate.create! locale: @post.locale, subtypes: ["slideshow", "top_x"]
reaction = FindReaction.for(@post).reaction
reaction.should_not be_blank
reaction.should eq reaction2
end
end
describe :attach do
#Spec 4
it "should change posts reaction_template when attaching it" do
post.reaction_template.should be_nil
reaction = ReactionTemplate.create! locale: @post.locale, subtypes: [@post.type, "top_x"]
FindReaction.for(post).attach
post.reaction_template.should_not be_nil
post.reaction_template.should eq reaction
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment