Skip to content

Instantly share code, notes, and snippets.

@erez-rabih
Last active December 23, 2015 21:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erez-rabih/6697511 to your computer and use it in GitHub Desktop.
Save erez-rabih/6697511 to your computer and use it in GitHub Desktop.
Rspec refactoring - initial test suite
describe FindReaction do
#Spec 1
it "should return no reaction template when there are no reaction templates" do
post = create :post, locale: "en", type: "basic"
reaction = FindReaction.for(@post).reaction
reaction.blank?.should == true
end
#Spec 2
it "should return no reaction template if reaction templates exist, but non fitting" do
post = create :post, locale: "en", type: "basic"
reaction1 = ReactionTemplate.create locale: "de", subtypes: ["basic", "top_x"]
reaction2 = ReactionTemplate.create locale: "en", subtypes: ["slideshow", "top_x"]
reaction = FindReaction.for(@post).reaction
reaction.blank?.should == true
end
#Spec 3
it "should return the right reaction if it exists" do
post = create :post, locale: "en", type: "basic"
reaction1 = ReactionTemplate.create locale: "en", subtypes: ["basic", "top_x"]
reaction2 = ReactionTemplate.create locale: "en", subtypes: ["basic", "top_x"]
reaction3 = ReactionTemplate.create locale: "en" , subtypes: ["slideshow", "top_x"]
reaction = FindReaction.for(@post).reaction
reaction.blank?.should == false
reaction.should eq reaction2
end
#Spec 4
it "should change posts reaction_template when attaching it" do
post = create :post, locale: "en", type: "basic"
post.reaction_template.nil?.should == true
reaction = ReactionTemplate.create locale: "en", subtypes: ["basic", "top_x"]
FindReaction.for(post).attach
post.reaction_template.nil?.should == false
post.reaction_template.should eq reaction
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment