Skip to content

Ensures saving of other changed attributes on state change. #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [3.3]
gemfile: [activerecord-6.0.Gemfile, activerecord-6.1.Gemfile, activerecord-7.0.Gemfile, activerecord-7.1.Gemfile]
ruby: [3.3, 3.4]
gemfile: [activerecord-7.1.Gemfile, activerecord-7.2.Gemfile]
env:
BUNDLE_GEMFILE: gemfiles/${{matrix.gemfile}}
steps:
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,33 @@ end
Changelog
---------

### Next

* Ensure other changed attributes will stored together with state change.

- to avoid a second write query

before:
```rb
def event
o.title = 'new title'
o.save
end
```

now:
```rb
def event
o.title = 'new title'
end
```

* Add Ruby 3.4 to test matrix

- retires: ruby < 3.3, rails < 7.1

* Defines actual passing state

### New in the version 6.0.0

* GH-14 retire Ruby 2.6 and Rails 5.* and older since they have reached end of
Expand Down
3 changes: 0 additions & 3 deletions gemfiles/activerecord-6.1.Gemfile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")

gem 'activerecord', '~> 6.0.0'
gem 'activerecord', '~> 7.2.0'
4 changes: 2 additions & 2 deletions lib/workflow-activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def load_workflow_state
# On transition the new workflow state is immediately saved in the
# database.
def persist_workflow_state(new_value)
# Rails 3.1 or newer
update_column self.class.workflow_column, new_value
assign_attributes(self.class.workflow_column => new_value)
save
end

private
Expand Down
6 changes: 3 additions & 3 deletions test/persistence_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def assert_state(title, expected_state, klass = PersistenceTestOrder)
o
end

test 'ensure other dirty attributes are not saved on state change' do
test 'ensure other dirty attributes are also saved on state change' do
o = assert_state 'order6', 'accepted'
o.title = 'going to change the title'
assert o.changed?
o.ship!
assert o.changed?, 'title should not be saved and the change still stay pending'
# assert o.changed?, 'title should not be saved and the change still stay pending'
assert o.reload.title, 'going to change the title'
end

end

16 changes: 8 additions & 8 deletions workflow_activerecord.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ Gem::Specification.new do |gem|
"README.md"
]

rails_versions = ['>= 6.0']
rails_versions = ['>= 6.0', '< 8.0']

gem.required_ruby_version = '>= 2.7'
gem.required_ruby_version = '>= 3.3'

gem.add_runtime_dependency 'workflow', '~> 3.0'
gem.add_runtime_dependency 'activerecord', rails_versions

gem.add_development_dependency 'rdoc', '~> 6.4'
gem.add_development_dependency 'bundler', '~> 2.3'
gem.add_development_dependency 'mocha', '~> 2.2'
gem.add_development_dependency 'rake', '~> 13.1'
gem.add_development_dependency 'minitest', '~> 5.21'
gem.add_development_dependency 'sqlite3', '~> 1.3'
gem.add_development_dependency 'rdoc'#, '~> 6.4'
gem.add_development_dependency 'bundler'#, '~> 2.3'
gem.add_development_dependency 'mocha'#, '~> 2.2'
gem.add_development_dependency 'rake'#, '~> 13.1'
gem.add_development_dependency 'minitest'#, '~> 5.21'
gem.add_development_dependency 'sqlite3'#, '~> 1.3'
end