state_machines-activerecord 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a08515c6e6c44049b7473b3140fd0e96f3eb3d8
4
- data.tar.gz: 1722de2ecf4eb65aee81221d5725c49bcac361ec
3
+ metadata.gz: 83184c4ea1136843d9a2b5a6638ffe4af34502d5
4
+ data.tar.gz: d5c732fd76e6a9bd4f96cf391fa360f5d526bc24
5
5
  SHA512:
6
- metadata.gz: 43826d053ae3d06a3c2fa966245b70e6a56e71223567f7e4f1f622136016cbb24da5bae787c20f07d87f85645a8fcdad37bde872ae7778a334e38298fa87465e
7
- data.tar.gz: a5cee9e813ce7adebed5027b0b68ba64be155f54db35df8943282556cab82d9fa89c467bdf0109879e8a3ea0bc8844532b9e8e86e73ed3377b7c58c2d5a277d5
6
+ metadata.gz: 844e338a3c7c50cad3c3c6de08944cb9b81d7bcb6a81d6428c597feb09c09141f6a3d983cbcae804f89133b65bd87348ece794ca585e61dca9818cd34210a023
7
+ data.tar.gz: b9c56c10217e4d74b667ad1a4e56bec12635f921e8fa908b41da0922ae8f7810c371864c47aec04443e82c483bf5a4dc4c0cb1e69f17d6be868f089f14435246
data/.travis.yml CHANGED
@@ -5,7 +5,6 @@ cache: bundler
5
5
  rvm:
6
6
  - 2.1
7
7
  - 2.2
8
- - jruby-19mode
9
8
  - jruby
10
9
  - rbx-2
11
10
 
@@ -16,5 +15,4 @@ gemfile:
16
15
  matrix:
17
16
  allow_failures:
18
17
  - rvm: jruby
19
- - rvm: jruby-19mode
20
- - rvm: rbx-2
18
+ - rvm: rbx-2
@@ -447,47 +447,41 @@ module StateMachines
447
447
  end
448
448
  end
449
449
 
450
- # Defines an initialization hook into the owner class for setting the
451
- # initial state of the machine *before* any attributes are set on the
452
- # object
453
450
  def define_state_initializer
454
- define_static_state_initializer
455
- define_dynamic_state_initializer
456
- end
457
-
458
- # Initializes static states
459
- def define_static_state_initializer
460
- # This is the only available hook where the default set of attributes
461
- # can be overridden for a new object *prior* to the processing of the
462
- # attributes passed into #initialize
463
- define_helper :class, <<-end_eval, __FILE__, __LINE__ + 1
464
- if ActiveRecord.gem_version >= Gem::Version.new('4.2')
465
- def _default_attributes #:nodoc:
466
- result = super
467
- self.state_machines.initialize_states(nil, :static => :force, :dynamic => false, :to => result)
468
- result
469
- end
470
- else
471
- def column_defaults(*) #:nodoc:
451
+ if ::ActiveRecord.gem_version >= Gem::Version.new('4.2')
452
+ define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
453
+ def initialize(attributes = nil, options = {})
454
+ super(attributes, options) do |*args|
455
+ self.class.state_machines.initialize_states(self, {}, attributes || {})
456
+ yield(*args) if block_given?
457
+ end
458
+ end
459
+ end_eval
460
+ else
461
+ # Initializes static states
462
+ #
463
+ # This is the only available hook where the default set of attributes
464
+ # can be overridden for a new object *prior* to the processing of the
465
+ # attributes passed into #initialize
466
+ define_helper :class, <<-end_eval, __FILE__, __LINE__ + 1
467
+ def column_defaults(*) #:nodoc:
472
468
  result = super
473
469
  # No need to pass in an object, since the overrides will be forced
474
470
  self.state_machines.initialize_states(nil, :static => :force, :dynamic => false, :to => result)
475
471
  result
476
- end
477
- end
478
- end_eval
479
- end
472
+ end
473
+ end_eval
480
474
 
481
- # Initializes dynamic states
482
- def define_dynamic_state_initializer
483
- define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
484
- def initialize(*)
485
- super do |*args|
486
- self.class.state_machines.initialize_states(self)
475
+ # Initializes dynamic states
476
+ define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
477
+ def initialize(attributes = nil, options = {})
478
+ super(attributes, options) do |*args|
479
+ self.class.state_machines.initialize_states(self, {}, attributes || {})
487
480
  yield(*args) if block_given?
488
481
  end
489
482
  end
490
- end_eval
483
+ end_eval
484
+ end
491
485
  end
492
486
 
493
487
  # Uses around callbacks to run state events if using the :save hook
@@ -566,23 +560,4 @@ module StateMachines
566
560
  end
567
561
  end
568
562
  end
569
- class Machine
570
- # FIXME
571
- def initialize_state(object, options = {})
572
- state = initial_state(object)
573
- if state && (options[:force] || initialize_state?(object))
574
- value = state.value
575
-
576
- if hash = options[:to]
577
- if hash.is_a?(Hash)
578
- hash[attribute.to_s] = value
579
- else # in ActiveRecord 4.2 hash is an Activerecord::AttributeSet
580
- hash.write_from_user(attribute.to_s, value)
581
- end
582
- else
583
- write(object, :state, value)
584
- end
585
- end
586
- end
587
- end
588
563
  end
@@ -1,7 +1,7 @@
1
1
  module StateMachines
2
2
  module Integrations
3
3
  module ActiveRecord
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
5
5
  end
6
6
  end
7
7
  end
@@ -5,6 +5,12 @@ class IntegrationTest < BaseTestCase
5
5
  assert_equal :active_record, StateMachines::Integrations::ActiveRecord.integration_name
6
6
  end
7
7
 
8
+ def test_should_be_before_activemodel
9
+ integrations = StateMachines::Integrations.list.to_a
10
+ assert StateMachines::Integrations::ActiveRecord, integrations.first
11
+ assert StateMachines::Integrations::ActiveModel, integrations.last
12
+ end
13
+
8
14
  def test_should_match_if_class_inherits_from_active_record
9
15
  assert StateMachines::Integrations::ActiveRecord.matches?(new_model)
10
16
  end
@@ -3,13 +3,7 @@ require_relative 'test_helper'
3
3
  class MachineWithNonColumnStateAttributeDefinedTest < BaseTestCase
4
4
  def setup
5
5
  @model = new_model do
6
- def status=(value)
7
- self['status'] = value
8
- end
9
-
10
- def status
11
- self['status']
12
- end
6
+ attr_accessor :status
13
7
  end
14
8
 
15
9
  @machine = StateMachines::Machine.new(@model, :status, :initial => :parked)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machines-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-17 00:00:00.000000000 Z
12
+ date: 2015-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: state_machines-activemodel
@@ -169,7 +169,6 @@ files:
169
169
  - test/machine_with_internationalization_test.rb
170
170
  - test/machine_with_loopback_test.rb
171
171
  - test/machine_with_non_column_state_attribute_defined_test.rb
172
- - test/machine_with_non_column_state_attribute_undefined_test.rb
173
172
  - test/machine_with_same_column_default_test.rb
174
173
  - test/machine_with_scopes_and_joins_test.rb
175
174
  - test/machine_with_scopes_and_owner_subclass_test.rb
@@ -204,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
203
  version: '0'
205
204
  requirements: []
206
205
  rubyforge_project:
207
- rubygems_version: 2.2.2
206
+ rubygems_version: 2.4.5
208
207
  signing_key:
209
208
  specification_version: 4
210
209
  summary: State machines Active Record Integration
@@ -246,7 +245,6 @@ test_files:
246
245
  - test/machine_with_internationalization_test.rb
247
246
  - test/machine_with_loopback_test.rb
248
247
  - test/machine_with_non_column_state_attribute_defined_test.rb
249
- - test/machine_with_non_column_state_attribute_undefined_test.rb
250
248
  - test/machine_with_same_column_default_test.rb
251
249
  - test/machine_with_scopes_and_joins_test.rb
252
250
  - test/machine_with_scopes_and_owner_subclass_test.rb
@@ -1,33 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class MachineWithNonColumnStateAttributeUndefinedTest < BaseTestCase
4
- def setup
5
- @model = new_model do
6
- def initialize
7
- # Skip attribute initialization
8
- @initialized_state_machines = true
9
- super
10
- end
11
- end
12
-
13
- @machine = StateMachines::Machine.new(@model, :status, :initial => :parked)
14
- @machine.other_states(:idling)
15
- @record = @model.new
16
- end
17
-
18
- def test_should_not_define_a_column_for_the_attribute
19
- assert_nil @model.columns_hash['status']
20
- end
21
-
22
- def test_should_define_a_reader_attribute_for_the_attribute
23
- assert @record.respond_to?(:status)
24
- end
25
-
26
- def test_should_define_a_writer_attribute_for_the_attribute
27
- assert @record.respond_to?(:status=)
28
- end
29
-
30
- def test_should_define_an_attribute_predicate
31
- assert @record.respond_to?(:status?)
32
- end
33
- end