From 2b479a7f084997df49f474fac6e3ac666b9b9b99 Mon Sep 17 00:00:00 2001 From: Edouard Chin Date: Tue, 4 Dec 2018 22:10:35 +0100 Subject: [PATCH] Support rails 6.0.0 (#1172) * Change update_attributes to update In Rails 6.0 update_attributes/update_attributes! is considered deprecated. Method update/update! is the replacement. * CI: Don't use Bundler 1.16.1 - Bundler 1.16.1 has bug where dependencies can't be resolved properly when a gem is a release candidate or an alpha version. The underlying bundler issue can be found here https://github.com/bundler/bundler/issues/6449 * Disable eager_load in test env: - In Rails 6.0, rails/rails@3b95478 made a change to eagerly define attribute methods of a Model when `eager_load` is enabled. This breaks our test suite because of the way we run migration. The TL;DR is that doing `People.attribute_names` will return an empty array instead of `[:id, time_zone, ...]`. You can find a failing build here https://travis-ci.org/paper-trail-gem/paper_trail/jobs/463369634 Basically what happens is: 1) The dummy app boot, attribute methods of each model are defined but since migration didn't run yet, the tables aren't even created resulting in a empty attribute set. 2) Migration runs, but it's already too late. In this commit I disabled eager_loading in test, AFAIT there isn't much benefit in eager_loading the dummy app anyway. Also renaming the `user.rb` file to `postgres_user.rb` in order for rails autoloading to work correctly. --- .travis.yml | 20 ++++- Appraisals | 6 ++ CHANGELOG.md | 4 +- README.md | 50 +++++------ gemfiles/ar_6.0.gemfile | 8 ++ .../postgres_array_serializer.rb | 3 +- paper_trail.gemspec | 2 +- .../app/controllers/widgets_controller.rb | 2 +- .../app/models/{user.rb => postgres_user.rb} | 0 spec/dummy_app/config/environments/test.rb | 7 +- spec/models/animal_spec.rb | 16 ++-- spec/models/article_spec.rb | 34 +++---- spec/models/boolit_spec.rb | 8 +- spec/models/callback_modifier_spec.rb | 6 +- spec/models/car_spec.rb | 2 +- spec/models/custom_primary_key_record_spec.rb | 2 +- spec/models/document_spec.rb | 12 +-- spec/models/family/celebrity_family_spec.rb | 4 +- spec/models/family/family_spec.rb | 4 +- spec/models/fruit_spec.rb | 2 +- spec/models/json_version_spec.rb | 12 +-- spec/models/legacy_widget_spec.rb | 10 +-- spec/models/on/create_spec.rb | 4 +- spec/models/on/destroy_spec.rb | 4 +- spec/models/on/empty_array_spec.rb | 4 +- spec/models/on/update_spec.rb | 4 +- spec/models/person_spec.rb | 8 +- spec/models/pet_spec.rb | 14 +-- spec/models/post_spec.rb | 4 +- spec/models/skipper_spec.rb | 8 +- spec/models/translation_spec.rb | 6 +- spec/models/version_spec.rb | 32 +++---- spec/models/widget_spec.rb | 30 +++---- .../error.rb | 8 +- .../ignore.rb | 8 +- .../association_reify_error_behaviour/warn.rb | 8 +- .../associations/belongs_to_spec.rb | 16 ++-- spec/paper_trail/associations/habtm_spec.rb | 18 ++-- .../paper_trail/associations/has_many_spec.rb | 48 +++++----- .../associations/has_many_through_spec.rb | 48 +++++----- spec/paper_trail/associations/has_one_spec.rb | 30 +++---- spec/paper_trail/model_spec.rb | 88 +++++++++---------- spec/paper_trail/version_limit_spec.rb | 2 +- spec/paper_trail/version_spec.rb | 14 +-- 44 files changed, 327 insertions(+), 293 deletions(-) create mode 100644 gemfiles/ar_6.0.gemfile rename spec/dummy_app/app/models/{user.rb => postgres_user.rb} (100%) diff --git a/.travis.yml b/.travis.yml index 7954a2873..1e71b2b96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,9 @@ cache: bundler # For example, if our gemspec says `required_ruby_version = ">= 2.3.0"`, and # ruby 2.5.0 has just been released, then we test 2.3 and 2.5, but not 2.4. rvm: - - 2.5.0 - - 2.3.6 + - 2.3.8 + - 2.4.5 + - 2.5.3 env: global: @@ -25,11 +26,26 @@ env: # the meantime. sudo: required +before_install: + - gem update bundler + gemfile: - gemfiles/ar_4.2.gemfile - gemfiles/ar_5.1.gemfile - gemfiles/ar_5.2.gemfile + - gemfiles/ar_6.0.gemfile matrix: + exclude: + # rails 6 will not support ruby < 2.4.1 + - rvm: 2.3.8 + gemfile: gemfiles/ar_6.0.gemfile + # optimization: don't test intermediate rubies (see above) + - rvm: 2.4.5 + gemfile: gemfiles/ar_4.2.gemfile + - rvm: 2.4.5 + gemfile: gemfiles/ar_5.1.gemfile + - rvm: 2.4.5 + gemfile: gemfiles/ar_5.2.gemfile fast_finish: true addons: postgresql: "9.4" diff --git a/Appraisals b/Appraisals index e46d851b2..af325e3c9 100644 --- a/Appraisals +++ b/Appraisals @@ -30,3 +30,9 @@ appraise "ar-5.2" do gem "activerecord", "~> 5.2.1" gem "rails-controller-testing", "~> 1.0.2" end + +appraise "ar-6.0" do + # TODO: Use actual version number once 6.0 beta is released + gem "activerecord", github: "rails/rails" + gem "rails-controller-testing", "~> 1.0.3" +end diff --git a/CHANGELOG.md b/CHANGELOG.md index bbdfd279d..c751e4f98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). - [#1158](https://github.com/paper-trail-gem/paper_trail/pull/1158) — Add the ability to pass options, such as `scope` or `extend:` to the `has_many :versions` association macro. +- [#1172](https://github.com/paper-trail-gem/paper_trail/pull/1172) - + Support rails 6.0.0 alpha. ### Fixed @@ -1009,7 +1011,7 @@ in the `PaperTrail::Version` class through a `Rails::Engine` when the gem is use `ActionController::API` for compatibility with the [`rails-api`](https://github.com/rails-api/rails-api) gem. - [#312](https://github.com/paper-trail-gem/paper_trail/issues/312) - Fix RSpec `with_versioning` class level helper method. - `model_instance.without_versioning` now yields the `model_instance`, enabling syntax like this: - `model_instance.without_versioning { |obj| obj.update_attributes(:name => 'value') }`. + `model_instance.without_versioning { |obj| obj.update(:name => 'value') }`. - Deprecated `Model.paper_trail_on` and `Model.paper_trail_off` in favor of bang versions of the methods. Deprecation warning informs users that the non-bang versions of the methods will be removed in version `4.0` diff --git a/README.md b/README.md index 2fbb3ba2a..192d2a61e 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,8 @@ has been destroyed. | paper_trail | branch | ruby | activerecord | | -------------- | ---------- | -------- | ------------- | | unreleased | master | >= 2.3.0 | >= 4.2, < 6 | -| 10 | 10-stable | >= 2.3.0 | >= 4.2, < 6 | -| 9 | 9-stable | >= 2.3.0 | >= 4.2, < 6 | +| 10 | 10-stable | >= 2.3.0 | >= 4.2, < 5.3 | +| 9 | 9-stable | >= 2.3.0 | >= 4.2, < 5.3 | | 8 | 8-stable | >= 2.2.0 | >= 4.2, < 5.2 | | 7 | 7-stable | >= 2.1.0 | >= 4.0, < 5.2 | | 6 | 6-stable | >= 1.9.3 | >= 4.0, < 5.2 | @@ -167,7 +167,7 @@ widget.name # 'Doobly' # Add has_paper_trail to Widget model. widget.versions # [] -widget.update_attributes name: 'Wotsit' +widget.update name: 'Wotsit' widget.versions.last.reify.name # 'Doobly' widget.versions.last.event # 'update' ``` @@ -333,11 +333,11 @@ a = Article.create a.versions.size # 1 a.versions.last.event # 'create' a.paper_trail_event = 'update title' -a.update_attributes title: 'My Title' +a.update title: 'My Title' a.versions.size # 2 a.versions.last.event # 'update title' a.paper_trail_event = nil -a.update_attributes title: 'Alternate' +a.update title: 'Alternate' a.versions.size # 3 a.versions.last.event # 'update' ``` @@ -414,9 +414,9 @@ Changes to other attributes will create a version record. ```ruby a = Article.create a.versions.length # 1 -a.update_attributes title: 'My Title', rating: 3 +a.update title: 'My Title', rating: 3 a.versions.length # 1 -a.update_attributes title: 'Greeting', content: 'Hello' +a.update title: 'Greeting', content: 'Hello' a.versions.length # 2 a.paper_trail.previous_version.title # 'My Title' ``` @@ -436,9 +436,9 @@ Only changes to the `title` will create a version record. ```ruby a = Article.create a.versions.length # 1 -a.update_attributes title: 'My Title' +a.update title: 'My Title' a.versions.length # 2 -a.update_attributes content: 'Hello' +a.update content: 'Hello' a.versions.length # 2 a.paper_trail.previous_version.content # nil ``` @@ -457,14 +457,14 @@ will create a version record. ```ruby a = Article.create a.versions.length # 1 -a.update_attributes content: 'Hello' +a.update content: 'Hello' a.versions.length # 2 -a.update_attributes title: 'Title One' +a.update title: 'Title One' a.versions.length # 3 -a.update_attributes content: 'Hai' +a.update content: 'Hai' a.versions.length # 3 a.paper_trail.previous_version.content # "Hello" -a.update_attributes title: 'Title Two' +a.update title: 'Title Two' a.versions.length # 4 a.paper_trail.previous_version.content # "Hai" ``` @@ -592,7 +592,7 @@ PaperTrail makes reverting to a previous version easy: ```ruby widget = Widget.find 42 -widget.update_attributes name: 'Blah blah' +widget.update name: 'Blah blah' # Time passes.... widget = widget.paper_trail.previous_version # the widget as it was before the update widget.save # reverted @@ -707,7 +707,7 @@ widget.versions.last.changeset # "updated_at"=>[nil, 2015-08-10 04:10:40 UTC], # "id"=>[nil, 1] # } -widget.update_attributes name: 'Robert' +widget.update name: 'Robert' widget.versions.last.changeset # { # "name"=>["Bob", "Robert"], @@ -770,7 +770,7 @@ version's `whodunnit` column. ```ruby PaperTrail.request.whodunnit = 'Andy Stewart' -widget.update_attributes name: 'Wibble' +widget.update name: 'Wibble' widget.versions.last.whodunnit # Andy Stewart ``` @@ -795,7 +795,7 @@ To set whodunnit temporarily, for the duration of a block, use ```ruby PaperTrail.request(whodunnit: 'Dorian Marié') do - widget.update_attributes name: 'Wibble' + widget.update name: 'Wibble' end ``` @@ -839,10 +839,10 @@ like it does, call `paper_trail_originator` on the object. ```ruby widget = Widget.find 153 # assume widget has 0 versions PaperTrail.request.whodunnit = 'Alice' -widget.update_attributes name: 'Yankee' +widget.update name: 'Yankee' widget.paper_trail.originator # 'Alice' PaperTrail.request.whodunnit = 'Bob' -widget.update_attributes name: 'Zulu' +widget.update name: 'Zulu' widget.paper_trail.originator # 'Bob' first_version, last_version = widget.versions.first, widget.versions.last first_version.whodunnit # 'Alice' @@ -1413,9 +1413,9 @@ The `have_a_version_with` matcher makes assertions about versions using ```ruby describe '`have_a_version_with` matcher' do it 'is possible to do assertions on version attributes' do - widget.update_attributes!(name: 'Leonard', an_integer: 1) - widget.update_attributes!(name: 'Tom') - widget.update_attributes!(name: 'Bob') + widget.update!(name: 'Leonard', an_integer: 1) + widget.update!(name: 'Tom') + widget.update!(name: 'Bob') expect(widget).to have_a_version_with name: 'Leonard', an_integer: 1 expect(widget).to have_a_version_with an_integer: 1 expect(widget).to have_a_version_with name: 'Tom' @@ -1430,9 +1430,9 @@ The `have_a_version_with_changes` matcher makes assertions about versions using ```ruby describe '`have_a_version_with_changes` matcher' do it 'is possible to do assertions on version changes' do - widget.update_attributes!(name: 'Leonard', an_integer: 1) - widget.update_attributes!(name: 'Tom') - widget.update_attributes!(name: 'Bob') + widget.update!(name: 'Leonard', an_integer: 1) + widget.update!(name: 'Tom') + widget.update!(name: 'Bob') expect(widget).to have_a_version_with_changes name: 'Leonard', an_integer: 2 expect(widget).to have_a_version_with_changes an_integer: 2 expect(widget).to have_a_version_with_changes name: 'Bob' diff --git a/gemfiles/ar_6.0.gemfile b/gemfiles/ar_6.0.gemfile new file mode 100644 index 000000000..072e70003 --- /dev/null +++ b/gemfiles/ar_6.0.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", github: "rails/rails" +gem "rails-controller-testing", "~> 1.0.3" + +gemspec path: "../" diff --git a/lib/paper_trail/type_serializers/postgres_array_serializer.rb b/lib/paper_trail/type_serializers/postgres_array_serializer.rb index b0c1247e4..b5b1b6a4b 100644 --- a/lib/paper_trail/type_serializers/postgres_array_serializer.rb +++ b/lib/paper_trail/type_serializers/postgres_array_serializer.rb @@ -29,8 +29,7 @@ def deserialize(array) private def active_record_pre_502? - ::ActiveRecord::VERSION::MAJOR < 5 || - (::ActiveRecord::VERSION::MINOR.zero? && ::ActiveRecord::VERSION::TINY < 2) + ::ActiveRecord.gem_version < Gem::Version.new("5.0.2") end def serialize_with_ar(array) diff --git a/paper_trail.gemspec b/paper_trail.gemspec index d8300d354..22049261a 100644 --- a/paper_trail.gemspec +++ b/paper_trail.gemspec @@ -28,7 +28,7 @@ has been destroyed. s.required_ruby_version = ">= 2.3.0" # Rails does not follow semver, makes breaking changes in minor versions. - s.add_dependency "activerecord", [">= 4.2", "< 5.3"] + s.add_dependency "activerecord", [">= 4.2", "< 6.0"] s.add_dependency "request_store", "~> 1.1" s.add_development_dependency "appraisal", "~> 2.2" diff --git a/spec/dummy_app/app/controllers/widgets_controller.rb b/spec/dummy_app/app/controllers/widgets_controller.rb index 08f7f41b1..916b56a65 100644 --- a/spec/dummy_app/app/controllers/widgets_controller.rb +++ b/spec/dummy_app/app/controllers/widgets_controller.rb @@ -12,7 +12,7 @@ def create def update @widget = Widget.find params[:id] - @widget.update_attributes widget_params + @widget.update widget_params head :ok end diff --git a/spec/dummy_app/app/models/user.rb b/spec/dummy_app/app/models/postgres_user.rb similarity index 100% rename from spec/dummy_app/app/models/user.rb rename to spec/dummy_app/app/models/postgres_user.rb diff --git a/spec/dummy_app/config/environments/test.rb b/spec/dummy_app/config/environments/test.rb index 8297e2346..e0757e6cb 100644 --- a/spec/dummy_app/config/environments/test.rb +++ b/spec/dummy_app/config/environments/test.rb @@ -9,8 +9,11 @@ # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # Eager loads all registered namespaces - config.eager_load = true + # In Rails 6.0, rails/rails@3b95478 made a change to eagerly define attribute + # methods of a Model when `eager_load` is enabled. If we used `eager_load`, + # this would break our test suite because of the way we run migration. For + # example, `People.attribute_names` would return an empty array. + config.eager_load = false if config.respond_to?(:public_file_server) config.public_file_server.enabled = true diff --git a/spec/models/animal_spec.rb b/spec/models/animal_spec.rb index 43a81a53a..e1e1ed62e 100644 --- a/spec/models/animal_spec.rb +++ b/spec/models/animal_spec.rb @@ -16,16 +16,16 @@ it "works with custom STI inheritance column" do animal = Animal.create(name: "Animal") - animal.update_attributes(name: "Animal from the Muppets") - animal.update_attributes(name: "Animal Muppet") + animal.update(name: "Animal from the Muppets") + animal.update(name: "Animal Muppet") animal.destroy dog = Dog.create(name: "Snoopy") - dog.update_attributes(name: "Scooby") - dog.update_attributes(name: "Scooby Doo") + dog.update(name: "Scooby") + dog.update(name: "Scooby Doo") dog.destroy cat = Cat.create(name: "Garfield") - cat.update_attributes(name: "Garfield (I hate Mondays)") - cat.update_attributes(name: "Garfield The Cat") + cat.update(name: "Garfield (I hate Mondays)") + cat.update(name: "Garfield The Cat") cat.destroy expect(PaperTrail::Version.count).to(eq(12)) expect(animal.versions.count).to(eq(4)) @@ -45,7 +45,7 @@ it "allows the inheritance_column (species) to be updated" do cat = Cat.create!(name: "Leo") - cat.update_attributes(name: "Spike", species: "Dog") + cat.update(name: "Spike", species: "Dog") dog = Animal.find(cat.id) expect(dog).to be_instance_of(Dog) end @@ -55,7 +55,7 @@ let(:callback_cat) { Cat.create(name: "Markus") } it "trails all events" do - callback_cat.update_attributes(name: "Billie") + callback_cat.update(name: "Billie") callback_cat.destroy expect(callback_cat.versions.collect(&:event)).to eq %w[create update destroy] end diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index b06419836..54ac407a0 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -14,7 +14,7 @@ context "which updates an ignored column" do it "not change the number of versions" do article = described_class.create - article.update_attributes(title: "My first title") + article.update(title: "My first title") expect(PaperTrail::Version.count).to(eq(1)) end end @@ -22,7 +22,7 @@ context "which updates an ignored column with truly Proc" do it "not change the number of versions" do article = described_class.create - article.update_attributes(abstract: "ignore abstract") + article.update(abstract: "ignore abstract") expect(PaperTrail::Version.count).to(eq(1)) end end @@ -30,7 +30,7 @@ context "which updates an ignored column with falsy Proc" do it "change the number of versions" do article = described_class.create - article.update_attributes(abstract: "do not ignore abstract!") + article.update(abstract: "do not ignore abstract!") expect(PaperTrail::Version.count).to(eq(2)) end end @@ -38,7 +38,7 @@ context "which updates an ignored column, ignored with truly Proc and a selected column" do it "change the number of versions" do article = described_class.create - article.update_attributes( + article.update( title: "My first title", content: "Some text here.", abstract: "ignore abstract" @@ -49,7 +49,7 @@ it "have stored only non-ignored attributes" do article = described_class.create - article.update_attributes( + article.update( title: "My first title", content: "Some text here.", abstract: "ignore abstract" @@ -62,7 +62,7 @@ context "which updates an ignored column, ignored with falsy Proc and a selected column" do it "change the number of versions" do article = described_class.create - article.update_attributes( + article.update( title: "My first title", content: "Some text here.", abstract: "do not ignore abstract" @@ -73,7 +73,7 @@ it "stores only non-ignored attributes" do article = described_class.create - article.update_attributes( + article.update( title: "My first title", content: "Some text here.", abstract: "do not ignore abstract" @@ -89,7 +89,7 @@ context "which updates a selected column" do it "change the number of versions" do article = described_class.create - article.update_attributes(content: "Some text here.") + article.update(content: "Some text here.") expect(PaperTrail::Version.count).to(eq(2)) expect(article.versions.size).to(eq(2)) end @@ -98,7 +98,7 @@ context "which updates a non-ignored and non-selected column" do it "not change the number of versions" do article = described_class.create - article.update_attributes(abstract: "Other abstract") + article.update(abstract: "Other abstract") expect(PaperTrail::Version.count).to(eq(1)) end end @@ -106,7 +106,7 @@ context "which updates a skipped column" do it "not change the number of versions" do article = described_class.create - article.update_attributes(file_upload: "Your data goes here") + article.update(file_upload: "Your data goes here") expect(PaperTrail::Version.count).to(eq(1)) end end @@ -114,7 +114,7 @@ context "which updates a skipped column and a selected column" do it "change the number of versions" do article = described_class.create - article.update_attributes( + article.update( file_upload: "Your data goes here", content: "Some text here." ) @@ -123,7 +123,7 @@ it "show the new version in the model's `versions` association" do article = described_class.create - article.update_attributes( + article.update( file_upload: "Your data goes here", content: "Some text here." ) @@ -132,7 +132,7 @@ it "have stored only non-skipped attributes" do article = described_class.create - article.update_attributes( + article.update( file_upload: "Your data goes here", content: "Some text here." ) @@ -144,11 +144,11 @@ context "and when updated again" do it "have removed the skipped attributes when saving the previous version" do article = described_class.create - article.update_attributes( + article.update( file_upload: "Your data goes here", content: "Some text here." ) - article.update_attributes( + article.update( file_upload: "More data goes here", content: "More text here." ) @@ -160,11 +160,11 @@ it "have kept the non-skipped attributes in the previous version" do article = described_class.create - article.update_attributes( + article.update( file_upload: "Your data goes here", content: "Some text here." ) - article.update_attributes( + article.update( file_upload: "More data goes here", content: "More text here." ) diff --git a/spec/models/boolit_spec.rb b/spec/models/boolit_spec.rb index 27e4c0ffa..58a454757 100644 --- a/spec/models/boolit_spec.rb +++ b/spec/models/boolit_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Boolit, type: :model, versioning: true do let(:boolit) { Boolit.create! } - before { boolit.update_attributes!(name: FFaker::Name.name) } + before { boolit.update!(name: FFaker::Name.name) } it "has two versions" do expect(boolit.versions.size).to eq(2) @@ -17,7 +17,7 @@ end context "Instance falls out of default scope" do - before { boolit.update_attributes!(scoped: false) } + before { boolit.update!(scoped: false) } it "is NOT scoped" do expect(Boolit.first).to be_nil @@ -30,8 +30,8 @@ context "with `nil` attributes on the live instance" do before do PaperTrail.serializer = CustomJsonSerializer - boolit.update_attributes!(name: nil) - boolit.update_attributes!(name: FFaker::Name.name) + boolit.update!(name: nil) + boolit.update!(name: FFaker::Name.name) end after { PaperTrail.serializer = PaperTrail::Serializers::YAML } diff --git a/spec/models/callback_modifier_spec.rb b/spec/models/callback_modifier_spec.rb index e4344e181..9cc4cf372 100644 --- a/spec/models/callback_modifier_spec.rb +++ b/spec/models/callback_modifier_spec.rb @@ -47,7 +47,7 @@ it "creates a version" do modifier = UpdateModifier.create!(some_content: FFaker::Lorem.sentence) - modifier.update_attributes! some_content: "modified" + modifier.update! some_content: "modified" expect(modifier.versions.last.event).to eq "update" end end @@ -78,7 +78,7 @@ it "tracks update" do modifier = DefaultModifier.create!(some_content: FFaker::Lorem.sentence) - modifier.update_attributes! some_content: "modified" + modifier.update! some_content: "modified" expect(modifier.versions.last.event).to eq "update" end @@ -91,7 +91,7 @@ context "when only one callback-method" do it "does only track the corresponding event" do modifier = CreateModifier.create!(some_content: FFaker::Lorem.sentence) - modifier.update_attributes!(some_content: "modified") + modifier.update!(some_content: "modified") modifier.test_destroy expect(modifier.versions.collect(&:event)).to eq ["create"] end diff --git a/spec/models/car_spec.rb b/spec/models/car_spec.rb index f22dc0935..cf0e1d9da 100644 --- a/spec/models/car_spec.rb +++ b/spec/models/car_spec.rb @@ -8,7 +8,7 @@ describe "changeset", versioning: true do it "has the expected keys (see issue 738)" do car = Car.create!(name: "Alice") - car.update_attributes(name: "Bob") + car.update(name: "Bob") assert_includes car.versions.last.changeset.keys, "name" end end diff --git a/spec/models/custom_primary_key_record_spec.rb b/spec/models/custom_primary_key_record_spec.rb index 2af47bafe..519f0ffe5 100644 --- a/spec/models/custom_primary_key_record_spec.rb +++ b/spec/models/custom_primary_key_record_spec.rb @@ -8,7 +8,7 @@ describe "#versions" do it "returns instances of CustomPrimaryKeyRecordVersion", versioning: true do custom_primary_key_record = described_class.create! - custom_primary_key_record.update_attributes!(name: "bob") + custom_primary_key_record.update!(name: "bob") version = custom_primary_key_record.versions.last expect(version).to be_a(CustomPrimaryKeyRecordVersion) version_from_db = CustomPrimaryKeyRecordVersion.last diff --git a/spec/models/document_spec.rb b/spec/models/document_spec.rb index ae306123d..59e0a5303 100644 --- a/spec/models/document_spec.rb +++ b/spec/models/document_spec.rb @@ -6,7 +6,7 @@ describe "have_a_version_with matcher" do it "works with custom versions association" do document = Document.create!(name: "Foo") - document.update_attributes!(name: "Bar") + document.update!(name: "Bar") expect(document).to have_a_version_with(name: "Foo") end end @@ -14,7 +14,7 @@ describe "#paper_trail.next_version" do it "returns the expected document" do doc = Document.create - doc.update_attributes(name: "Doc 1") + doc.update(name: "Doc 1") reified = doc.paper_trail_versions.last.reify expect(doc.name).to(eq(reified.paper_trail.next_version.name)) end @@ -23,8 +23,8 @@ describe "#paper_trail.previous_version" do it "returns the expected document" do doc = Document.create - doc.update_attributes(name: "Doc 1") - doc.update_attributes(name: "Doc 2") + doc.update(name: "Doc 1") + doc.update(name: "Doc 2") expect(doc.paper_trail_versions.length).to(eq(3)) expect(doc.paper_trail.previous_version.name).to(eq("Doc 1")) end @@ -33,7 +33,7 @@ describe "#paper_trail_versions" do it "returns the expected version records" do doc = Document.create - doc.update_attributes(name: "Doc 1") + doc.update(name: "Doc 1") expect(doc.paper_trail_versions.length).to(eq(2)) expect(doc.paper_trail_versions.map(&:event)).to( match_array(%w[create update]) @@ -44,7 +44,7 @@ describe "#versions" do it "does not respond to versions method" do doc = Document.create - doc.update_attributes(name: "Doc 1") + doc.update(name: "Doc 1") expect(doc).not_to respond_to(:versions) end end diff --git a/spec/models/family/celebrity_family_spec.rb b/spec/models/family/celebrity_family_spec.rb index 6d93f2c30..b55e70b16 100644 --- a/spec/models/family/celebrity_family_spec.rb +++ b/spec/models/family/celebrity_family_spec.rb @@ -37,7 +37,7 @@ module Family child1 = parent.children.build(name: "Jaimy Jermaine Jackson") parent.children.build(name: "Autumn Joy Jackson") parent.save! - parent.update_attributes!( + parent.update!( name: "Hazel Gordy", children_attributes: { id: child1.id, name: "Jay Jackson" } ) @@ -98,7 +98,7 @@ module Family "bring up 5 boys who have a true zest for comedy." parent.build_mentee(name: "Abraham Schönberg") parent.save! - parent.update_attributes( + parent.update( name: "Samuel Marx", mentee_attributes: { id: parent.mentee.id, name: "Al Shean" } ) diff --git a/spec/models/family/family_spec.rb b/spec/models/family/family_spec.rb index 71329133b..5f77dfc46 100644 --- a/spec/models/family/family_spec.rb +++ b/spec/models/family/family_spec.rb @@ -10,7 +10,7 @@ module Family parent = described_class.new(name: "parent1") parent.children.build(name: "child1") parent.save! - parent.update_attributes!( + parent.update!( name: "parent2", children_attributes: { id: parent.children.first.id, name: "child2" } ) @@ -64,7 +64,7 @@ module Family parent = described_class.new(name: "parent1") parent.build_mentee(name: "partner1") parent.save! - parent.update_attributes( + parent.update( name: "parent2", mentee_attributes: { id: parent.mentee.id, name: "partner2" } ) diff --git a/spec/models/fruit_spec.rb b/spec/models/fruit_spec.rb index c37bf6f83..acb70fca7 100644 --- a/spec/models/fruit_spec.rb +++ b/spec/models/fruit_spec.rb @@ -10,7 +10,7 @@ # so that's why were testing the have_a_version_with_changes matcher # here. banana = Fruit.create!(color: "Red", name: "Banana") - banana.update_attributes!(color: "Yellow") + banana.update!(color: "Yellow") expect(banana).to have_a_version_with_changes(color: "Yellow") expect(banana).not_to have_a_version_with_changes(color: "Pink") expect(banana).not_to have_a_version_with_changes(color: "Yellow", name: "Kiwi") diff --git a/spec/models/json_version_spec.rb b/spec/models/json_version_spec.rb index 42453dde0..d1d7253a7 100644 --- a/spec/models/json_version_spec.rb +++ b/spec/models/json_version_spec.rb @@ -34,9 +34,9 @@ it "locates versions according to their `object` contents" do fruit = Fruit.create!(name: "apple") expect(fruit.versions.length).to eq(1) - fruit.update_attributes!(name: "banana", color: "aqua") + fruit.update!(name: "banana", color: "aqua") expect(fruit.versions.length).to eq(2) - fruit.update_attributes!(name: "coconut", color: "black") + fruit.update!(name: "coconut", color: "black") expect(fruit.versions.length).to eq(3) where_apple = described_class.where_object(name: "apple") expect(where_apple.to_sql).to eq( @@ -75,8 +75,8 @@ context "valid arguments", versioning: true do it "finds versions according to their `object_changes` contents" do fruit = Fruit.create!(name: "apple") - fruit.update_attributes!(name: "banana", color: "red") - fruit.update_attributes!(name: "coconut", color: "green") + fruit.update!(name: "banana", color: "red") + fruit.update!(name: "coconut", color: "green") where_apple = fruit.versions.where_object_changes(name: "apple") expect(where_apple.to_sql.squish).to eq( <<-SQL.squish @@ -99,8 +99,8 @@ it "finds versions with multiple attributes changed" do fruit = Fruit.create!(name: "apple") - fruit.update_attributes!(name: "banana", color: "red") - fruit.update_attributes!(name: "coconut", color: "green") + fruit.update!(name: "banana", color: "red") + fruit.update!(name: "coconut", color: "green") where_red_apple = fruit.versions.where_object_changes(color: "red", name: "apple") expect(where_red_apple.to_sql.squish).to eq( <<-SQL.squish diff --git a/spec/models/legacy_widget_spec.rb b/spec/models/legacy_widget_spec.rb index 51fe2e20b..8addc1425 100644 --- a/spec/models/legacy_widget_spec.rb +++ b/spec/models/legacy_widget_spec.rb @@ -6,7 +6,7 @@ describe "#custom_version" do it "knows which version it came from" do widget = described_class.create(name: "foo", version: 2) - %w[bar baz].each { |name| widget.update_attributes(name: name) } + %w[bar baz].each { |name| widget.update(name: name) } version = widget.versions.last reified = version.reify expect(reified.custom_version).to(eq(version)) @@ -16,16 +16,16 @@ describe "#previous_version" do it "return its previous self" do widget = described_class.create(name: "foo", version: 2) - %w[bar baz].each { |name| widget.update_attributes(name: name) } + %w[bar baz].each { |name| widget.update(name: name) } version = widget.versions.last reified = version.reify expect(reified.paper_trail.previous_version).to(eq(reified.versions[-2].reify)) end end - describe "#update_attributes" do + describe "#update" do it "does not create a PT version record because the updated column is ignored" do - described_class.create.update_attributes(version: 1) + described_class.create.update(version: 1) expect(PaperTrail::Version.count).to(eq(1)) end end @@ -35,7 +35,7 @@ widget = described_class.create(name: "foo", version: 2) expect(widget.versions.size).to(eq(1)) expect(widget.version).to(eq(2)) - widget.update_attributes(version: 3) + widget.update(version: 3) expect(widget.version).to(eq(3)) end end diff --git a/spec/models/on/create_spec.rb b/spec/models/on/create_spec.rb index 273625a74..1fc49ed32 100644 --- a/spec/models/on/create_spec.rb +++ b/spec/models/on/create_spec.rb @@ -8,7 +8,7 @@ module On describe "#versions" do it "only have a version for the create event" do record = described_class.create(name: "Alice") - record.update_attributes(name: "blah") + record.update(name: "blah") record.destroy expect(record.versions.length).to(eq(1)) expect(record.versions.last.event).to(eq("create")) @@ -19,7 +19,7 @@ module On it "rembembers the custom event name" do record = described_class.new record.paper_trail_event = "banana" - record.update_attributes(name: "blah") + record.update(name: "blah") record.destroy expect(record.versions.length).to(eq(1)) expect(record.versions.last.event).to(eq("banana")) diff --git a/spec/models/on/destroy_spec.rb b/spec/models/on/destroy_spec.rb index db6ded48d..627e79947 100644 --- a/spec/models/on/destroy_spec.rb +++ b/spec/models/on/destroy_spec.rb @@ -8,7 +8,7 @@ module On describe "#versions" do it "only creates one version record, for the destroy event" do record = described_class.create(name: "Alice") - record.update_attributes(name: "blah") + record.update(name: "blah") record.destroy expect(record.versions.length).to(eq(1)) expect(record.versions.last.event).to(eq("destroy")) @@ -19,7 +19,7 @@ module On it "rembembers the custom event name" do record = described_class.create(name: "Alice") record.paper_trail_event = "banana" - record.update_attributes(name: "blah") + record.update(name: "blah") record.destroy expect(record.versions.length).to(eq(1)) expect(record.versions.last.event).to(eq("banana")) diff --git a/spec/models/on/empty_array_spec.rb b/spec/models/on/empty_array_spec.rb index b9236336f..e13ac4deb 100644 --- a/spec/models/on/empty_array_spec.rb +++ b/spec/models/on/empty_array_spec.rb @@ -21,10 +21,10 @@ module On end end - describe "#update_attributes" do + describe "#update" do it "does not create any version records" do record = described_class.create(name: "Alice") - record.update_attributes(name: "blah") + record.update(name: "blah") expect(record.versions.length).to(eq(0)) end end diff --git a/spec/models/on/update_spec.rb b/spec/models/on/update_spec.rb index 2a2ac9653..2bde6290c 100644 --- a/spec/models/on/update_spec.rb +++ b/spec/models/on/update_spec.rb @@ -8,7 +8,7 @@ module On describe "#versions" do it "only creates one version record, for the update event" do record = described_class.create(name: "Alice") - record.update_attributes(name: "blah") + record.update(name: "blah") record.destroy expect(record.versions.length).to(eq(1)) expect(record.versions.last.event).to(eq("update")) @@ -19,7 +19,7 @@ module On it "rembembers the custom event name" do record = described_class.create(name: "Alice") record.paper_trail_event = "banana" - record.update_attributes(name: "blah") + record.update(name: "blah") record.destroy expect(record.versions.length).to(eq(1)) expect(record.versions.last.event).to(eq("banana")) diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 6efda789b..d5fe3bbac 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -158,11 +158,11 @@ person.car = car person.bicycle = bicycle - person.update_attributes(name: "Steve") + person.update(name: "Steve") - car.update_attributes(name: "BMW 330") - bicycle.update_attributes(name: "BMX 2.0") - person.update_attributes(name: "Peter") + car.update(name: "BMW 330") + bicycle.update(name: "BMX 2.0") + person.update(name: "Peter") expect(person.reload.versions.length).to(eq(3)) diff --git a/spec/models/pet_spec.rb b/spec/models/pet_spec.rb index 42b6d9cb3..e48fcaa34 100644 --- a/spec/models/pet_spec.rb +++ b/spec/models/pet_spec.rb @@ -15,11 +15,11 @@ person.pets << Pet.create(animal: dog) person.pets << Pet.create(animal: cat) - person.update_attributes(name: "Steve") + person.update(name: "Steve") - dog.update_attributes(name: "Beethoven") - cat.update_attributes(name: "Sylvester") - person.update_attributes(name: "Peter") + dog.update(name: "Beethoven") + cat.update(name: "Sylvester") + person.update(name: "Peter") expect(person.reload.versions.length).to(eq(3)) @@ -50,9 +50,9 @@ before do # This line runs the `let` for :cat, creating two entries - cat.update_attributes(name: "Sylvester") # Index 1 - second - cat.update_attributes(name: "Cheshire") # Index 2 - third - cat.destroy # Index 3 - fourth + cat.update(name: "Sylvester") # Index 1 - second + cat.update(name: "Cheshire") # Index 2 - third + cat.destroy # Index 3 - fourth # Prior to PR#1143 a subclassed version's item_subtype would be nil. In order to simulate # an entry having been made in the old way, set one of the item_subtype entries to be nil diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index a1fc132b8..08bb5e2ed 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -7,7 +7,7 @@ it "inserts records into the correct table, post_versions" do post = Post.create expect(PostVersion.count).to(eq(1)) - post.update_attributes(content: "Some new content") + post.update(content: "Some new content") expect(PostVersion.count).to(eq(2)) expect(PaperTrail::Version.count).to(eq(0)) end @@ -28,7 +28,7 @@ describe "#changeset" do it "returns nil because the object_changes column doesn't exist" do post = Post.create - post.update_attributes(content: "Some new content") + post.update(content: "Some new content") expect(post.versions.last.changeset).to(be_nil) end end diff --git a/spec/models/skipper_spec.rb b/spec/models/skipper_spec.rb index 382a98ee8..33242fa2b 100644 --- a/spec/models/skipper_spec.rb +++ b/spec/models/skipper_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Skipper, type: :model, versioning: true do it { is_expected.to be_versioned } - describe "#update_attributes!", versioning: true do + describe "#update!", versioning: true do context "updating a skipped attribute" do let(:t1) { Time.zone.local(2015, 7, 15, 20, 34, 0) } let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) } @@ -13,7 +13,7 @@ it "does not create a version" do skipper = Skipper.create!(another_timestamp: t1) expect { - skipper.update_attributes!(another_timestamp: t2) + skipper.update!(another_timestamp: t2) }.not_to(change { skipper.versions.length }) end end @@ -26,7 +26,7 @@ context "without preserve (default)" do it "has no timestamp" do skipper = Skipper.create!(another_timestamp: t1) - skipper.update_attributes!(another_timestamp: t2, name: "Foobar") + skipper.update!(another_timestamp: t2, name: "Foobar") skipper = skipper.versions.last.reify expect(skipper.another_timestamp).to be(nil) end @@ -35,7 +35,7 @@ context "with preserve" do it "preserves its timestamp" do skipper = Skipper.create!(another_timestamp: t1) - skipper.update_attributes!(another_timestamp: t2, name: "Foobar") + skipper.update!(another_timestamp: t2, name: "Foobar") skipper = skipper.versions.last.reify(unversioned_attributes: :preserve) expect(skipper.another_timestamp).to eq(t2) end diff --git a/spec/models/translation_spec.rb b/spec/models/translation_spec.rb index fa3f9e228..d00947b00 100644 --- a/spec/models/translation_spec.rb +++ b/spec/models/translation_spec.rb @@ -12,7 +12,7 @@ context "after update" do it "not change the number of versions" do translation = described_class.create!(headline: "Headline") - translation.update_attributes(content: "Content") + translation.update(content: "Content") expect(PaperTrail::Version.count).to(eq(0)) end end @@ -41,7 +41,7 @@ translation.language_code = "US" translation.type = "DRAFT" translation.save! - translation.update_attributes(content: "Content") + translation.update(content: "Content") expect(PaperTrail::Version.count).to(eq(0)) end end @@ -54,7 +54,7 @@ it "update does not change the number of versions" do translation = described_class.create!(headline: "Headline", language_code: "US") - translation.update_attributes(content: "Content") + translation.update(content: "Content") expect(PaperTrail::Version.count).to(eq(2)) expect(translation.versions.size).to(eq(2)) end diff --git a/spec/models/version_spec.rb b/spec/models/version_spec.rb index d5b1dd0b9..4b90ba768 100644 --- a/spec/models/version_spec.rb +++ b/spec/models/version_spec.rb @@ -66,8 +66,8 @@ module PaperTrail it "returns name of whodunnit" do name = FFaker::Name.name widget = Widget.create!(name: FFaker::Name.name) - widget.versions.first.update_attributes!(whodunnit: name) - widget.update_attributes!(name: FFaker::Name.first_name) + widget.versions.first.update!(whodunnit: name) + widget.update!(name: FFaker::Name.first_name) expect(widget.versions.last.paper_trail_originator).to eq(name) end end @@ -84,8 +84,8 @@ module PaperTrail it "returns a PaperTrail::Version" do name = FFaker::Name.name widget = Widget.create!(name: FFaker::Name.name) - widget.versions.first.update_attributes!(whodunnit: name) - widget.update_attributes!(name: FFaker::Name.first_name) + widget.versions.first.update!(whodunnit: name) + widget.update!(name: FFaker::Name.first_name) expect(widget.versions.last.previous).to be_instance_of(PaperTrail::Version) end end @@ -167,9 +167,9 @@ module PaperTrail describe "#where_object", versioning: true do it "requires its argument to be a Hash" do - widget.update_attributes!(name: name, an_integer: int) - widget.update_attributes!(name: "foobar", an_integer: 100) - widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15) + widget.update!(name: name, an_integer: int) + widget.update!(name: "foobar", an_integer: 100) + widget.update!(name: FFaker::Name.last_name, an_integer: 15) expect { PaperTrail::Version.where_object(:foo) }.to raise_error(ArgumentError) @@ -181,9 +181,9 @@ module PaperTrail context "YAML serializer" do it "locates versions according to their `object` contents" do expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML - widget.update_attributes!(name: name, an_integer: int) - widget.update_attributes!(name: "foobar", an_integer: 100) - widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15) + widget.update!(name: name, an_integer: int) + widget.update!(name: "foobar", an_integer: 100) + widget.update!(name: FFaker::Name.last_name, an_integer: 15) expect( PaperTrail::Version.where_object(an_integer: int) ).to eq([widget.versions[1]]) @@ -200,9 +200,9 @@ module PaperTrail it "locates versions according to their `object` contents" do PaperTrail.serializer = PaperTrail::Serializers::JSON expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON - widget.update_attributes!(name: name, an_integer: int) - widget.update_attributes!(name: "foobar", an_integer: 100) - widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15) + widget.update!(name: name, an_integer: int) + widget.update!(name: "foobar", an_integer: 100) + widget.update!(name: FFaker::Name.last_name, an_integer: 15) expect( PaperTrail::Version.where_object(an_integer: int) ).to eq([widget.versions[1]]) @@ -264,9 +264,9 @@ module PaperTrail # supports text columns. if column_datatype_override it "locates versions according to their object_changes contents" do - widget.update_attributes!(name: name, an_integer: 0) - widget.update_attributes!(name: "foobar", an_integer: 100) - widget.update_attributes!(name: FFaker::Name.last_name, an_integer: int) + widget.update!(name: name, an_integer: 0) + widget.update!(name: "foobar", an_integer: 100) + widget.update!(name: FFaker::Name.last_name, an_integer: int) expect( widget.versions.where_object_changes(name: name) ).to eq(widget.versions[0..1]) diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb index df8fe5805..d894c45b8 100644 --- a/spec/models/widget_spec.rb +++ b/spec/models/widget_spec.rb @@ -11,9 +11,9 @@ describe "`have_a_version_with` matcher", versioning: true do before do - widget.update_attributes!(name: "Leonard", an_integer: 1) - widget.update_attributes!(name: "Tom") - widget.update_attributes!(name: "Bob") + widget.update!(name: "Leonard", an_integer: 1) + widget.update!(name: "Tom") + widget.update!(name: "Bob") end it "is possible to do assertions on version attributes" do @@ -40,7 +40,7 @@ describe "Callbacks", versioning: true do describe "before_save" do it "resets value for timestamp attrs for update so that value gets updated properly" do - widget.update_attributes!(name: "Foobar") + widget.update!(name: "Foobar") w = widget.versions.last.reify expect { w.save! }.to change(w, :updated_at) end @@ -56,7 +56,7 @@ describe "after_update" do before do - widget.update_attributes!(name: "Foobar", updated_at: Time.now + 1.week) + widget.update!(name: "Foobar", updated_at: Time.now + 1.week) end it "clears the `versions_association_name` virtual attribute" do @@ -90,8 +90,8 @@ before do begin widget.transaction do - widget.update_attributes!(name: rolled_back_name) - widget.update_attributes!(name: Widget::EXCLUDED_NAME) + widget.update!(name: rolled_back_name) + widget.update!(name: Widget::EXCLUDED_NAME) end rescue ActiveRecord::RecordInvalid widget.reload @@ -125,8 +125,8 @@ if defined?(ActiveRecord::IdentityMap) && ActiveRecord::IdentityMap.respond_to?(:without) describe "IdentityMap", versioning: true do it "does not clobber the IdentityMap when reifying" do - widget.update_attributes name: "Henry", created_at: Time.now - 1.day - widget.update_attributes name: "Harry" + widget.update name: "Henry", created_at: Time.now - 1.day + widget.update name: "Harry" allow(ActiveRecord::IdentityMap).to receive(:without) widget.versions.last.reify expect(ActiveRecord::IdentityMap).to have_receive(:without).once @@ -182,24 +182,24 @@ expect(widget.paper_trail).to be_live expect(widget.paper_trail.originator).to eq(orig_name) ::PaperTrail.request(whodunnit: new_name) { - widget.update_attributes(name: "Elizabeth") + widget.update(name: "Elizabeth") } expect(widget.paper_trail.originator).to eq(new_name) end it "returns the appropriate originator" do - widget.update_attributes(name: "Andy") + widget.update(name: "Andy") PaperTrail.request.whodunnit = new_name - widget.update_attributes(name: "Elizabeth") + widget.update(name: "Elizabeth") reified_widget = widget.versions[1].reify expect(reified_widget.paper_trail.originator).to eq(orig_name) expect(reified_widget).not_to be_new_record end it "can create a new instance with options[:dup]" do - widget.update_attributes(name: "Andy") + widget.update(name: "Andy") PaperTrail.request.whodunnit = new_name - widget.update_attributes(name: "Elizabeth") + widget.update(name: "Elizabeth") reified_widget = widget.versions[1].reify(dup: true) expect(reified_widget.paper_trail.originator).to eq(orig_name) expect(reified_widget).to be_new_record @@ -250,7 +250,7 @@ it "creates a version record" do widget = Widget.create assert_equal 1, widget.versions.length - widget.update_attributes(name: "Bugle") + widget.update(name: "Bugle") assert_equal 2, widget.versions.length end end diff --git a/spec/paper_trail/association_reify_error_behaviour/error.rb b/spec/paper_trail/association_reify_error_behaviour/error.rb index fa9184933..395c6a669 100644 --- a/spec/paper_trail/association_reify_error_behaviour/error.rb +++ b/spec/paper_trail/association_reify_error_behaviour/error.rb @@ -18,11 +18,11 @@ person.car = car person.bicycle = bicycle - person.update_attributes(name: "Steve") + person.update(name: "Steve") - car.update_attributes(name: "BMW 330") - bicycle.update_attributes(name: "BMX 2.0") - person.update_attributes(name: "Peter") + car.update(name: "BMW 330") + bicycle.update(name: "BMX 2.0") + person.update(name: "Peter") expect(person.reload.versions.length).to(eq(3)) diff --git a/spec/paper_trail/association_reify_error_behaviour/ignore.rb b/spec/paper_trail/association_reify_error_behaviour/ignore.rb index ac0dd19fc..2199dc86d 100644 --- a/spec/paper_trail/association_reify_error_behaviour/ignore.rb +++ b/spec/paper_trail/association_reify_error_behaviour/ignore.rb @@ -18,11 +18,11 @@ person.thing = thing person.thing_2 = thing2 - person.update_attributes(name: "Steve") + person.update(name: "Steve") - thing.update_attributes(name: "BMW 330") - thing.update_attributes(name: "BMX 2.0") - person.update_attributes(name: "Peter") + thing.update(name: "BMW 330") + thing.update(name: "BMX 2.0") + person.update(name: "Peter") expect(person.reload.versions.length).to(eq(3)) diff --git a/spec/paper_trail/association_reify_error_behaviour/warn.rb b/spec/paper_trail/association_reify_error_behaviour/warn.rb index 2f354b8ed..80ea0f081 100644 --- a/spec/paper_trail/association_reify_error_behaviour/warn.rb +++ b/spec/paper_trail/association_reify_error_behaviour/warn.rb @@ -18,11 +18,11 @@ person.thing = thing person.thing_2 = thing2 - person.update_attributes(name: "Steve") + person.update(name: "Steve") - thing.update_attributes(name: "BMW 330") - thing.update_attributes(name: "BMX 2.0") - person.update_attributes(name: "Peter") + thing.update(name: "BMW 330") + thing.update(name: "BMX 2.0") + person.update(name: "Peter") expect(person.reload.versions.length).to(eq(3)) diff --git a/spec/paper_trail/associations/belongs_to_spec.rb b/spec/paper_trail/associations/belongs_to_spec.rb index 809afe567..67d1dbe34 100644 --- a/spec/paper_trail/associations/belongs_to_spec.rb +++ b/spec/paper_trail/associations/belongs_to_spec.rb @@ -9,7 +9,7 @@ context "where the association is created between model versions" do before do @wotsit = Wotsit.create(name: "wotsit_0") - @wotsit.update_attributes(widget_id: @widget.id, name: "wotsit_1") + @wotsit.update(widget_id: @widget.id, name: "wotsit_1") end context "when reified" do @@ -26,10 +26,10 @@ context "and then the associated is updated between model versions" do before do - @widget.update_attributes(name: "widget_1") - @widget.update_attributes(name: "widget_2") - @wotsit.update_attributes(name: "wotsit_2") - @widget.update_attributes(name: "widget_3") + @widget.update(name: "widget_1") + @widget.update(name: "widget_2") + @wotsit.update(name: "wotsit_2") + @widget.update(name: "widget_3") end context "when reified" do @@ -55,7 +55,7 @@ context "and then the associated is destroyed" do before do - @wotsit.update_attributes(name: "wotsit_2") + @wotsit.update(name: "wotsit_2") @widget.destroy end @@ -86,7 +86,7 @@ context "and then the model is updated" do before do - @wotsit.update_attributes(name: "wotsit_3") + @wotsit.update(name: "wotsit_3") end context "when reified" do @@ -104,7 +104,7 @@ before do @wotsit = @widget.create_wotsit(name: "wotsit_0") @new_widget = Widget.create(name: "new_widget") - @wotsit.update_attributes(widget_id: @new_widget.id, name: "wotsit_1") + @wotsit.update(widget_id: @new_widget.id, name: "wotsit_1") end context "when reified" do diff --git a/spec/paper_trail/associations/habtm_spec.rb b/spec/paper_trail/associations/habtm_spec.rb index 0cfc17595..ea3cb689e 100644 --- a/spec/paper_trail/associations/habtm_spec.rb +++ b/spec/paper_trail/associations/habtm_spec.rb @@ -10,7 +10,7 @@ context "where the association is created between model versions" do before do - @foo.update_attributes(name: "foo1", bar_habtms: [BarHabtm.create(name: "bar")]) + @foo.update(name: "foo1", bar_habtms: [BarHabtm.create(name: "bar")]) end context "when reified" do @@ -30,8 +30,8 @@ context "where the association is changed between model versions" do before do - @foo.update_attributes(name: "foo2", bar_habtms: [BarHabtm.create(name: "bar2")]) - @foo.update_attributes(name: "foo3", bar_habtms: [BarHabtm.create(name: "bar3")]) + @foo.update(name: "foo2", bar_habtms: [BarHabtm.create(name: "bar2")]) + @foo.update(name: "foo3", bar_habtms: [BarHabtm.create(name: "bar3")]) end context "when reified" do @@ -59,8 +59,8 @@ context "where the association is destroyed between model versions" do before do - @foo.update_attributes(name: "foo2", bar_habtms: [BarHabtm.create(name: "bar2")]) - @foo.update_attributes(name: "foo3", bar_habtms: []) + @foo.update(name: "foo2", bar_habtms: [BarHabtm.create(name: "bar2")]) + @foo.update(name: "foo3", bar_habtms: []) end context "when reified" do @@ -81,9 +81,9 @@ context "where the unassociated model changes" do before do @bar = BarHabtm.create(name: "bar2") - @foo.update_attributes(name: "foo2", bar_habtms: [@bar]) - @foo.update_attributes(name: "foo3", bar_habtms: [BarHabtm.create(name: "bar4")]) - @bar.update_attributes(name: "bar3") + @foo.update(name: "foo2", bar_habtms: [@bar]) + @foo.update(name: "foo3", bar_habtms: [BarHabtm.create(name: "bar4")]) + @bar.update(name: "bar3") end context "when reified" do @@ -105,7 +105,7 @@ context "updated via nested attributes" do before do @foo = FooHabtm.create(name: "foo", bar_habtms_attributes: [{ name: "bar" }]) - @foo.update_attributes( + @foo.update( name: "foo2", bar_habtms_attributes: [{ id: @foo.bar_habtms.first.id, name: "bar2" }] ) diff --git a/spec/paper_trail/associations/has_many_spec.rb b/spec/paper_trail/associations/has_many_spec.rb index 74cc687b6..dd6185c55 100644 --- a/spec/paper_trail/associations/has_many_spec.rb +++ b/spec/paper_trail/associations/has_many_spec.rb @@ -6,7 +6,7 @@ describe "customer, reified from version before order created" do it "has no orders" do customer = Customer.create(name: "customer_0") - customer.update_attributes!(name: "customer_1") + customer.update!(name: "customer_1") customer.orders.create!(order_date: Date.today) customer0 = customer.versions.last.reify(has_many: true) expect(customer0.orders).to(eq([])) @@ -17,7 +17,7 @@ describe "customer, reified with mark_for_destruction, from version before order" do it "has orders, but they are marked for destruction" do customer = Customer.create(name: "customer_0") - customer.update_attributes!(name: "customer_1") + customer.update!(name: "customer_1") customer.orders.create!(order_date: Date.today) customer0 = customer.versions.last.reify(has_many: true, mark_for_destruction: true) expect(customer0.orders.map(&:marked_for_destruction?)).to(eq([true])) @@ -28,7 +28,7 @@ it "has the expected order" do customer = Customer.create(name: "customer_0") customer.orders.create!(order_date: "order_date_0") - customer.update_attributes(name: "customer_1") + customer.update(name: "customer_1") customer0 = customer.versions.last.reify(has_many: true) expect(customer0.orders.map(&:order_date)).to(eq(["order_date_0"])) end @@ -38,7 +38,7 @@ it "has the expected line item" do customer = Customer.create(name: "customer_0") order = customer.orders.create!(order_date: "order_date_0") - customer.update_attributes(name: "customer_1") + customer.update(name: "customer_1") order.line_items.create!(product: "product_0") customer0 = customer.versions.last.reify(has_many: true) expect(customer0.orders.first.line_items.map(&:product)).to(eq(["product_0"])) @@ -49,11 +49,11 @@ it "has the updated order_date" do customer = Customer.create(name: "customer_0") order = customer.orders.create!(order_date: "order_date_0") - customer.update_attributes(name: "customer_1") - order.update_attributes(order_date: "order_date_1") - order.update_attributes(order_date: "order_date_2") - customer.update_attributes(name: "customer_2") - order.update_attributes(order_date: "order_date_3") + customer.update(name: "customer_1") + order.update(order_date: "order_date_1") + order.update(order_date: "order_date_2") + customer.update(name: "customer_2") + order.update(order_date: "order_date_3") customer1 = customer.versions.last.reify(has_many: true) expect(customer1.orders.map(&:order_date)).to(eq(["order_date_2"])) expect(customer.orders.reload.map(&:order_date)).to(eq(["order_date_3"])) @@ -65,11 +65,11 @@ # TODO: This can be tested with fewer db records customer = Customer.create(name: "customer_0") order = customer.orders.create!(order_date: "order_date_0") - customer.update_attributes(name: "customer_1") - order.update_attributes(order_date: "order_date_1") - order.update_attributes(order_date: "order_date_2") - customer.update_attributes(name: "customer_2") - order.update_attributes(order_date: "order_date_3") + customer.update(name: "customer_1") + order.update(order_date: "order_date_1") + order.update(order_date: "order_date_2") + customer.update(name: "customer_2") + order.update(order_date: "order_date_3") customer1 = customer.versions.last.reify(has_many: false) expect(customer1.orders.map(&:order_date)).to(eq(["order_date_3"])) end @@ -80,11 +80,11 @@ # TODO: This can be tested with fewer db records customer = Customer.create(name: "customer_0") order = customer.orders.create!(order_date: "order_date_0") - customer.update_attributes(name: "customer_1") - order.update_attributes(order_date: "order_date_1") - order.update_attributes(order_date: "order_date_2") - customer.update_attributes(name: "customer_2") - order.update_attributes(order_date: "order_date_3") + customer.update(name: "customer_1") + order.update(order_date: "order_date_1") + order.update(order_date: "order_date_2") + customer.update(name: "customer_2") + order.update(order_date: "order_date_3") order.destroy customer1 = customer.versions.last.reify(has_many: true) expect(customer1.orders.map(&:order_date)).to(eq(["order_date_2"])) @@ -96,7 +96,7 @@ it "has the order" do customer = Customer.create(name: "customer_0") order = customer.orders.create!(order_date: "order_date_0") - customer.update_attributes(name: "customer_1") + customer.update(name: "customer_1") order.destroy customer1 = customer.versions.last.reify(has_many: true) expect(customer1.orders.map(&:order_date)).to(eq([order.order_date])) @@ -108,9 +108,9 @@ it "does not have the order" do customer = Customer.create(name: "customer_0") order = customer.orders.create!(order_date: "order_date_0") - customer.update_attributes(name: "customer_1") + customer.update(name: "customer_1") order.destroy - customer.update_attributes(name: "customer_2") + customer.update(name: "customer_2") customer1 = customer.versions.last.reify(has_many: true) expect(customer1.orders).to(eq([])) end @@ -120,7 +120,7 @@ it "has the old order_date" do customer = Customer.create(name: "customer_0") customer.orders.create!(order_date: "order_date_0") - customer.update_attributes(name: "customer_1") + customer.update(name: "customer_1") customer.orders.create!(order_date: "order_date_1") customer0 = customer.versions.last.reify(has_many: true) expect(customer0.orders.map(&:order_date)).to(eq(["order_date_0"])) @@ -134,7 +134,7 @@ it "has both orders, and the second is marked for destruction" do customer = Customer.create(name: "customer_0") customer.orders.create!(order_date: "order_date_0") - customer.update_attributes(name: "customer_1") + customer.update(name: "customer_1") customer.orders.create!(order_date: "order_date_1") customer0 = customer.versions.last.reify(has_many: true, mark_for_destruction: true) order = customer0.orders.detect { |o| o.order_date == "order_date_1" } diff --git a/spec/paper_trail/associations/has_many_through_spec.rb b/spec/paper_trail/associations/has_many_through_spec.rb index 8a6e9cced..057bccc00 100644 --- a/spec/paper_trail/associations/has_many_through_spec.rb +++ b/spec/paper_trail/associations/has_many_through_spec.rb @@ -23,7 +23,7 @@ context "updated before the associated was created" do before do - @book.update_attributes!(title: "book_1") + @book.update!(title: "book_1") @book.authors.create!(name: "author_0") end @@ -57,7 +57,7 @@ context "updated before it is associated with an existing one" do before do person_existing = Person.create(name: "person_existing") - @book.update_attributes!(title: "book_1") + @book.update!(title: "book_1") (@book.authors << person_existing) end @@ -88,7 +88,7 @@ before do @author = @book.authors.create!(name: "author_0") @person_existing = Person.create(name: "person_existing") - @book.update_attributes!(title: "book_1") + @book.update!(title: "book_1") end context "when reified" do @@ -101,10 +101,10 @@ context "and then the associated is updated between model versions" do before do - @author.update_attributes(name: "author_1") - @author.update_attributes(name: "author_2") - @book.update_attributes(title: "book_2") - @author.update_attributes(name: "author_3") + @author.update(name: "author_1") + @author.update(name: "author_2") + @book.update(title: "book_2") + @author.update(name: "author_3") end context "when reified" do @@ -147,7 +147,7 @@ context "and then the associated is destroyed between model versions" do before do @author.destroy - @book.update_attributes(title: "book_2") + @book.update(title: "book_2") end context "when reified" do @@ -162,7 +162,7 @@ context "and then the associated is dissociated between model versions" do before do @book.authors = [] - @book.update_attributes(title: "book_2") + @book.update(title: "book_2") end context "when reified" do @@ -241,7 +241,7 @@ context "updated before the associated without paper_trail was created" do before do - @book.update_attributes!(title: "book_1") + @book.update!(title: "book_1") @book.editors.create!(name: "editor_0") end @@ -259,7 +259,7 @@ before { @chapter = Chapter.create(name: CHAPTER_NAMES[0]) } context "before any associations are created" do - before { @chapter.update_attributes(name: CHAPTER_NAMES[1]) } + before { @chapter.update(name: CHAPTER_NAMES[1]) } it "not reify any associations" do chapter_v1 = @chapter.versions[1].reify(has_many: true) @@ -271,11 +271,11 @@ context "after the first has_many through relationship is created" do before do - @chapter.update_attributes(name: CHAPTER_NAMES[1]) + @chapter.update(name: CHAPTER_NAMES[1]) @chapter.sections.create(name: "section 1") - @chapter.sections.first.update_attributes(name: "section 2") - @chapter.update_attributes(name: CHAPTER_NAMES[2]) - @chapter.sections.first.update_attributes(name: "section 3") + @chapter.sections.first.update(name: "section 2") + @chapter.update(name: CHAPTER_NAMES[2]) + @chapter.sections.first.update(name: "section 3") end context "version 1" do @@ -296,7 +296,7 @@ context "version 2, before the section was destroyed" do before do - @chapter.update_attributes(name: CHAPTER_NAMES[2]) + @chapter.update(name: CHAPTER_NAMES[2]) @chapter.sections.destroy_all end @@ -309,7 +309,7 @@ context "version 3, after the section was destroyed" do before do @chapter.sections.destroy_all - @chapter.update_attributes(name: CHAPTER_NAMES[3]) + @chapter.update(name: CHAPTER_NAMES[3]) end it "have no sections" do @@ -328,9 +328,9 @@ it "have one paragraph" do initial_section_name = @section.name initial_paragraph_name = @paragraph.name - @chapter.update_attributes(name: CHAPTER_NAMES[4]) + @chapter.update(name: CHAPTER_NAMES[4]) expect(@chapter.versions.size).to(eq(4)) - @paragraph.update_attributes(name: "para3") + @paragraph.update(name: "para3") chapter_v3 = @chapter.versions[3].reify(has_many: true) expect(chapter_v3.sections.map(&:name)).to(eq([initial_section_name])) paragraphs = chapter_v3.sections.first.paragraphs @@ -341,7 +341,7 @@ context "the version before a section is destroyed" do it "have the section and paragraph" do - @chapter.update_attributes(name: CHAPTER_NAMES[3]) + @chapter.update(name: CHAPTER_NAMES[3]) expect(@chapter.versions.size).to(eq(4)) @section.destroy expect(@chapter.versions.size).to(eq(4)) @@ -356,7 +356,7 @@ context "the version after a section is destroyed" do it "not have any sections or paragraphs" do @section.destroy - @chapter.update_attributes(name: CHAPTER_NAMES[5]) + @chapter.update(name: CHAPTER_NAMES[5]) expect(@chapter.versions.size).to(eq(4)) chapter_v3 = @chapter.versions[3].reify(has_many: true) expect(chapter_v3.sections.size).to(eq(0)) @@ -367,7 +367,7 @@ context "the version before a paragraph is destroyed" do it "have the one paragraph" do initial_paragraph_name = @section.paragraphs.first.name - @chapter.update_attributes(name: CHAPTER_NAMES[5]) + @chapter.update(name: CHAPTER_NAMES[5]) @paragraph.destroy chapter_v3 = @chapter.versions[3].reify(has_many: true) paragraphs = chapter_v3.sections.first.paragraphs @@ -379,7 +379,7 @@ context "the version after a paragraph is destroyed" do it "have no paragraphs" do @paragraph.destroy - @chapter.update_attributes(name: CHAPTER_NAMES[5]) + @chapter.update(name: CHAPTER_NAMES[5]) chapter_v3 = @chapter.versions[3].reify(has_many: true) expect(chapter_v3.paragraphs.size).to(eq(0)) expect(chapter_v3.sections.first.paragraphs).to(eq([])) @@ -395,7 +395,7 @@ paragraph = Paragraph.create(name: "Paragraph One", section: section) quotation = Quotation.create(chapter: chapter) citation = Citation.create(quotation: quotation) - chapter.update_attributes(name: CHAPTER_NAMES[1]) + chapter.update(name: CHAPTER_NAMES[1]) expect(chapter.versions.count).to(eq(2)) paragraph.destroy citation.destroy diff --git a/spec/paper_trail/associations/has_one_spec.rb b/spec/paper_trail/associations/has_one_spec.rb index 616b467a0..ba55a4273 100644 --- a/spec/paper_trail/associations/has_one_spec.rb +++ b/spec/paper_trail/associations/has_one_spec.rb @@ -6,7 +6,7 @@ describe "widget, reified from a version prior to creation of wotsit" do it "has a nil wotsit" do widget = Widget.create(name: "widget_0") - widget.update_attributes(name: "widget_1") + widget.update(name: "widget_1") widget.create_wotsit(name: "wotsit_0") widget0 = widget.versions.last.reify(has_one: true) expect(widget0.wotsit).to be_nil @@ -17,7 +17,7 @@ it "has the expected wotsit" do widget = Widget.create(name: "widget_0") wotsit = widget.create_wotsit(name: "wotsit_0") - widget.update_attributes(name: "widget_1") + widget.update(name: "widget_1") widget0 = widget.versions.last.reify(has_one: true) expect(widget0.wotsit.name).to(eq("wotsit_0")) expect(widget.reload.wotsit).to(eq(wotsit)) @@ -28,11 +28,11 @@ it "has the expected wotsit" do widget = Widget.create(name: "widget_0") wotsit = widget.create_wotsit(name: "wotsit_0") - widget.update_attributes(name: "widget_1") - wotsit.update_attributes(name: "wotsit_1") - wotsit.update_attributes(name: "wotsit_2") - widget.update_attributes(name: "widget_2") - wotsit.update_attributes(name: "wotsit_3") + widget.update(name: "widget_1") + wotsit.update(name: "wotsit_1") + wotsit.update(name: "wotsit_2") + widget.update(name: "widget_2") + wotsit.update(name: "wotsit_3") widget1 = widget.versions.last.reify(has_one: true) expect(widget1.wotsit.name).to(eq("wotsit_2")) expect(widget.reload.wotsit.name).to(eq("wotsit_3")) @@ -43,11 +43,11 @@ it "has the latest wotsit in the database" do widget = Widget.create(name: "widget_0") wotsit = widget.create_wotsit(name: "wotsit_0") - widget.update_attributes(name: "widget_1") - wotsit.update_attributes(name: "wotsit_1") - wotsit.update_attributes(name: "wotsit_2") - widget.update_attributes(name: "widget_2") - wotsit.update_attributes(name: "wotsit_3") + widget.update(name: "widget_1") + wotsit.update(name: "wotsit_1") + wotsit.update(name: "wotsit_2") + widget.update(name: "widget_2") + wotsit.update(name: "wotsit_3") widget1 = widget.versions.last.reify(has_one: false) expect(widget1.wotsit.name).to(eq("wotsit_3")) end @@ -57,7 +57,7 @@ it "has the wotsit" do widget = Widget.create(name: "widget_0") wotsit = widget.create_wotsit(name: "wotsit_0") - widget.update_attributes(name: "widget_1") + widget.update(name: "widget_1") wotsit.destroy widget1 = widget.versions.last.reify(has_one: true) expect(widget1.wotsit).to(eq(wotsit)) @@ -69,9 +69,9 @@ it "has a nil wotsit" do widget = Widget.create(name: "widget_0") wotsit = widget.create_wotsit(name: "wotsit_0") - widget.update_attributes(name: "widget_1") + widget.update(name: "widget_1") wotsit.destroy - widget.update_attributes(name: "widget_3") + widget.update(name: "widget_3") widget2 = widget.versions.last.reify(has_one: true) expect(widget2.wotsit).to be_nil end diff --git a/spec/paper_trail/model_spec.rb b/spec/paper_trail/model_spec.rb index f95bb4823..246e6503c 100644 --- a/spec/paper_trail/model_spec.rb +++ b/spec/paper_trail/model_spec.rb @@ -93,13 +93,13 @@ context "and then updated with changes" do it "have three previous versions" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") expect(widget.versions.length).to(eq(2)) end it "be available in its previous version" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") expect(widget.name).to(eq("Harry")) expect(widget.versions.last.object).not_to(be_nil) reified_widget = widget.versions.last.reify @@ -109,19 +109,19 @@ it "have the same ID in its previous version" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") expect(widget.versions.last.reify.id).to(eq(widget.id)) end it "record the correct event" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") expect(widget.versions.last.event).to(match(/update/i)) end it "have versions that are not live" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget.versions.map(&:reify).compact.each do |v| expect(v.paper_trail).not_to be_live end @@ -129,7 +129,7 @@ it "have stored changes" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") last_obj_changes = widget.versions.last.object_changes actual = PaperTrail.serializer.load(last_obj_changes).reject do |k, _v| (k.to_sym == :updated_at) @@ -141,7 +141,7 @@ it "return changes with indifferent access" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") expect(widget.versions.last.changeset[:name]).to(eq(%w[Henry Harry])) expect(widget.versions.last.changeset["name"]).to(eq(%w[Henry Harry])) end @@ -149,7 +149,7 @@ context "and has one associated object" do it "not copy the has_one association by default when reifying" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") wotsit = widget.create_wotsit name: "John" reified_widget = widget.versions.last.reify expect(reified_widget.wotsit).to eq(wotsit) @@ -158,7 +158,7 @@ it "copy the has_one association when reifying with :has_one => true" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") wotsit = widget.create_wotsit name: "John" reified_widget = widget.versions.last.reify(has_one: true) expect(reified_widget.wotsit).to(be_nil) @@ -169,7 +169,7 @@ context "and has many associated objects" do it "copy the has_many associations when reifying" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget.fluxors.create(name: "f-zero") widget.fluxors.create(name: "f-one") reified_widget = widget.versions.last.reify @@ -183,7 +183,7 @@ context "and has many associated polymorphic objects" do it "copy the has_many associations when reifying" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget.whatchamajiggers.create(name: "f-zero") widget.whatchamajiggers.create(name: "f-zero") reified_widget = widget.versions.last.reify @@ -197,7 +197,7 @@ context "polymorphic objects by themselves" do it "not fail with a nil pointer on the polymorphic association" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget = Whatchamajigger.new(name: "f-zero") widget.save! end @@ -206,14 +206,14 @@ context "and then destroyed" do it "record the correct event" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget.destroy expect(PaperTrail::Version.last.event).to(match(/destroy/i)) end it "have three previous versions" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget.destroy expect(PaperTrail::Version.with_item_keys("Widget", widget.id).length).to(eq(3)) end @@ -221,7 +221,7 @@ describe "#attributes" do it "returns the expected attributes for the reified widget" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget.destroy reified_widget = PaperTrail::Version.last.reify expect(reified_widget.id).to eq(widget.id) @@ -249,7 +249,7 @@ it "be re-creatable from its previous version" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget.destroy reified_widget = PaperTrail::Version.last.reify expect(reified_widget.save).to(be_truthy) @@ -257,7 +257,7 @@ it "restore its associations on its previous version" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget.fluxors.create(name: "flux") widget.destroy reified_widget = PaperTrail::Version.last.reify @@ -267,7 +267,7 @@ it "have nil item for last version" do widget = Widget.create(name: "Henry") - widget.update_attributes(name: "Harry") + widget.update(name: "Harry") widget.destroy expect(widget.versions.last.item).to be_nil end @@ -306,7 +306,7 @@ a_date: @date, a_boolean: true ) - @widget.update_attributes( + @widget.update( name: nil, a_text: nil, an_integer: nil, @@ -389,7 +389,7 @@ after { PaperTrail.enabled = true } context "when updated" do - before { @widget.update_attributes(name: "Beeblebrox") } + before { @widget.update(name: "Beeblebrox") } it "not add to its trail" do expect(@widget.versions.length).to(eq(@count)) @@ -408,7 +408,7 @@ end context "when updated" do - before { @widget.update_attributes(name: "Beeblebrox") } + before { @widget.update(name: "Beeblebrox") } it "not add to its trail" do expect(@widget.versions.length).to(eq(@count)) @@ -421,7 +421,7 @@ end context "when updated" do - before { @widget.update_attributes(name: "Ford") } + before { @widget.update(name: "Ford") } it "add to its trail" do expect(@widget.versions.length).to(eq((@count + 1))) @@ -451,7 +451,7 @@ context "when a record is updated" do before do PaperTrail.request.whodunnit = "Bob" - @widget.update_attributes(name: "Rivet") + @widget.update(name: "Rivet") @version = @widget.versions.last end @@ -480,23 +480,23 @@ end end - it "update_attributes! records timestamps" do + it "update! records timestamps" do wotsit = Wotsit.create!(name: "wotsit") - wotsit.update_attributes!(name: "changed") + wotsit.update!(name: "changed") reified = wotsit.versions.last.reify expect(reified.created_at).not_to(be_nil) expect(reified.updated_at).not_to(be_nil) end - it "update_attributes! does not raise error" do + it "update! does not raise error" do wotsit = Wotsit.create!(name: "name1") - expect { wotsit.update_attributes!(name: "name2") }.not_to(raise_error) + expect { wotsit.update!(name: "name2") }.not_to(raise_error) end context "A subclass" do before do @foo = FooWidget.create - @foo.update_attributes!(name: "Foo") + @foo.update!(name: "Foo") end it "reify with the correct type" do @@ -527,8 +527,8 @@ context "An item with versions" do before do @widget = Widget.create(name: "Widget") - @widget.update_attributes(name: "Fidget") - @widget.update_attributes(name: "Digit") + @widget.update(name: "Fidget") + @widget.update(name: "Digit") end context "which were created over time" do @@ -536,9 +536,9 @@ @created = 2.days.ago @first_update = 1.day.ago @second_update = 1.hour.ago - @widget.versions[0].update_attributes(created_at: @created) - @widget.versions[1].update_attributes(created_at: @first_update) - @widget.versions[2].update_attributes(created_at: @second_update) + @widget.versions[0].update(created_at: @created) + @widget.versions[1].update(created_at: @first_update) + @widget.versions[2].update(created_at: @second_update) @widget.update_attribute(:updated_at, @second_update) end @@ -590,9 +590,9 @@ @created = 30.days.ago @first_update = 15.days.ago @second_update = 1.day.ago - @widget.versions[0].update_attributes(created_at: @created) - @widget.versions[1].update_attributes(created_at: @first_update) - @widget.versions[2].update_attributes(created_at: @second_update) + @widget.versions[0].update(created_at: @created) + @widget.versions[1].update(created_at: @first_update) + @widget.versions[2].update(created_at: @second_update) @widget.update_attribute(:updated_at, @second_update) end @@ -676,7 +676,7 @@ context "and updated" do before do - @article.update_attributes!(content: "Better text.", title: "Rhubarb") + @article.update!(content: "Better text.", title: "Rhubarb") end it "store fixed meta data" do @@ -722,7 +722,7 @@ before do widget = Widget.create(name: "Bob") %w[Tom Dick Jane].each do |name| - widget.update_attributes(name: name) + widget.update(name: name) end @version = widget.versions.last @widget = @version.reify @@ -743,7 +743,7 @@ it "returns the object (not a Version) as it became next" do widget = Widget.create(name: "Bob") %w[Tom Dick Jane].each do |name| - widget.update_attributes(name: name) + widget.update(name: name) end second_widget = widget.versions[1].reify last_widget = widget.versions.last.reify @@ -758,7 +758,7 @@ expect(widget.paper_trail.next_version).to(be_nil) widget.save %w[Tom Dick Jane].each do |name| - widget.update_attributes(name: name) + widget.update(name: name) end expect(widget.paper_trail.next_version).to(be_nil) end @@ -770,7 +770,7 @@ it "returns the object (not a Version) as it was most recently" do widget = Widget.create(name: "Bob") %w[Tom Dick Jane].each do |name| - widget.update_attributes(name: name) + widget.update(name: name) end second_widget = widget.versions[1].reify last_widget = widget.versions.last.reify @@ -785,7 +785,7 @@ expect(widget.paper_trail.previous_version).to(be_nil) widget.save %w[Tom Dick Jane].each do |name| - widget.update_attributes(name: name) + widget.update(name: name) end expect(widget.paper_trail.previous_version.name).to(eq(widget.versions.last.reify.name)) end @@ -843,7 +843,7 @@ context "the default accessor, length=, is overwritten" do it "returns overwritten value on reified instance" do song = Song.create(length: 4) - song.update_attributes(length: 5) + song.update(length: 5) expect(song.length).to(eq(5)) expect(song.versions.last.reify.length).to(eq(4)) end @@ -852,7 +852,7 @@ context "song name is a virtual attribute (no such db column)" do it "returns overwritten virtual attribute on the reified instance" do song = Song.create(length: 4) - song.update_attributes(length: 5) + song.update(length: 5) song.name = "Good Vibrations" song.save song.name = "Yellow Submarine" diff --git a/spec/paper_trail/version_limit_spec.rb b/spec/paper_trail/version_limit_spec.rb index 0e1981a8a..1dc6769b0 100644 --- a/spec/paper_trail/version_limit_spec.rb +++ b/spec/paper_trail/version_limit_spec.rb @@ -13,7 +13,7 @@ module PaperTrail widget = Widget.create 100.times do |i| - widget.update_attributes(name: "Name #{i}") + widget.update(name: "Name #{i}") expect(Widget.find(widget.id).versions.count).to be <= 11 # 11 versions = 10 updates + 1 create. end diff --git a/spec/paper_trail/version_spec.rb b/spec/paper_trail/version_spec.rb index 2abd60457..e29008bb1 100644 --- a/spec/paper_trail/version_spec.rb +++ b/spec/paper_trail/version_spec.rb @@ -7,7 +7,7 @@ module PaperTrail describe ".creates" do it "returns only create events" do animal = Animal.create(name: "Foo") - animal.update_attributes(name: "Bar") + animal.update(name: "Bar") expect(described_class.creates.pluck(:event)).to eq(["create"]) end end @@ -15,7 +15,7 @@ module PaperTrail describe ".updates" do it "returns only update events" do animal = Animal.create - animal.update_attributes(name: "Animal") + animal.update(name: "Animal") expect(described_class.updates.pluck(:event)).to eq(["update"]) end end @@ -31,7 +31,7 @@ module PaperTrail describe ".not_creates" do it "returns all versions except create events" do animal = Animal.create - animal.update_attributes(name: "Animal") + animal.update(name: "Animal") animal.destroy expect( described_class.not_creates.pluck(:event) @@ -44,7 +44,7 @@ module PaperTrail it "returns all versions that were created after the timestamp" do animal = Animal.create 2.times do - animal.update_attributes(name: FFaker::Lorem.word) + animal.update(name: FFaker::Lorem.word) end value = described_class.subsequent(1.hour.ago, true) expect(value).to eq(animal.versions.to_a) @@ -58,7 +58,7 @@ module PaperTrail it "grab the timestamp from the version and use that as the value" do animal = Animal.create 2.times do - animal.update_attributes(name: FFaker::Lorem.word) + animal.update(name: FFaker::Lorem.word) end expect(described_class.subsequent(animal.versions.first)).to eq( animal.versions.to_a.drop(1) @@ -72,7 +72,7 @@ module PaperTrail it "returns all versions that were created before the timestamp" do animal = Animal.create 2.times do - animal.update_attributes(name: FFaker::Lorem.word) + animal.update(name: FFaker::Lorem.word) end value = described_class.preceding(5.seconds.from_now, true) expect(value).to eq(animal.versions.reverse) @@ -86,7 +86,7 @@ module PaperTrail it "grab the timestamp from the version and use that as the value" do animal = Animal.create 2.times do - animal.update_attributes(name: FFaker::Lorem.word) + animal.update(name: FFaker::Lorem.word) end expect(described_class.preceding(animal.versions.last)).to eq( animal.versions.to_a.tap(&:pop).reverse