acts_as_status_for 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/acts_as_status_for.gemspec +3 -3
- data/lib/acts_as_status_for.rb +23 -5
- data/spec/acts_as_status_for_spec.rb +102 -72
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07a9c8433b356b5b2011722658b52dbdbd4a399b
|
4
|
+
data.tar.gz: 9be5879453318fa5066ed20669dbf9864ebfdcc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2e083754627dccfb7fe5819aad07ed6f033d6ea05bf154461fc89cd39054ba49e2975c4dd53471451472ebdc432fdfafff683cac715803eaf92fc71f04ea5ee
|
7
|
+
data.tar.gz: fc3c7b6c581ae0bf7094b06a860ffacd85e42a07d0badbbd571ce55974e2d1bbc9bbcc746bb2f7f7f9794d1a7d03e4cfd520a86c3378d51a53f32833c8b22994
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.1.0
|
data/acts_as_status_for.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: acts_as_status_for 4.
|
5
|
+
# stub: acts_as_status_for 4.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "acts_as_status_for"
|
9
|
-
s.version = "4.
|
9
|
+
s.version = "4.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Curtis Schofield"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2015-02-11"
|
15
15
|
s.description = "Given a list of datetime _at attributes allow an activerecord object to query status, change status and hold multiple states, these states can be used to build state machines or other constructs. "
|
16
16
|
s.email = "github.com@robotarmyma.de"
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/acts_as_status_for.rb
CHANGED
@@ -146,13 +146,31 @@ module ActsAsStatusFor
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
alias :current_status= :status=
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
149
|
+
|
150
|
+
def status
|
151
|
+
status_time = {}
|
152
|
+
get_on_at_events.each do | event |
|
153
|
+
time = self.send("#{event}_at")
|
153
154
|
status_time[event] = time unless time.nil?
|
155
|
+
end
|
156
|
+
status_time.sort { |a,b| b.last <=> a.last }.collect(&:first).join(' ')
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
def get_on_at_events
|
161
|
+
current_klass = self.class
|
162
|
+
events = current_klass.on_at_events
|
163
|
+
while events.nil?
|
164
|
+
current_klass = current_klass.superclass
|
165
|
+
if current_klass.respond_to? :on_at_events
|
166
|
+
events = current_klass.on_at_events
|
167
|
+
else
|
168
|
+
puts "WARNING >> ActsAsStatusFor [ No status events found ] "
|
169
|
+
events = []
|
170
|
+
break
|
154
171
|
end
|
155
|
-
status_time.sort { |a,b| b.last <=> a.last }.collect(&:first).join(' ')
|
156
172
|
end
|
173
|
+
events
|
174
|
+
end
|
157
175
|
end
|
158
176
|
end
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
ActiveRecord::Migration.create_table :things do |t|
|
4
4
|
t.string :name
|
5
|
+
t.string :type # allow single table inheritance
|
5
6
|
t.datetime :on_hold_at
|
6
7
|
t.datetime :archived_at
|
7
8
|
t.datetime :featured_at
|
@@ -105,90 +106,119 @@ describe ActsAsStatusFor do
|
|
105
106
|
end
|
106
107
|
end
|
107
108
|
context "#status" do
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
context "with multi object inheritance" do
|
110
|
+
before do
|
111
|
+
Thing.instance_eval do
|
112
|
+
acts_as_status_for :on_hold, :archived, :featured
|
113
|
+
end
|
114
|
+
class ThingA < Thing
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
-
end
|
116
|
+
end
|
117
|
+
class ThingB < ThingA
|
117
118
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
119
|
+
end
|
120
|
+
end
|
121
|
+
context "it searches inheritance tree for on_at_methods" do
|
122
|
+
subject {
|
123
|
+
ThingB.new(:name => 'required')
|
124
|
+
}
|
125
|
+
it "defaults to ''" do
|
126
|
+
expect(subject.status).to eq('')
|
127
|
+
end
|
128
|
+
it "uses superclasse status" do
|
129
|
+
subject.on_hold!
|
130
|
+
expect(subject.status).to eq('on_hold')
|
131
|
+
end
|
132
|
+
end
|
124
133
|
end
|
125
134
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
expect(subject.status).to eq('featured archived on_hold')
|
133
|
-
subject.not_on_hold!
|
134
|
-
subject.on_hold!
|
135
|
-
expect(subject.status).to eq('on_hold featured archived')
|
136
|
-
end
|
135
|
+
context "with single object" do
|
136
|
+
before do
|
137
|
+
Thing.instance_eval do
|
138
|
+
acts_as_status_for :on_hold, :archived, :featured
|
139
|
+
end
|
140
|
+
end
|
137
141
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
subject.featured!
|
142
|
-
subject.status = ''
|
143
|
-
expect(subject.status).to eq('')
|
144
|
-
end
|
142
|
+
it "defaults to ''" do
|
143
|
+
expect(subject.status).to eq('')
|
144
|
+
end
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
subject.
|
149
|
-
subject.
|
150
|
-
subject.
|
151
|
-
subject.
|
152
|
-
expect(subject.class.archived).to include(subject)
|
153
|
-
expect(subject.class.not_on_hold).to include(subject)
|
154
|
-
expect(subject.class.on_hold).not_to include(subject)
|
155
|
-
expect(subject.class.not_featured).to include(subject)
|
156
|
-
expect(subject.class.featured).not_to include(subject)
|
146
|
+
it "allows negation of status using 'not_' prefix" do
|
147
|
+
subject.on_hold!
|
148
|
+
subject.archived!
|
149
|
+
expect(subject.status).to eq('archived on_hold')
|
150
|
+
subject.status = "not_archived"
|
151
|
+
expect(subject.status).to eq('on_hold')
|
157
152
|
end
|
158
|
-
end
|
159
153
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
expect(subject.send(%%#{state}?%)).to be_truthy
|
172
|
-
expect(subject.status).to include(state.to_s)
|
173
|
-
end
|
154
|
+
it "is sorted by event time" do
|
155
|
+
subject.on_hold!
|
156
|
+
expect(subject.status).to eq('on_hold')
|
157
|
+
subject.archived!
|
158
|
+
expect(subject.status).to eq('archived on_hold')
|
159
|
+
subject.featured!
|
160
|
+
expect(subject.status).to eq('featured archived on_hold')
|
161
|
+
subject.not_on_hold!
|
162
|
+
subject.on_hold!
|
163
|
+
expect(subject.status).to eq('on_hold featured archived')
|
164
|
+
end
|
174
165
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
166
|
+
it "setting it to blank clears all states" do
|
167
|
+
subject.on_hold!
|
168
|
+
subject.archived!
|
169
|
+
subject.featured!
|
170
|
+
subject.status = ''
|
171
|
+
expect(subject.status).to eq('')
|
172
|
+
end
|
181
173
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
174
|
+
|
175
|
+
describe "audit trail is independent of scope" do
|
176
|
+
it "should recognize only the most recent" do
|
177
|
+
subject.featured_at = 3.days.ago
|
178
|
+
subject.on_hold_at = 1.days.ago
|
179
|
+
subject.archived_at = Time.now
|
180
|
+
subject.save
|
181
|
+
expect(subject.class.archived).to include(subject)
|
182
|
+
expect(subject.class.not_on_hold).to include(subject)
|
183
|
+
expect(subject.class.on_hold).not_to include(subject)
|
184
|
+
expect(subject.class.not_featured).to include(subject)
|
185
|
+
expect(subject.class.featured).not_to include(subject)
|
186
186
|
end
|
187
|
+
end
|
187
188
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
189
|
+
(ClassFinderMethods = {
|
190
|
+
# class finder method
|
191
|
+
# => [ list of event states that belong to finder]
|
192
|
+
#
|
193
|
+
:featured => [:featured],
|
194
|
+
:on_hold => [:on_hold],
|
195
|
+
:archived => [:archived]
|
196
|
+
}).each do |scope,states|
|
197
|
+
states.each do |state|
|
198
|
+
it "can be used to set events" do
|
199
|
+
subject.status = state.to_s
|
200
|
+
expect(subject.send(%%#{state}?%)).to be_truthy
|
201
|
+
expect(subject.status).to include(state.to_s)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "can be reversed" do
|
205
|
+
subject.status = state.to_s
|
206
|
+
expect(subject.send("#{state}?")).to be_truthy
|
207
|
+
subject.status = "not_" + state.to_s
|
208
|
+
expect(subject.send("#{state}?")).to be_falsey
|
209
|
+
end
|
210
|
+
|
211
|
+
it "#{state} sets state string" do
|
212
|
+
subject.send("#{state}!")
|
213
|
+
expect(subject.send("#{state}?")).to be_truthy
|
214
|
+
expect(subject.status).to include(state.to_s)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "#{state} is in the scope #{scope}" do
|
218
|
+
subject.send("#{state}!")
|
219
|
+
expect(subject.send("#{state}?")).to be_truthy
|
220
|
+
expect(subject.class.send(scope)).to include(subject)
|
221
|
+
end
|
192
222
|
end
|
193
223
|
end
|
194
224
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_status_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Curtis Schofield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|