require 'spec_helper' describe "Inter::Actable Instance" do before :each do @article = Article.create! end describe "getting and setting" do describe "booleans" do it "#is_*!" do @article.is_published! expect(@article).to have(1).interaction expect(@article.interactions.last.key).to be == "published" expect(@article.interactions.last.value).to be_true end it "#isnt_*!" do @article.isnt_published! expect(@article).to have(1).interaction expect(@article.interactions.last.key).to be == "published" expect(@article.interactions.last.value).to be_false end it "#is_not_!" do @article.is_not_published! expect(@article).to have(1).interaction expect(@article.interactions.last.key).to be == "published" expect(@article.interactions.last.value).to be_false end it "#is_*?" do expect(@article.is_published?).to be_false @article.is_published! expect(@article.is_published?).to be_true @article.isnt_published! expect(@article.is_published?).to be_false end it "#isnt_*?" do expect(@article.isnt_published?).to be_true @article.is_published! expect(@article.isnt_published?).to be_false @article.isnt_published! expect(@article.isnt_published?).to be_true end it "#is_not_*?" do @article.is_published! expect(@article.is_not_published?).to be_false @article.is_not_published! expect(@article.isnt_published?).to be_true end it "#is_*_and_is_*?" do @article.is_published! @article.is_hidden! expect(@article.is_hidden_and_published?).to be_true @article.isnt_hidden! expect(@article.is_hidden_and_published?).to be_false end it "#is_*_and_is_not_*?" do @article.is_published! @article.is_hidden! expect(@article.is_hidden_and_is_not_published?).to be_false @article.isnt_published! expect(@article.is_hidden_and_is_not_published?).to be_true end it "#isnt_*_and_is_*?" do @article.is_published! @article.is_hidden! expect(@article.isnt_hidden_and_is_published?).to be_false @article.isnt_hidden! expect(@article.isnt_hidden_and_is_published?).to be_true end it "#is_not_*_and_is_*?" do @article.is_published! @article.is_hidden! expect(@article.is_not_hidden_and_is_published?).to be_false @article.isnt_hidden! expect(@article.is_not_hidden_and_is_published?).to be_true end it "#is_not_*_and_is_not_*?" do @article.is_published! @article.is_hidden! expect(@article.is_not_hidden_and_is_not_published?).to be_false @article.isnt_hidden! @article.isnt_published! expect(@article.is_not_hidden_and_is_not_published?).to be_true end it "#is_*_and_isnt_*?" do @article.is_published! @article.is_hidden! expect(@article.is_hidden_and_isnt_published?).to be_false @article.isnt_published! expect(@article.is_hidden_and_isnt_published?).to be_true end it "#is_*_and_is_*_and_is_*?" do @article.is_published! @article.is_hidden! expect(@article.is_hidden_and_is_published_and_is_amazing?).to be_false @article.is_amazing! expect(@article.is_hidden_and_is_published_and_is_amazing?).to be_true end it "#isnt_*_and_is_*_and_is_not_*?" do @article.is_published! @article.isnt_hidden! @article.is_amazing! expect(@article.isnt_hidden_and_is_published_and_is_not_amazing?).to be_false @article.isnt_amazing! expect(@article.isnt_hidden_and_is_published_and_is_not_amazing?).to be_true end end describe "complex values" do it "#set *symbol, *" do @article.set :tags, [:foo, :bar] expect(@article).to have(1).interaction expect(@article.interactions.last.key).to be == "tags" expect(@article.interactions.last.value).to be == ["foo", "bar"] end it "#set *string, *" do @article.set "tags", [:foo, :bar] expect(@article).to have(1).interaction expect(@article.interactions.last.key).to be == "tags" expect(@article.interactions.last.value).to be == ["foo", "bar"] end it "#get *symbol" do @article.set "tags", [:foo, :bar] expect(@article.get(:tags)).to be == ["foo", "bar"] end it "#get *string" do @article.set :tags, [:foo, :bar] expect(@article.get("tags")).to be == ["foo", "bar"] end it "#has? *" do expect(@article.has? :tags).to be_false @article.set "tags", [:foo, :bar] expect(@article.has? :tags).to be_true @article.set "tags", nil expect(@article.has? :tags).to be_false end end end describe "direct access methods" do describe "booleans" do it "#is *string" do @article.is "published" expect(@article).to have(1).interaction expect(@article.interactions.last.key).to be == "published" expect(@article.interactions.last.value).to be_true end it "#is *symbol" do @article.is :published expect(@article).to have(1).interaction expect(@article.interactions.last.key).to be == "published" expect(@article.interactions.last.value).to be_true end it "#is *implicit_array" do @article.is :hidden, :published expect(@article).to have(2).interactions expect(@article.interactions.last.key).to be == "published" expect(@article.interactions.last.value).to be_true end it "#is *explicit_array" do @article.is [:hidden, :published] expect(@article).to have(2).interactions expect(@article.interactions.last.key).to be == "published" expect(@article.interactions.last.value).to be_true end it "#is *array with negatives" do @article.is [:hidden, :not_published] expect(@article).to have(2).interactions expect(@article.interactions.last.key).to be == "published" expect(@article.interactions.last.value).to be_false end it "#is? *" do expect(@article.is?(:promoted, :published)).to be_false @article.is [:promoted, :published] expect(@article.is?(:promoted, :published)).to be_true @article.is :not_published expect(@article.is?(:promoted, :published)).to be_false end it "#is? []" do expect(@article.is?([:promoted, :published])).to be_false @article.is [:promoted, :published] expect(@article.is?([:promoted, :published])).to be_true @article.is :not_published expect(@article.is?([:promoted, :published])).to be_false end end end describe "history" do describe "booleans" do it "#was_*?" do expect(@article.was_published?).to be_false @article.is_published! @article.isnt_published! expect(@article.was_published?).to be_true end it "#wasnt_?" do expect(@article.wasnt_published?).to be_true @article.is_published! @article.isnt_published! expect(@article.wasnt_published?).to be_false end it "#was_not_?" do expect(@article.was_not_published?).to be_true @article.is_published! @article.isnt_published! expect(@article.was_not_published?).to be_false end it "#was_*_and_*" do expect(@article.was_published_and_hidden?).to be_false @article.is_published_and_hidden! @article.isnt_published_and_hidden! expect(@article.was_published_and_hidden?).to be_true end it "#was_*_and_was_*?" do expect(@article.was_published_and_was_hidden?).to be_false @article.is_published_and_hidden! @article.isnt_published_and_hidden! expect(@article.was_published_and_was_hidden?).to be_true end it "#was_*_and_was_not_*?" do expect(@article.was_published_and_was_not_hidden?).to be_false @article.is_published! @article.isnt_published! expect(@article.was_published_and_was_not_hidden?).to be_true end it "#was_not_*_and_was_*?" do expect(@article.was_not_published_and_was_hidden?).to be_false @article.is_hidden! @article.isnt_hidden! expect(@article.was_not_published_and_was_hidden?).to be_true end it "#was_*_and_wasnt_*?" do expect(@article.was_published_and_wasnt_hidden?).to be_false @article.is_published! @article.isnt_published! expect(@article.was_published_and_wasnt_hidden?).to be_true end it "#wasnt_*_and_was_*?" do expect(@article.wasnt_published_and_was_hidden?).to be_false @article.is_hidden! @article.isnt_hidden! expect(@article.wasnt_published_and_was_hidden?).to be_true end it "#was_*_and_wasnt_*_and_was_*?" do expect(@article.was_published_and_wasnt_hidden_and_was_promoted?).to be_false @article.is_published! @article.is_promoted! @article.isnt_published! expect(@article.was_published_and_wasnt_hidden_and_was_promoted?).to be_true end it "#history *string" do @article.is_published! @article.isnt_published_and_is_hidden! history = @article.history "published" expect(history).to have(2).interactions history.each do |interaction| expect(interaction).to be_a(Inter::Action) expect(interaction.key).to be == "published" end end it "#history *symbol" do @article.is_published! @article.isnt_published_and_is_hidden! history = @article.history :published expect(history).to have(2).interactions history.each do |interaction| expect(interaction).to be_a(Inter::Action) expect(interaction.key).to be == "published" end end it "#history *implicit array" do @article.is_published! @article.isnt_published_and_is_hidden! history = @article.history :published, :hidden expect(history).to have(3).interactions end it "#history *explicit array" do @article.is_published! @article.isnt_published_and_is_hidden! history = @article.history ["published", "hidden"] expect(history).to have(3).interactions end pending "#history *implicit hash" pending "#history *explicit hash" end end end