acts_as_status_for 2.0.2 → 2.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.2
1
+ 2.1.0
@@ -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 = "2.0.2"
8
+ s.version = "2.1.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-28}
12
+ s.date = %q{2011-06-29}
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 = [
@@ -20,11 +20,42 @@ module ActsAsStatusFor
20
20
  def log_error(state)
21
21
  STDERR.puts "Arel could not find #{state}_at in the database - skipping installation of acts_as_status"
22
22
  end
23
+
24
+
25
+ #
26
+ # having the state means that the
27
+ # state is not nil and the state_at is greater than all the other states not nil
28
+ #
29
+ def construct_have_state_arel_condition(state)
30
+ has_condition = self.arel_table["#{state}_at".to_sym].not_eq(nil)
31
+ (on_at_events - [state]).each do | unstate |
32
+ has_condition = has_condition.and(self.arel_table["#{state}_at".to_sym].
33
+ gt(self.arel_table["#{unstate}_at".to_sym]).
34
+ or(self.arel_table["#{unstate}_at".to_sym].eq(nil)))
35
+ end
36
+ has_condition
37
+ end
38
+
39
+ #
40
+ # not having the state means that the
41
+ # state is nil or the state_at is less or equal to all the other non nil states
42
+ #
43
+ def construct_not_have_state_arel_condition(state)
44
+ has_not_condition = self.arel_table["#{state}_at".to_sym].eq(nil)
45
+ (on_at_events - [state]).each do | unstate |
46
+ has_not_condition = has_not_condition.or(self.arel_table["#{state}_at".to_sym].
47
+ lteq(self.arel_table["#{unstate}_at".to_sym]).
48
+ and(self.arel_table["#{unstate}_at".to_sym].not_eq(nil)))
49
+ end
50
+ has_not_condition
51
+ end
23
52
  def install_scopes
24
- on_at_events.each do |state|
53
+ on_at_events.each do | state |
25
54
  if self.arel_table["#{state}_at".to_sym] then
26
- scope "#{state}".to_sym, where(self.arel_table["#{state}_at".to_sym].not_eq(nil))
27
- scope "not_#{state}".to_sym, where(self.arel_table["#{state}_at".to_sym].eq(nil))
55
+ has_condition = construct_have_state_arel_condition(state)
56
+ has_not_condition = construct_not_have_state_arel_condition(state)
57
+ scope "#{state}".to_sym, where(has_condition)
58
+ scope "not_#{state}".to_sym, where(has_not_condition)
28
59
  else
29
60
  log_error(state)
30
61
  @all_status_marks_exist = @all_status_marks_exist && false
@@ -70,7 +101,7 @@ module ActsAsStatusFor
70
101
  def current_status
71
102
  status.split(' ').first or ''
72
103
  end
73
-
104
+
74
105
  def status=(event_string)
75
106
  case event_string
76
107
  when ''
@@ -86,13 +117,13 @@ module ActsAsStatusFor
86
117
  end
87
118
  end
88
119
  alias :current_status= :status=
89
- def status
90
- status_time = {}
91
- self.class.on_at_events.each do | event |
92
- time = self.send("#{event}_at")
120
+ def status
121
+ status_time = {}
122
+ self.class.on_at_events.each do | event |
123
+ time = self.send("#{event}_at")
93
124
  status_time[event] = time unless time.nil?
125
+ end
126
+ status_time.sort { |a,b| b.last <=> a.last }.collect(&:first).join(' ')
94
127
  end
95
- status_time.sort { |a,b| b.last <=> a.last }.collect(&:first).join(' ')
96
- end
97
128
  end
98
129
  end
@@ -109,14 +109,29 @@ describe ActsAsStatusFor do
109
109
  subject.status = ''
110
110
  subject.status.should == ''
111
111
  end
112
- {
112
+
113
+ describe "audit trail is independent of scope" do
114
+ it "should recognize only the most recent" do
115
+ subject.featured_at = 3.days.ago
116
+ subject.on_hold_at = 1.days.ago
117
+ subject.archived_at = Time.now
118
+ subject.save
119
+ subject.class.archived.should include(subject)
120
+ subject.class.not_on_hold.should include(subject)
121
+ subject.class.on_hold.should_not include(subject)
122
+ subject.class.not_featured.should include(subject)
123
+ subject.class.featured.should_not include(subject)
124
+ end
125
+ end
126
+
127
+ (ClassFinderMethods = {
113
128
  # class finder method
114
129
  # => [ list of event states that belong to finder]
115
130
  #
116
131
  :featured => [:featured],
117
132
  :on_hold => [:on_hold],
118
133
  :archived => [:archived]
119
- }.each do |scope,states|
134
+ }).each do |scope,states|
120
135
  states.each do |state|
121
136
  it "can be used to set events" do
122
137
  subject.status = state.to_s
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: 2.0.2
5
+ version: 2.1.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-28 00:00:00 -07:00
13
+ date: 2011-06-29 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: 556641777155012256
119
+ hash: -3085350057681311933
120
120
  segments:
121
121
  - 0
122
122
  version: "0"