Skip to content

Commit

Permalink
make necessary modifications for specs to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
maneyko committed Sep 29, 2021
1 parent d8adc5a commit 8d9d9ff
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.6
2.6.6
2 changes: 1 addition & 1 deletion HornsAndHooves-moribus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/moribus/aggregated_cache_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/moribus/aggregated_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 18 additions & 18 deletions spec/moribus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -232,42 +232,42 @@ 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: "[email protected]")
expect{ email.update_attributes(email: "[email protected]") }.not_to raise_error
expect{ email.update!(email: "[email protected]") }.not_to raise_error
end

it "updates lock_version column based on parent relation" do
@other_customer = SpecCustomer.create
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

Expand All @@ -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
Expand Down

0 comments on commit 8d9d9ff

Please sign in to comment.