2014-10-09 15:04:17 -04:00
|
|
|
require 'rails_helper'
|
2014-10-06 19:13:39 -04:00
|
|
|
|
2014-10-09 15:04:17 -04:00
|
|
|
describe Gadget, :type => :model do
|
2014-10-31 10:40:43 -04:00
|
|
|
it { is_expected.to be_versioned }
|
2014-10-06 19:13:39 -04:00
|
|
|
|
2014-10-06 19:52:06 -04:00
|
|
|
let(:gadget) { Gadget.create!(:name => 'Wrench', :brand => 'Acme') }
|
2014-10-06 19:13:39 -04:00
|
|
|
|
|
|
|
describe "updates", :versioning => true do
|
|
|
|
it "should generate a version for updates to `name` attribute" do
|
|
|
|
expect { gadget.update_attribute(:name, 'Hammer').to change{gadget.versions.size}.by(1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should ignore for updates to `brand` attribute" do
|
|
|
|
expect { gadget.update_attribute(:brand, 'Stanley') }.to_not change{gadget.versions.size}
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should still generate a version when only the `updated_at` attribute is updated" do
|
|
|
|
expect { gadget.update_attribute(:updated_at, Time.now) }.to change{gadget.versions.size}.by(1)
|
|
|
|
end
|
|
|
|
end
|
2014-10-07 23:44:38 -04:00
|
|
|
|
|
|
|
describe "Methods" do
|
|
|
|
describe "Instance", :versioning => true do
|
|
|
|
describe "private" do
|
2014-10-09 15:04:17 -04:00
|
|
|
describe '#changed_notably?' do
|
2014-10-07 23:44:38 -04:00
|
|
|
subject { Gadget.new(:created_at => Time.now) }
|
|
|
|
|
2015-12-13 01:14:59 -05:00
|
|
|
it { expect(subject.private_methods).to include(:changed_notably?) }
|
2014-10-07 23:44:38 -04:00
|
|
|
|
|
|
|
context "create events" do
|
2014-10-09 15:04:17 -04:00
|
|
|
it { expect(subject.send(:changed_notably?)).to be true }
|
2014-10-07 23:44:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "update events" do
|
|
|
|
before { subject.save! }
|
|
|
|
|
|
|
|
context "without update timestamps" do
|
|
|
|
it "should only acknowledge non-ignored attrs" do
|
|
|
|
subject.name = 'Wrench'
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(subject.send(:changed_notably?)).to be true
|
2014-10-07 23:44:38 -04:00
|
|
|
end
|
|
|
|
|
2015-07-15 21:28:07 -04:00
|
|
|
it "should not acknowledge ignored attr (brand)" do
|
2014-10-07 23:44:38 -04:00
|
|
|
subject.brand = 'Acme'
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(subject.send(:changed_notably?)).to be false
|
2014-10-07 23:44:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with update timestamps" do
|
|
|
|
it "should only acknowledge non-ignored attrs" do
|
|
|
|
subject.name, subject.updated_at = 'Wrench', Time.now
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(subject.send(:changed_notably?)).to be true
|
2014-10-07 23:44:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not acknowledge ignored attrs and timestamps only" do
|
|
|
|
subject.brand, subject.updated_at = 'Acme', Time.now
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(subject.send(:changed_notably?)).to be false
|
2014-10-07 23:44:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-10-06 19:13:39 -04:00
|
|
|
end
|