acts_as_status_for 1.1.2 → 2.0.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.
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/acts_as_status_for.gemspec +2 -2
- data/lib/acts_as_status_for.rb +10 -6
- data/spec/acts_as_status_for_spec.rb +40 -0
- metadata +3 -3
data/Rakefile
CHANGED
@@ -37,9 +37,8 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
37
37
|
end
|
38
38
|
|
39
39
|
task :default => :spec
|
40
|
-
|
41
|
-
|
42
|
-
Rake::RDocTask.new do |rdoc|
|
40
|
+
require 'rdoc/task'
|
41
|
+
RDoc::Task.new do |rdoc|
|
43
42
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
43
|
|
45
44
|
rdoc.rdoc_dir = 'rdoc'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
data/acts_as_status_for.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{acts_as_status_for}
|
8
|
-
s.version = "
|
8
|
+
s.version = "2.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Curtis Schofield"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-27}
|
13
13
|
s.description = %q{Given a list of datetime _at attributes }
|
14
14
|
s.email = %q{github.com@robotarmyma.de}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/acts_as_status_for.rb
CHANGED
@@ -71,7 +71,10 @@ module ActsAsStatusFor
|
|
71
71
|
end
|
72
72
|
|
73
73
|
module InstanceMethods
|
74
|
-
|
74
|
+
def current_status
|
75
|
+
status.split(' ').first or ''
|
76
|
+
end
|
77
|
+
|
75
78
|
def status=(event_string)
|
76
79
|
case event_string
|
77
80
|
when ''
|
@@ -79,20 +82,21 @@ module ActsAsStatusFor
|
|
79
82
|
self.send("#{event}!") if self.respond_to?("#{event}!")
|
80
83
|
end
|
81
84
|
else
|
82
|
-
event_string.split(' ').each do | event |
|
85
|
+
event_string.split(' ').each do | event |
|
83
86
|
if self.class.all_at_events.include?(event.to_sym)
|
84
87
|
self.send("#{event}!") if self.respond_to?("#{event}!")
|
85
88
|
end
|
86
89
|
end
|
87
90
|
end
|
88
91
|
end
|
89
|
-
|
92
|
+
alias :current_status= :status=
|
90
93
|
def status
|
91
|
-
|
94
|
+
status_time = {}
|
92
95
|
self.class.on_at_events.each do | event |
|
93
|
-
|
96
|
+
time = self.send("#{event}_at")
|
97
|
+
status_time[event] = time unless time.nil?
|
94
98
|
end
|
95
|
-
|
99
|
+
status_time.sort { |a,b| b.last <=> a.last }.collect(&:first).join(' ')
|
96
100
|
end
|
97
101
|
end
|
98
102
|
end
|
@@ -40,16 +40,56 @@ describe ActsAsStatusFor do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
context "#current_status" do
|
44
|
+
it 'has a setter' do
|
45
|
+
subject.current_status = 'on_hold'
|
46
|
+
subject.on_hold?.should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'reveals the last status set' do
|
50
|
+
subject.on_hold!
|
51
|
+
subject.current_status.should == 'on_hold'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'can be wound and unwound' do
|
55
|
+
subject.on_hold!
|
56
|
+
subject.current_status.should == 'on_hold'
|
57
|
+
subject.archived!
|
58
|
+
subject.current_status.should == 'archived'
|
59
|
+
subject.featured!
|
60
|
+
subject.current_status.should == 'featured'
|
61
|
+
subject.not_featured!
|
62
|
+
subject.current_status.should == 'archived'
|
63
|
+
subject.not_archived!
|
64
|
+
subject.current_status.should == 'on_hold'
|
65
|
+
subject.not_on_hold!
|
66
|
+
subject.current_status.should == ''
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
43
70
|
context "#status" do
|
44
71
|
before do
|
45
72
|
Thing.instance_eval do
|
46
73
|
acts_as_status_for :on_hold, :archived, :featured
|
47
74
|
end
|
48
75
|
end
|
76
|
+
|
49
77
|
it "defaults to ''" do
|
50
78
|
subject.status.should == ''
|
51
79
|
end
|
52
80
|
|
81
|
+
it "is sorted by event time" do
|
82
|
+
subject.on_hold!
|
83
|
+
subject.status.should == 'on_hold'
|
84
|
+
subject.archived!
|
85
|
+
subject.status.should == 'archived on_hold'
|
86
|
+
subject.featured!
|
87
|
+
subject.status.should == 'featured archived on_hold'
|
88
|
+
subject.not_on_hold!
|
89
|
+
subject.on_hold!
|
90
|
+
subject.status.should == 'on_hold featured archived'
|
91
|
+
end
|
92
|
+
|
53
93
|
it "setting it to blank clears all states" do
|
54
94
|
subject.on_hold!
|
55
95
|
subject.archived!
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: acts_as_status_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version:
|
5
|
+
version: 2.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Curtis Schofield
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-27 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
requirements:
|
117
117
|
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
hash:
|
119
|
+
hash: 1247048969588569045
|
120
120
|
segments:
|
121
121
|
- 0
|
122
122
|
version: "0"
|