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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5591d28000c93fd3bdb5c5286635e4611b03997b
4
- data.tar.gz: e6d5543632a3438c0044ae8fb7f20df0319ee5a9
3
+ metadata.gz: 07a9c8433b356b5b2011722658b52dbdbd4a399b
4
+ data.tar.gz: 9be5879453318fa5066ed20669dbf9864ebfdcc4
5
5
  SHA512:
6
- metadata.gz: 8a8175b982789ccb5bd1668f5bb487fafb28d473f641707c023320489605e8f39d81128dcd42fa7d67b19bcf6bbce368511dee197587a4782d57883c1e874715
7
- data.tar.gz: a9fabdbb72d3cb1af8861020adb342cae53b19cc26f1c9f38cc4bf8791a39c13ae52604a3caf95cede5a15b23262e874c2dbdd55b103c6cd79a791f0e1af6155
6
+ metadata.gz: f2e083754627dccfb7fe5819aad07ed6f033d6ea05bf154461fc89cd39054ba49e2975c4dd53471451472ebdc432fdfafff683cac715803eaf92fc71f04ea5ee
7
+ data.tar.gz: fc3c7b6c581ae0bf7094b06a860ffacd85e42a07d0badbbd571ce55974e2d1bbc9bbcc746bb2f7f7f9794d1a7d03e4cfd520a86c3378d51a53f32833c8b22994
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.0
1
+ 4.1.0
@@ -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.0.0 ruby lib
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.0.0"
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 = "2014-07-29"
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 = [
@@ -146,13 +146,31 @@ module ActsAsStatusFor
146
146
  end
147
147
  end
148
148
  alias :current_status= :status=
149
- def status
150
- status_time = {}
151
- self.class.on_at_events.each do | event |
152
- time = self.send("#{event}_at")
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
- before do
109
- Thing.instance_eval do
110
- acts_as_status_for :on_hold, :archived, :featured
111
- end
112
- end
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
- it "defaults to ''" do
115
- expect(subject.status).to eq('')
116
- end
116
+ end
117
+ class ThingB < ThingA
117
118
 
118
- it "allows negation of status using 'not_' prefix" do
119
- subject.on_hold!
120
- subject.archived!
121
- expect(subject.status).to eq('archived on_hold')
122
- subject.status = "not_archived"
123
- expect(subject.status).to eq('on_hold')
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
- it "is sorted by event time" do
127
- subject.on_hold!
128
- expect(subject.status).to eq('on_hold')
129
- subject.archived!
130
- expect(subject.status).to eq('archived on_hold')
131
- subject.featured!
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
- it "setting it to blank clears all states" do
139
- subject.on_hold!
140
- subject.archived!
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
- describe "audit trail is independent of scope" do
147
- it "should recognize only the most recent" do
148
- subject.featured_at = 3.days.ago
149
- subject.on_hold_at = 1.days.ago
150
- subject.archived_at = Time.now
151
- subject.save
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
- (ClassFinderMethods = {
161
- # class finder method
162
- # => [ list of event states that belong to finder]
163
- #
164
- :featured => [:featured],
165
- :on_hold => [:on_hold],
166
- :archived => [:archived]
167
- }).each do |scope,states|
168
- states.each do |state|
169
- it "can be used to set events" do
170
- subject.status = state.to_s
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
- it "can be reversed" do
176
- subject.status = state.to_s
177
- expect(subject.send("#{state}?")).to be_truthy
178
- subject.status = "not_" + state.to_s
179
- expect(subject.send("#{state}?")).to be_falsey
180
- end
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
- it "#{state} sets state string" do
183
- subject.send("#{state}!")
184
- expect(subject.send("#{state}?")).to be_truthy
185
- expect(subject.status).to include(state.to_s)
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
- it "#{state} is in the scope #{scope}" do
189
- subject.send("#{state}!")
190
- expect(subject.send("#{state}?")).to be_truthy
191
- expect(subject.class.send(scope)).to include(subject)
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.0.0
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: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord