diff --git a/.ruby-version b/.ruby-version index 7bf4b6a..338a5b5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4.6 +2.6.6 diff --git a/HornsAndHooves-moribus.gemspec b/HornsAndHooves-moribus.gemspec index 3be0985..f987fb2 100644 --- a/HornsAndHooves-moribus.gemspec +++ b/HornsAndHooves-moribus.gemspec @@ -27,5 +27,5 @@ Gem::Specification.new do |s| s.add_development_dependency "rake" s.add_development_dependency "rspec" s.add_development_dependency "rspec-rails" - s.add_development_dependency "sqlite3", "~> 1.3.6" + s.add_development_dependency "sqlite3" end diff --git a/lib/moribus/aggregated_cache_behavior.rb b/lib/moribus/aggregated_cache_behavior.rb index d5ecf58..1f1cca3 100644 --- a/lib/moribus/aggregated_cache_behavior.rb +++ b/lib/moribus/aggregated_cache_behavior.rb @@ -31,7 +31,7 @@ module AggregatedCacheBehavior class_attribute :aggregated_records_cache self.aggregated_records_cache = {} - after_save :cache_aggregated_record, :on => :create + after_commit :cache_aggregated_record, :on => :create end # Class methods for model that includes AggregatedCacheBehavior diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js new file mode 100644 index 0000000..6277764 --- /dev/null +++ b/spec/dummy/app/assets/config/manifest.js @@ -0,0 +1,5 @@ +// Sprockets 4.0+ requires this file to define asset paths. + +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/spec/moribus/aggregated_behavior_spec.rb b/spec/moribus/aggregated_behavior_spec.rb index 4689e2e..77aeafa 100644 --- a/spec/moribus/aggregated_behavior_spec.rb +++ b/spec/moribus/aggregated_behavior_spec.rb @@ -93,7 +93,7 @@ class SpecCustomerFeature < MoribusSpecModel(feature_name: :string) it "looks up self and replaces id with existing on update" do name = SpecPersonName.create first_name: "Alice", last_name: "Smith" - name.update_attributes first_name: "John" + name.update! first_name: "John" expect(name.id).to eq @existing.id end diff --git a/spec/moribus_spec.rb b/spec/moribus_spec.rb index 87b5516..77b36da 100644 --- a/spec/moribus_spec.rb +++ b/spec/moribus_spec.rb @@ -128,7 +128,7 @@ class SpecCustomerEmail < MoribusSpecModel(spec_customer_id: :integer, suppress(Exception) do expect { - @info.update_attributes spec_customer_id: nil, spec_person_name_id: 2 + @info.update! spec_customer_id: nil, spec_person_name_id: 2 }.not_to change(SpecCustomerInfo, :count) end @@ -155,25 +155,25 @@ class SpecCustomerEmail < MoribusSpecModel(spec_customer_id: :integer, it "creates a new current record if updated" do expect { - @info.update_attributes(spec_person_name_id: 2) + @info.update!(spec_person_name_id: 2) }.to change(SpecCustomerInfo, :count).by(1) end it "replaces itself with new id" do old_id = @info.id - @info.update_attributes(spec_person_name_id: 2) + @info.update!(spec_person_name_id: 2) expect(@info.id).not_to eq old_id end it "sets is_current record to false for superseded record" do old_id = @info.id - @info.update_attributes(spec_person_name_id: 2) + @info.update!(spec_person_name_id: 2) expect(SpecCustomerInfo.find(old_id).is_current).to eq false end it "sets previous_id to the id of the previous record" do old_id = @info.id - @info.update_attributes(spec_person_name_id: 2) + @info.update!(spec_person_name_id: 2) expect(@info.previous_id).to eq old_id end @@ -191,7 +191,7 @@ class SpecCustomerEmail < MoribusSpecModel(spec_customer_id: :integer, status: "unverified", is_current: true ) - expect{ email.update_attributes(status: "verified") }.not_to raise_error + expect{ email.update!(status: "verified") }.not_to raise_error end describe "updated_at and created_at" do @@ -221,9 +221,9 @@ class SpecCustomerEmail < MoribusSpecModel(spec_customer_id: :integer, end it "raises a stale object error" do - @info1.update_attributes(spec_person_name_id: 3) + @info1.update!(spec_person_name_id: 3) - expect{ @info2.update_attributes(spec_person_name_id: 4) }. + expect{ @info2.update!(spec_person_name_id: 4) }. to raise_error(ActiveRecord::StaleObjectError, /Attempted to update_current \(version #{@info2.lock_version}\) a stale object: SpecCustomerInfo\./) end @@ -232,30 +232,30 @@ class SpecCustomerEmail < MoribusSpecModel(spec_customer_id: :integer, spec_customer_info = @customer.spec_customer_info expect { - spec_customer_info.update_attributes(spec_person_name_id: 3) + spec_customer_info.update!(spec_person_name_id: 3) }.to change { spec_customer_info.lock_version }.from(0).to(1) expect { - spec_customer_info.update_attributes(spec_person_name_id: 4) + spec_customer_info.update!(spec_person_name_id: 4) }.to change { spec_customer_info.lock_version }.from(1).to(2) end it "does not fail to update if a lock version growth is for any reason not monotonic" do spec_customer_info = @customer.spec_customer_info - spec_customer_info.update_attributes(spec_person_name_id: 3) - spec_customer_info.update_attributes(spec_person_name_id: 4) + spec_customer_info.update!(spec_person_name_id: 3) + spec_customer_info.update!(spec_person_name_id: 4) SpecCustomerInfo.where(spec_customer_id: @customer.id, lock_version: 1).delete_all expect { - spec_customer_info.update_attributes(spec_person_name_id: 5) + spec_customer_info.update!(spec_person_name_id: 5) }.to change { spec_customer_info.lock_version }.from(2).to(3) end it "does not fail if no locking_column is present" do email = SpecCustomerEmail.create(spec_customer_id: 1, email: "foo@bar.com") - expect{ email.update_attributes(email: "foo2@bar.com") }.not_to raise_error + expect{ email.update!(email: "foo2@bar.com") }.not_to raise_error end it "updates lock_version column based on parent relation" do @@ -263,11 +263,11 @@ class SpecCustomerEmail < MoribusSpecModel(spec_customer_id: :integer, spec_customer_info = @customer.spec_customer_info expect { - spec_customer_info.update_attributes(spec_person_name_id: 3) + spec_customer_info.update!(spec_person_name_id: 3) }.to change { spec_customer_info.lock_version }.from(0).to(1) expect { - spec_customer_info.update_attributes(spec_customer: @other_customer) + spec_customer_info.update!(spec_customer: @other_customer) }.to change { spec_customer_info.lock_version }.from(1).to(0) end @@ -282,10 +282,10 @@ class SpecCustomerEmail < MoribusSpecModel(spec_customer_id: :integer, expect( other_info_with_type.lock_version ).to eq 0 - info_with_type.update_attributes(spec_status: :active) + info_with_type.update!(spec_status: :active) expect( info_with_type.lock_version ).to eq 1 - info_with_type.update_attributes(spec_status: :inactive) + info_with_type.update!(spec_status: :inactive) expect( info_with_type.lock_version ).to eq 2 expect( other_info_with_type.lock_version ).to eq 0