Created
September 25, 2013 12:12
-
-
Save erez-rabih/6698783 to your computer and use it in GitHub Desktop.
This file contains 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
describe FindReaction do | |
before :all do | |
@post = build :post, locale: "en", type: "basic" | |
end | |
before :each do | |
@post.reaction = nil | |
end | |
describe :reaction do | |
subject { FindReaction.for(@post).reaction } | |
#Spec 1 | |
context "there are no reaction templates" do | |
it {should be_blank } | |
end | |
#Spec 2 | |
context "reaction templates exist, but non fitting" do | |
before :each do | |
reaction1 = ReactionTemplate.create! locale: "de", subtypes: ["basic", "top_x"] | |
reaction2 = ReactionTemplate.create! locale: "en", subtypes: ["slideshow", "top_x"] | |
end | |
it {should be_blank } | |
end | |
#Spec 3 | |
context "fitting reaction templates exist" do | |
before :each 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"] | |
end | |
it {should_not be_blank} | |
it {should eq @reaction2} | |
end | |
end | |
describe :attach do | |
#Spec 4 | |
context "attaching a reaction to post" do | |
before :each do | |
@reaction = ReactionTemplate.create! locale: @post.locale, subtypes: [@post.type, "top_x"] | |
end | |
it "should change posts reaction template" do | |
expect { | |
FindReaction.for(@post).attach | |
}.to change{@post.reaction_template}.from(nil).to(@reaction) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment