aasm 3.0.6 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.0.7
4
+
5
+ * removed deprecation warning when localizing aasm state names (look at https://github.com/rubyist/aasm/issues/38 for details)
6
+
3
7
  ## 3.0.6
4
8
 
5
9
  * bugfix: if configured to skip validation the code does not validate anymore
@@ -11,8 +11,9 @@ Gem::Specification.new do |s|
11
11
  s.summary = %q{State machine mixin for Ruby objects}
12
12
  s.description = %q{AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects.}
13
13
  s.date = Time.now
14
+ s.licenses = ["MIT"]
14
15
 
15
- s.add_dependency 'activerecord'
16
+ s.add_development_dependency 'activerecord'
16
17
  s.add_development_dependency 'rake'
17
18
  s.add_development_dependency 'sdoc'
18
19
  s.add_development_dependency 'rspec', '~> 2.0'
@@ -2,20 +2,35 @@ module AASM
2
2
  module SupportingClasses
3
3
  class Localizer
4
4
  def human_event_name(klass, event)
5
- defaults = ancestors_list(klass).map do |ancestor|
6
- :"#{i18n_scope(klass)}.events.#{i18n_klass(ancestor)}.#{event}"
7
- end << event.to_s.humanize
8
-
9
- I18n.translate(defaults.shift, :default => defaults, :raise => true)
5
+ checklist = ancestors_list(klass).inject([]) do |list, ancestor|
6
+ list << :"#{i18n_scope(klass)}.events.#{i18n_klass(ancestor)}.#{event}"
7
+ list
8
+ end
9
+ (0...(checklist.size-1)).each do |i|
10
+ begin
11
+ return I18n.translate(checklist.shift, :raise => true)
12
+ rescue I18n::MissingTranslationData
13
+ # that's okay
14
+ end
15
+ end
16
+ I18n.translate(checklist.shift, :default => event.to_s.humanize)
10
17
  end
11
18
 
12
19
  def human_state(obj)
13
20
  klass = obj.class
14
- defaults = ancestors_list(klass).map do |ancestor|
15
- :"#{i18n_scope(klass)}.attributes.#{i18n_klass(ancestor)}.#{klass.aasm_column}.#{obj.aasm_current_state}"
16
- end << obj.aasm_current_state.to_s.humanize
17
-
18
- I18n.translate(defaults.shift, :default => defaults, :raise => true)
21
+ checklist = ancestors_list(klass).inject([]) do |list, ancestor|
22
+ list << :"#{i18n_scope(klass)}.attributes.#{i18n_klass(ancestor)}.#{klass.aasm_column}/#{obj.aasm_current_state}"
23
+ list << :"#{i18n_scope(klass)}.attributes.#{i18n_klass(ancestor)}.#{klass.aasm_column}.#{obj.aasm_current_state}"
24
+ list
25
+ end
26
+ (0...(checklist.size-1)).each do |i|
27
+ begin
28
+ return I18n.translate(checklist.shift, :raise => true)
29
+ rescue I18n::MissingTranslationData
30
+ # that's okay
31
+ end
32
+ end
33
+ I18n.translate(checklist.shift, :default => obj.aasm_current_state.to_s.humanize)
19
34
  end
20
35
 
21
36
  private
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "3.0.6"
2
+ VERSION = "3.0.7"
3
3
  end
@@ -6,5 +6,4 @@ en:
6
6
 
7
7
  attributes:
8
8
  localizer_test_model:
9
- aasm_state:
10
- open: "It's opened now!"
9
+ aasm_state/open: "It's opened now!"
@@ -0,0 +1,10 @@
1
+ en:
2
+ activerecord:
3
+ events:
4
+ localizer_test_model:
5
+ close: "Let's close it!"
6
+
7
+ attributes:
8
+ localizer_test_model:
9
+ aasm_state:
10
+ open: "It's opened now!"
@@ -4,7 +4,8 @@ require 'logger'
4
4
 
5
5
  load_schema
6
6
 
7
- ActiveRecord::Base.logger = Logger.new(STDERR)
7
+ # if you want to see the statements while running the spec enable the following line
8
+ # ActiveRecord::Base.logger = Logger.new(STDERR)
8
9
 
9
10
  class Gate < ActiveRecord::Base
10
11
  include AASM
@@ -3,8 +3,6 @@ require 'active_record'
3
3
  require 'logger'
4
4
  require 'i18n'
5
5
 
6
- ActiveRecord::Base.logger = Logger.new(STDERR)
7
-
8
6
  class LocalizerTestModel < ActiveRecord::Base
9
7
  include AASM
10
8
 
@@ -18,7 +16,7 @@ class LocalizerTestModel < ActiveRecord::Base
18
16
  aasm_event :open
19
17
  end
20
18
 
21
- describe AASM::SupportingClasses::Localizer do
19
+ describe AASM::SupportingClasses::Localizer, "new style" do
22
20
  before(:all) do
23
21
  I18n.load_path << 'spec/en.yml'
24
22
  I18n.default_locale = :en
@@ -52,3 +50,38 @@ describe AASM::SupportingClasses::Localizer do
52
50
  end
53
51
  end
54
52
  end
53
+
54
+ describe AASM::SupportingClasses::Localizer, "deprecated style" do
55
+ before(:all) do
56
+ I18n.load_path << 'spec/en_deprecated_style.yml'
57
+ I18n.default_locale = :en
58
+ I18n.reload!
59
+ end
60
+
61
+ after(:all) do
62
+ I18n.load_path.clear
63
+ end
64
+
65
+ let (:foo_opened) { LocalizerTestModel.new }
66
+ let (:foo_closed) { LocalizerTestModel.new.tap { |x| x.aasm_state = :closed } }
67
+
68
+ context 'aasm_human_state' do
69
+ it 'should return translated state value' do
70
+ foo_opened.aasm_human_state.should == "It's opened now!"
71
+ end
72
+
73
+ it 'should return humanized value if not localized' do
74
+ foo_closed.aasm_human_state.should == "Closed"
75
+ end
76
+ end
77
+
78
+ context 'aasm_human_event_name' do
79
+ it 'should return translated event name' do
80
+ LocalizerTestModel.aasm_human_event_name(:close).should == "Let's close it!"
81
+ end
82
+
83
+ it 'should return humanized event name' do
84
+ LocalizerTestModel.aasm_human_event_name(:open).should == "Open"
85
+ end
86
+ end
87
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,22 +12,22 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-05-17 00:00:00.000000000 Z
15
+ date: 2012-06-07 00:00:00.000000000Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord
19
- requirement: &70346607015720 !ruby/object:Gem::Requirement
19
+ requirement: &70261929166680 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
23
23
  - !ruby/object:Gem::Version
24
24
  version: '0'
25
- type: :runtime
25
+ type: :development
26
26
  prerelease: false
27
- version_requirements: *70346607015720
27
+ version_requirements: *70261929166680
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
- requirement: &70346607015180 !ruby/object:Gem::Requirement
30
+ requirement: &70261929166260 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '0'
36
36
  type: :development
37
37
  prerelease: false
38
- version_requirements: *70346607015180
38
+ version_requirements: *70261929166260
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: sdoc
41
- requirement: &70346607014640 !ruby/object:Gem::Requirement
41
+ requirement: &70261929165840 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0'
47
47
  type: :development
48
48
  prerelease: false
49
- version_requirements: *70346607014640
49
+ version_requirements: *70261929165840
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rspec
52
- requirement: &70346607013980 !ruby/object:Gem::Requirement
52
+ requirement: &70261929165340 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ~>
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: '2.0'
58
58
  type: :development
59
59
  prerelease: false
60
- version_requirements: *70346607013980
60
+ version_requirements: *70261929165340
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rr
63
- requirement: &70346607013560 !ruby/object:Gem::Requirement
63
+ requirement: &70261929164920 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ! '>='
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: '0'
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *70346607013560
71
+ version_requirements: *70261929164920
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: shoulda
74
- requirement: &70346607013000 !ruby/object:Gem::Requirement
74
+ requirement: &70261929195940 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ! '>='
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: '0'
80
80
  type: :development
81
81
  prerelease: false
82
- version_requirements: *70346607013000
82
+ version_requirements: *70261929195940
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
85
- requirement: &70346607012380 !ruby/object:Gem::Requirement
85
+ requirement: &70261929195520 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ! '>='
@@ -90,10 +90,10 @@ dependencies:
90
90
  version: '0'
91
91
  type: :development
92
92
  prerelease: false
93
- version_requirements: *70346607012380
93
+ version_requirements: *70261929195520
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: minitest
96
- requirement: &70346607011840 !ruby/object:Gem::Requirement
96
+ requirement: &70261929195100 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ! '>='
@@ -101,10 +101,10 @@ dependencies:
101
101
  version: '0'
102
102
  type: :development
103
103
  prerelease: false
104
- version_requirements: *70346607011840
104
+ version_requirements: *70261929195100
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: ruby-debug-completion
107
- requirement: &70346607011340 !ruby/object:Gem::Requirement
107
+ requirement: &70261929194680 !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements:
110
110
  - - ! '>='
@@ -112,7 +112,7 @@ dependencies:
112
112
  version: '0'
113
113
  type: :development
114
114
  prerelease: false
115
- version_requirements: *70346607011340
115
+ version_requirements: *70261929194680
116
116
  description: AASM is a continuation of the acts as state machine rails plugin, built
117
117
  for plain Ruby objects.
118
118
  email: scott@elitists.net, ttilley@gmail.com
@@ -144,6 +144,7 @@ files:
144
144
  - lib/aasm/version.rb
145
145
  - spec/database.yml
146
146
  - spec/en.yml
147
+ - spec/en_deprecated_style.yml
147
148
  - spec/models/conversation.rb
148
149
  - spec/models/invalid_persistor.rb
149
150
  - spec/models/not_auto_loaded/process.rb
@@ -166,7 +167,8 @@ files:
166
167
  - spec/unit/state_spec.rb
167
168
  - spec/unit/state_transition_spec.rb
168
169
  homepage: http://rubyist.github.com/aasm/
169
- licenses: []
170
+ licenses:
171
+ - MIT
170
172
  post_install_message:
171
173
  rdoc_options: []
172
174
  require_paths:
@@ -185,13 +187,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
187
  version: '0'
186
188
  requirements: []
187
189
  rubyforge_project:
188
- rubygems_version: 1.8.11
190
+ rubygems_version: 1.8.15
189
191
  signing_key:
190
192
  specification_version: 3
191
193
  summary: State machine mixin for Ruby objects
192
194
  test_files:
193
195
  - spec/database.yml
194
196
  - spec/en.yml
197
+ - spec/en_deprecated_style.yml
195
198
  - spec/models/conversation.rb
196
199
  - spec/models/invalid_persistor.rb
197
200
  - spec/models/not_auto_loaded/process.rb