transitions 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.0.4
2
+
3
+ (troessner)
4
+
5
+ * Raise exception if we try to overwrite existing instance methods when defining state predicate methods
6
+ * Improve exception message if we try to overwrite existing class methods when ActiveRecord scopes
7
+
1
8
  # 1.0.3
2
9
 
3
10
  (troessner) Make sure `empty?` works on symbols.
@@ -99,7 +99,9 @@ module Transitions
99
99
  def include_scopes
100
100
  @states.each do |state|
101
101
  state_name = state.name.to_s
102
- raise InvalidMethodOverride if @klass.respond_to?(state_name)
102
+ if @klass.respond_to?(state_name)
103
+ raise InvalidMethodOverride, "Transitions: Can not define scope `#{state_name}` because there is already an equally named method defined - either rename the existing method or the state."
104
+ end
103
105
  @klass.scope state_name, @klass.where(:state => state_name)
104
106
  end
105
107
  end
@@ -67,6 +67,9 @@ module Transitions
67
67
  private
68
68
  def define_state_query_method(machine)
69
69
  method_name, state_name = "#{@name}?", @name # Instance vars are out of scope when calling define_method below, so we use local variables.
70
+ if machine.klass.instance_methods.include?(method_name.to_sym)
71
+ raise InvalidMethodOverride, "Transitions: Can not define method `#{method_name}` because it is already defined - either rename the existing method or the state."
72
+ end
70
73
  machine.klass.send :define_method, method_name do
71
74
  current_state.to_s == state_name.to_s
72
75
  end
@@ -1,3 +1,3 @@
1
1
  module Transitions
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -61,14 +61,14 @@ class TestScopes < Test::Unit::TestCase
61
61
  end
62
62
 
63
63
  test 'scope generation raises an exception if we try to overwrite an existing method' do
64
- assert_raise(Transitions::InvalidMethodOverride) {
65
- class Bear < ActiveRecord::Base
64
+ assert_raise(Transitions::InvalidMethodOverride) do
65
+ Class.new(ActiveRecord::Base) do
66
66
  include ActiveModel::Transitions
67
67
 
68
68
  state_machine :auto_scopes => true do
69
69
  state :new
70
70
  end
71
71
  end
72
- }
72
+ end
73
73
  end
74
74
  end
@@ -17,4 +17,16 @@ class TestStatePredicateMethod < Test::Unit::TestCase
17
17
  assert_true @bus.respond_to?(:parking?)
18
18
  assert_true @bus.send(:parking?)
19
19
  end
20
+
21
+ test 'should raise `InvalidMethodOverride` if we try to overwrite existing methods' do
22
+ assert_raise(Transitions::InvalidMethodOverride) do
23
+ Class.new do
24
+ include Transitions
25
+
26
+ state_machine do
27
+ state :frozen
28
+ end
29
+ end
30
+ end
31
+ end
20
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transitions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-16 00:00:00.000000000 Z
13
+ date: 2012-11-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -179,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  segments:
181
181
  - 0
182
- hash: -465074797
182
+ hash: -392757581
183
183
  required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  none: false
185
185
  requirements: