test/lib/archiveable_test.rb in archiveable-0.0.3 vs test/lib/archiveable_test.rb in archiveable-0.0.5

- old
+ new

@@ -1,9 +1,9 @@ require_relative "../test_helper" describe Archiveable do - class MockModel + class MockModel < MiniTest::Mock def self.scopes @scopes end def self.scope(name, callback) @@ -13,19 +13,19 @@ attr_accessor :archived_at include Archiveable end + subject { MockModel.new } + describe ".included" do it "sets the published and archived scopes" do MockModel.scopes.keys.must_equal [:published, :archived] end end describe ".archived" do - subject { MockModel.new } - it "returns true when there is an archived_at date" do subject.archived_at = Time.now subject.archived.must_equal true end @@ -47,12 +47,10 @@ subject.archived_at.must_equal nil end end describe ".published" do - subject { MockModel.new } - it "returns true when it is not archived" do subject.archived = false subject.published.must_equal true end @@ -62,8 +60,40 @@ end it "sets the archived to false when published is true" do subject.published = true subject.archived.must_equal false + end + end + + describe "#archive" do + it "updates the archived to true" do + subject.expect :update, true, [{archived: true}] + subject.archive + subject.verify + end + end + + describe "#archive!" do + it "updates the archived to true" do + subject.expect :update!, true, [{archived: true}] + subject.archive! + subject.verify + end + end + + describe "#publish" do + it "updates the archived to false" do + subject.expect :update, true, [{archived: false}] + subject.publish + subject.verify + end + end + + describe "#publish!" do + it "updates the archived to false" do + subject.expect :update!, true, [{archived: false}] + subject.publish! + subject.verify end end end