statesman 3.4.0 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 171ee6b0234ee7909d9af5b91ee09e8cb397adac1c1e90db5e53b1e08413d137
4
- data.tar.gz: fd445775c6f034e067b492e79191803c4b5f48127599e9395374fb7934ea9d8e
3
+ metadata.gz: 7aa22275abdc014b0365e925fd1e6def087e00da45d407503807b948900ed786
4
+ data.tar.gz: 7e7b9319cb03f9d3f718c8bc47efec8dc3626dc197626eec8ff3cacb5cbbac24
5
5
  SHA512:
6
- metadata.gz: 0b88f58d64734af53bbf5155059a5f56ad96578c7d7be57e0f4b52b77bf1f57db6629438d91da1acd5068ea456d16893070555a720e1d153f7b5111cfa2f4ce2
7
- data.tar.gz: 3e07fafb2c37ae74a9c60f38ac186110d7f01e2024ff0361948b8dc039e282845748f31737f25a36d228eb8188788f2f7be8db2e1e2d978486e82153c82a7474
6
+ metadata.gz: 0a6a34ee714a7b860babe30605a362d0081950d8c662b013ed126b89f587fab7778064c4133d362b467d730e6a9513936b0938a436ce49373be725263dbb1f88
7
+ data.tar.gz: 36496a50080940acd1b97996435b8b3ece3c039140f216db6f1b6fee94d89c843e41e16a0def06b4699412a9c7886bdafe4236142d13a9f6d09aeee51e82f9f5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v3.4.1, 14 February 2018 ❤️
2
+
3
+ - Support ActiveRecord transition classes which don't include `Statesman::Adapters::ActiveRecordTransition`, and thus don't have a `.updated_timestamp_column` method (see #310 for further details) (patch by [@timrogers](https://github.com/timrogers))
4
+
1
5
  ## v3.4.0, 12 February 2018
2
6
 
3
7
  - When unsetting the `most_recent` flag during a transition, don't assume that transitions have an `updated_at` attribute, but rather allow the "updated timestamp column" to be re-configured or disabled entirely (patch by [@timrogers](https://github.com/timrogers))
data/README.md CHANGED
@@ -29,7 +29,7 @@ protection.
29
29
  To get started, just add Statesman to your `Gemfile`, and then run `bundle`:
30
30
 
31
31
  ```ruby
32
- gem 'statesman', '~> 3.4.0'
32
+ gem 'statesman', '~> 3.4.1'
33
33
  ```
34
34
 
35
35
  ## Usage
@@ -121,7 +121,7 @@ Order.not_in_state(:checking_out) # => [#<Order id: "123">]
121
121
 
122
122
  By default Statesman stores transition history in memory only. It can be
123
123
  persisted by configuring Statesman to use a different adapter. For example,
124
- ActiveRecord within Rails:
124
+ for ActiveRecord within Rails:
125
125
 
126
126
  `config/initializers/statesman.rb`:
127
127
 
@@ -137,6 +137,10 @@ Generate the transition model:
137
137
  $ rails g statesman:active_record_transition Order OrderTransition
138
138
  ```
139
139
 
140
+ Your transition class should
141
+ `include Statesman::Adapters::ActiveRecordTransition` if you're using the
142
+ ActiveRecord adapter.
143
+
140
144
  If you're using the ActiveRecord adapter and decide not to include the default
141
145
  `updated_at` column in your transition table, you'll need to configure the
142
146
  `updated_timestamp_column` option on the transition class, setting it to another column
@@ -178,8 +182,12 @@ or 5. To do that
178
182
  t.json :metadata, default: {}
179
183
  ```
180
184
 
181
- * Remove `include Statesman::Adapters::ActiveRecordTransition` statement from your
182
- transition model
185
+ * Remove the `include Statesman::Adapters::ActiveRecordTransition` statement from
186
+ your transition model. (If you want to customise your transition class's "updated
187
+ timestamp column", as described above, you should define a
188
+ `.updated_timestamp_column` method on your class and return the name of the column
189
+ as a symbol, or `nil` if you don't want to record an updated timestamp on
190
+ transitions.)
183
191
 
184
192
  ## Configuration
185
193
 
@@ -123,7 +123,20 @@ module Statesman
123
123
  end
124
124
 
125
125
  def with_updated_timestamp(params)
126
- return params if @transition_class.updated_timestamp_column.nil?
126
+ # TODO: Once we've set expectations that transition classes should conform to
127
+ # the interface of Adapters::ActiveRecordTransition as a breaking change in the
128
+ # next major version, we can stop calling `#respond_to?` first and instead
129
+ # assume that there is a `.updated_timestamp_column` method we can call.
130
+ #
131
+ # At the moment, most transition classes will include the module, but not all,
132
+ # not least because it doesn't work with PostgreSQL JSON columns for metadata.
133
+ column = if @transition_class.respond_to?(:updated_timestamp_column)
134
+ @transition_class.updated_timestamp_column
135
+ else
136
+ ActiveRecordTransition::DEFAULT_UPDATED_TIMESTAMP_COLUMN
137
+ end
138
+
139
+ return params if column.nil?
127
140
 
128
141
  timestamp = if ::ActiveRecord::Base.default_timezone == :utc
129
142
  Time.now.utc
@@ -131,7 +144,7 @@ module Statesman
131
144
  Time.now
132
145
  end
133
146
 
134
- params.merge(@transition_class.updated_timestamp_column => timestamp)
147
+ params.merge(column => timestamp)
135
148
  end
136
149
  end
137
150
  end
@@ -1,3 +1,3 @@
1
1
  module Statesman
2
- VERSION = "3.4.0".freeze
2
+ VERSION = "3.4.1".freeze
3
3
  end
@@ -163,6 +163,19 @@ describe Statesman::Adapters::ActiveRecord, active_record: true do
163
163
  to(change { previous_transition.reload.updated_at })
164
164
  end
165
165
 
166
+ context "for a transition class without an updated timestamp column attribute" do
167
+ let!(:adapter) do
168
+ described_class.new(MyActiveRecordModelTransitionWithoutInclude,
169
+ model,
170
+ observer)
171
+ end
172
+
173
+ it "defaults to touching the previous transition's updated_at timestamp" do
174
+ expect { Timecop.freeze(Time.now + 5.seconds) { create } }.
175
+ to(change { previous_transition.reload.updated_at })
176
+ end
177
+ end
178
+
166
179
  context "with a custom updated timestamp column set" do
167
180
  around do |example|
168
181
  MyActiveRecordModelTransition.updated_timestamp_column.tap do |original_value|
@@ -40,6 +40,13 @@ class MyActiveRecordModelTransition < ActiveRecord::Base
40
40
  serialize :metadata, JSON
41
41
  end
42
42
 
43
+ class MyActiveRecordModelTransitionWithoutInclude < ActiveRecord::Base
44
+ self.table_name = "my_active_record_model_transitions"
45
+
46
+ belongs_to :my_active_record_model
47
+ serialize :metadata, JSON
48
+ end
49
+
43
50
  class CreateMyActiveRecordModelMigration < MIGRATION_CLASS
44
51
  def change
45
52
  create_table :my_active_record_models do |t|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statesman
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ammeter