chillout 0.8.7 → 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -0
  3. data/CHANGELOG.md +5 -0
  4. data/lib/chillout.rb +1 -0
  5. data/lib/chillout/integrations/state_machine.rb +90 -0
  6. data/lib/chillout/railtie.rb +15 -1
  7. data/lib/chillout/version.rb +1 -1
  8. data/test/acceptance/client_sends_state_machine_metrics_test.rb +45 -0
  9. data/test/support/rails_4_0_0/Gemfile +1 -0
  10. data/test/support/rails_4_0_0/app/controllers/entities_controller.rb +1 -1
  11. data/test/support/rails_4_0_0/app/controllers/transitions_controller.rb +8 -0
  12. data/test/support/rails_4_0_0/app/models/entity.rb +35 -1
  13. data/test/support/rails_4_0_0/config/routes.rb +1 -0
  14. data/test/support/rails_4_0_0/db/schema.rb +2 -0
  15. data/test/support/rails_4_0_13/Gemfile +1 -0
  16. data/test/support/rails_4_0_13/app/controllers/entities_controller.rb +1 -1
  17. data/test/support/rails_4_0_13/app/controllers/transitions_controller.rb +8 -0
  18. data/test/support/rails_4_0_13/app/models/entity.rb +35 -1
  19. data/test/support/rails_4_0_13/config/routes.rb +1 -0
  20. data/test/support/rails_4_0_13/db/schema.rb +2 -0
  21. data/test/support/rails_4_1_0/Gemfile +1 -0
  22. data/test/support/rails_4_1_0/app/controllers/entities_controller.rb +1 -1
  23. data/test/support/rails_4_1_0/app/controllers/transitions_controller.rb +8 -0
  24. data/test/support/rails_4_1_0/app/models/entity.rb +35 -1
  25. data/test/support/rails_4_1_0/config/initializers/state_machine_integration_hack.rb +3 -0
  26. data/test/support/rails_4_1_0/config/routes.rb +1 -0
  27. data/test/support/rails_4_1_0/db/schema.rb +2 -0
  28. data/test/support/rails_4_1_16/Gemfile +2 -1
  29. data/test/support/rails_4_1_16/app/controllers/entities_controller.rb +1 -1
  30. data/test/support/rails_4_1_16/app/controllers/transitions_controller.rb +8 -0
  31. data/test/support/rails_4_1_16/app/jobs/create_entity_job.rb +1 -1
  32. data/test/support/rails_4_1_16/app/models/entity.rb +35 -1
  33. data/test/support/rails_4_1_16/config/initializers/state_machine_integration_hack.rb +3 -0
  34. data/test/support/rails_4_1_16/config/routes.rb +1 -0
  35. data/test/support/rails_4_1_16/db/schema.rb +2 -0
  36. data/test/support/rails_4_2_0/Gemfile +2 -1
  37. data/test/support/rails_4_2_0/app/controllers/entities_controller.rb +1 -1
  38. data/test/support/rails_4_2_0/app/controllers/transitions_controller.rb +8 -0
  39. data/test/support/rails_4_2_0/app/jobs/create_entity_job.rb +1 -1
  40. data/test/support/rails_4_2_0/app/models/entity.rb +35 -1
  41. data/test/support/rails_4_2_0/config/initializers/state_machine_integration_hack.rb +3 -0
  42. data/test/support/rails_4_2_0/config/routes.rb +1 -0
  43. data/test/support/rails_4_2_0/db/schema.rb +2 -0
  44. data/test/support/rails_4_2_8/Gemfile +7 -1
  45. data/test/support/rails_4_2_8/app/controllers/entities_controller.rb +1 -1
  46. data/test/support/rails_4_2_8/app/controllers/transitions_controller.rb +8 -0
  47. data/test/support/rails_4_2_8/app/jobs/create_entity_job.rb +1 -1
  48. data/test/support/rails_4_2_8/app/models/entity.rb +35 -1
  49. data/test/support/rails_4_2_8/config/initializers/state_machine_integration_hack.rb +3 -0
  50. data/test/support/rails_4_2_8/config/routes.rb +1 -0
  51. data/test/support/rails_4_2_8/db/schema.rb +2 -0
  52. data/test/support/rails_5_0_3/Gemfile +7 -1
  53. data/test/support/rails_5_0_3/app/controllers/entities_controller.rb +1 -1
  54. data/test/support/rails_5_0_3/app/controllers/transitions_controller.rb +8 -0
  55. data/test/support/rails_5_0_3/app/jobs/create_entity_job.rb +1 -1
  56. data/test/support/rails_5_0_3/app/models/entity.rb +35 -1
  57. data/test/support/rails_5_0_3/config/initializers/state_machine_integration_hack.rb +3 -0
  58. data/test/support/rails_5_0_3/config/routes.rb +1 -0
  59. data/test/support/rails_5_0_3/db/schema.rb +2 -0
  60. data/test/support/rails_5_1_1/Gemfile +6 -0
  61. data/test/support/rails_5_1_1/app/controllers/entities_controller.rb +1 -1
  62. data/test/support/rails_5_1_1/app/controllers/transitions_controller.rb +8 -0
  63. data/test/support/rails_5_1_1/app/jobs/create_entity_job.rb +1 -1
  64. data/test/support/rails_5_1_1/app/models/application_record.rb +3 -0
  65. data/test/support/rails_5_1_1/app/models/entity.rb +35 -1
  66. data/test/support/rails_5_1_1/app/models/user.rb +2 -0
  67. data/test/support/rails_5_1_1/config/routes.rb +2 -1
  68. data/test/support/rails_5_1_1/db/schema.rb +2 -0
  69. data/test/test_helper.rb +19 -3
  70. metadata +36 -3
@@ -0,0 +1,3 @@
1
+ module StateMachine::Integrations::ActiveModel
2
+ public :around_validation
3
+ end if defined?(StateMachine)
@@ -1,4 +1,5 @@
1
1
  Rails400::Application.routes.draw do
2
2
  resources :entities
3
3
  resources :purchases, only: %i(create)
4
+ resources :transitions, only: %i(create)
4
5
  end
@@ -15,6 +15,8 @@ ActiveRecord::Schema.define(:version => 20130103115400) do
15
15
 
16
16
  create_table "entities", :force => true do |t|
17
17
  t.string "name"
18
+ t.string "state"
19
+ t.string "seatbelt"
18
20
  t.datetime "created_at", :null => false
19
21
  t.datetime "updated_at", :null => false
20
22
  end
@@ -7,4 +7,5 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')
7
7
  gem "sidekiq", ENV['SIDEKIQ_VERSION'] || "~> 4.2"
8
8
  else
9
9
  gem "sidekiq", ENV['SIDEKIQ_VERSION'] || ">= 5"
10
- end
10
+ end
11
+ gem "state_machine", ENV['STATE_MACHINE_VERSION'] || ">= 1.2"
@@ -31,7 +31,7 @@ class EntitiesController < ApplicationController
31
31
  end
32
32
 
33
33
  def create
34
- @entity = Entity.new(params.require(:entity).permit!)
34
+ @entity = Entity.new(params.require(:entity).permit!.merge(state: "parked"))
35
35
 
36
36
  respond_to do |format|
37
37
  if @entity.save
@@ -0,0 +1,8 @@
1
+ class TransitionsController < ApplicationController
2
+ def create
3
+ e = Entity.new(state: "parked")
4
+ e.ignite
5
+ e.shift_up
6
+ head :ok
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
1
  class CreateEntityJob
2
2
  include Sidekiq::Worker
3
3
  def perform
4
- Entity.create!(name: Time.current.to_s)
4
+ Entity.create!(name: Time.current.to_s, state: "parked")
5
5
  end
6
6
  end
@@ -1,2 +1,36 @@
1
1
  class Entity < ActiveRecord::Base
2
- end
2
+ state_machine :initial => :parked do
3
+ before_transition :parked => any - :parked, do: :put_on_seatbelt
4
+ after_transition any => :parked do |vehicle, _transition|
5
+ vehicle.seatbelt = 'off'
6
+ end
7
+ around_transition :benchmark
8
+
9
+ event :ignite do
10
+ transition :parked => :idling
11
+ end
12
+
13
+ event :shift_up do
14
+ transition :idling => :first_gear,
15
+ :first_gear => :second_gear,
16
+ :second_gear => :third_gear
17
+ end
18
+
19
+ state :first_gear, :second_gear do
20
+ validates_presence_of :seatbelt_on
21
+ end
22
+ end
23
+
24
+ def put_on_seatbelt
25
+ sleep(0.1)
26
+ self.seatbelt = 'on'
27
+ end
28
+
29
+ def benchmark
30
+ yield
31
+ end
32
+
33
+ def seatbelt_on
34
+ self.seatbelt == 'on'
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module StateMachine::Integrations::ActiveModel
2
+ public :around_validation
3
+ end if defined?(StateMachine)
@@ -1,4 +1,5 @@
1
1
  Rails400::Application.routes.draw do
2
2
  resources :entities
3
3
  resources :purchases, only: %i(create)
4
+ resources :transitions, only: %i(create)
4
5
  end
@@ -15,6 +15,8 @@ ActiveRecord::Schema.define(:version => 20130103115400) do
15
15
 
16
16
  create_table "entities", :force => true do |t|
17
17
  t.string "name"
18
+ t.string "state"
19
+ t.string "seatbelt"
18
20
  t.datetime "created_at", :null => false
19
21
  t.datetime "updated_at", :null => false
20
22
  end
@@ -7,4 +7,5 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')
7
7
  gem "sidekiq", ENV['SIDEKIQ_VERSION'] || "~> 4.2"
8
8
  else
9
9
  gem "sidekiq", ENV['SIDEKIQ_VERSION'] || ">= 5"
10
- end
10
+ end
11
+ gem "state_machine", ENV['STATE_MACHINE_VERSION'] || ">= 1.2"
@@ -31,7 +31,7 @@ class EntitiesController < ApplicationController
31
31
  end
32
32
 
33
33
  def create
34
- @entity = Entity.new(params.require(:entity).permit!)
34
+ @entity = Entity.new(params.require(:entity).permit!.merge(state: "parked"))
35
35
 
36
36
  respond_to do |format|
37
37
  if @entity.save
@@ -0,0 +1,8 @@
1
+ class TransitionsController < ApplicationController
2
+ def create
3
+ e = Entity.new(state: "parked")
4
+ e.ignite
5
+ e.shift_up
6
+ head :ok
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
1
  class CreateEntityJob
2
2
  include Sidekiq::Worker
3
3
  def perform
4
- Entity.create!(name: Time.current.to_s)
4
+ Entity.create!(name: Time.current.to_s, state: "parked")
5
5
  end
6
6
  end
@@ -1,2 +1,36 @@
1
1
  class Entity < ActiveRecord::Base
2
- end
2
+ state_machine :initial => :parked do
3
+ before_transition :parked => any - :parked, do: :put_on_seatbelt
4
+ after_transition any => :parked do |vehicle, _transition|
5
+ vehicle.seatbelt = 'off'
6
+ end
7
+ around_transition :benchmark
8
+
9
+ event :ignite do
10
+ transition :parked => :idling
11
+ end
12
+
13
+ event :shift_up do
14
+ transition :idling => :first_gear,
15
+ :first_gear => :second_gear,
16
+ :second_gear => :third_gear
17
+ end
18
+
19
+ state :first_gear, :second_gear do
20
+ validates_presence_of :seatbelt_on
21
+ end
22
+ end
23
+
24
+ def put_on_seatbelt
25
+ sleep(0.1)
26
+ self.seatbelt = 'on'
27
+ end
28
+
29
+ def benchmark
30
+ yield
31
+ end
32
+
33
+ def seatbelt_on
34
+ self.seatbelt == 'on'
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module StateMachine::Integrations::ActiveModel
2
+ public :around_validation
3
+ end if defined?(StateMachine)
@@ -1,4 +1,5 @@
1
1
  Rails400::Application.routes.draw do
2
2
  resources :entities
3
3
  resources :purchases, only: %i(create)
4
+ resources :transitions, only: %i(create)
4
5
  end
@@ -15,6 +15,8 @@ ActiveRecord::Schema.define(:version => 20130103115400) do
15
15
 
16
16
  create_table "entities", :force => true do |t|
17
17
  t.string "name"
18
+ t.string "state"
19
+ t.string "seatbelt"
18
20
  t.datetime "created_at", :null => false
19
21
  t.datetime "updated_at", :null => false
20
22
  end
@@ -3,4 +3,10 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '4.2.8'
4
4
  gem 'sqlite3'
5
5
  gem 'chillout', :path => '../../../'
6
- gem "sidekiq", ENV['SIDEKIQ_VERSION'] || ">= 5"
6
+ gem "sidekiq", ENV['SIDEKIQ_VERSION'] || ">= 5"
7
+ if ENV['STATE_MACHINES_ACTIVERECORD_VERSION']
8
+ gem "state_machines-activerecord", ENV['STATE_MACHINES_ACTIVERECORD_VERSION']
9
+ gem "state_machines", ENV['STATE_MACHINES_VERSION'] || ENV['STATE_MACHINES_ACTIVERECORD_VERSION']
10
+ else
11
+ gem "state_machine", ENV['STATE_MACHINE_VERSION'] || ">= 1.2"
12
+ end
@@ -31,7 +31,7 @@ class EntitiesController < ApplicationController
31
31
  end
32
32
 
33
33
  def create
34
- @entity = Entity.new(params.require(:entity).permit!)
34
+ @entity = Entity.new(params.require(:entity).permit!.merge(state: "parked"))
35
35
 
36
36
  respond_to do |format|
37
37
  if @entity.save
@@ -0,0 +1,8 @@
1
+ class TransitionsController < ApplicationController
2
+ def create
3
+ e = Entity.new(state: "parked")
4
+ e.ignite
5
+ e.shift_up
6
+ head :ok
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
1
  class CreateEntityJob
2
2
  include Sidekiq::Worker
3
3
  def perform
4
- Entity.create!(name: Time.current.to_s)
4
+ Entity.create!(name: Time.current.to_s, state: "parked")
5
5
  end
6
6
  end
@@ -1,2 +1,36 @@
1
1
  class Entity < ActiveRecord::Base
2
- end
2
+ state_machine :initial => :parked do
3
+ before_transition :parked => any - :parked, do: :put_on_seatbelt
4
+ after_transition any => :parked do |vehicle, _transition|
5
+ vehicle.seatbelt = 'off'
6
+ end
7
+ around_transition :benchmark
8
+
9
+ event :ignite do
10
+ transition :parked => :idling
11
+ end
12
+
13
+ event :shift_up do
14
+ transition :idling => :first_gear,
15
+ :first_gear => :second_gear,
16
+ :second_gear => :third_gear
17
+ end
18
+
19
+ state :first_gear, :second_gear do
20
+ validates_presence_of :seatbelt_on
21
+ end
22
+ end
23
+
24
+ def put_on_seatbelt
25
+ sleep(0.1)
26
+ self.seatbelt = 'on'
27
+ end
28
+
29
+ def benchmark
30
+ yield
31
+ end
32
+
33
+ def seatbelt_on
34
+ self.seatbelt == 'on'
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module StateMachine::Integrations::ActiveModel
2
+ public :around_validation
3
+ end if defined?(StateMachine)
@@ -1,4 +1,5 @@
1
1
  Rails400::Application.routes.draw do
2
2
  resources :entities
3
3
  resources :purchases, only: %i(create)
4
+ resources :transitions, only: %i(create)
4
5
  end
@@ -15,6 +15,8 @@ ActiveRecord::Schema.define(:version => 20130103115400) do
15
15
 
16
16
  create_table "entities", :force => true do |t|
17
17
  t.string "name"
18
+ t.string "state"
19
+ t.string "seatbelt"
18
20
  t.datetime "created_at", :null => false
19
21
  t.datetime "updated_at", :null => false
20
22
  end
@@ -3,4 +3,10 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '5.0.3'
4
4
  gem 'sqlite3'
5
5
  gem 'chillout', :path => '../../../'
6
- gem "sidekiq", ENV['SIDEKIQ_VERSION'] || ">= 5"
6
+ gem "sidekiq", ENV['SIDEKIQ_VERSION'] || ">= 5"
7
+ if ENV['STATE_MACHINES_ACTIVERECORD_VERSION']
8
+ gem "state_machines-activerecord", ENV['STATE_MACHINES_ACTIVERECORD_VERSION']
9
+ gem "state_machines", ENV['STATE_MACHINES_VERSION'] || ENV['STATE_MACHINES_ACTIVERECORD_VERSION']
10
+ else
11
+ gem "state_machine", ENV['STATE_MACHINE_VERSION'] || ">= 1.2"
12
+ end
@@ -31,7 +31,7 @@ class EntitiesController < ApplicationController
31
31
  end
32
32
 
33
33
  def create
34
- @entity = Entity.new(params.require(:entity).permit!)
34
+ @entity = Entity.new(params.require(:entity).permit!.merge(state: "parked"))
35
35
 
36
36
  respond_to do |format|
37
37
  if @entity.save
@@ -0,0 +1,8 @@
1
+ class TransitionsController < ApplicationController
2
+ def create
3
+ e = Entity.new(state: "parked")
4
+ e.ignite
5
+ e.shift_up
6
+ head :ok
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
1
  class CreateEntityJob
2
2
  include Sidekiq::Worker
3
3
  def perform
4
- Entity.create!(name: Time.current.to_s)
4
+ Entity.create!(name: Time.current.to_s, state: "parked")
5
5
  end
6
6
  end
@@ -1,2 +1,36 @@
1
1
  class Entity < ActiveRecord::Base
2
- end
2
+ state_machine :initial => :parked do
3
+ before_transition :parked => any - :parked, do: :put_on_seatbelt
4
+ after_transition any => :parked do |vehicle, _transition|
5
+ vehicle.seatbelt = 'off'
6
+ end
7
+ around_transition :benchmark
8
+
9
+ event :ignite do
10
+ transition :parked => :idling
11
+ end
12
+
13
+ event :shift_up do
14
+ transition :idling => :first_gear,
15
+ :first_gear => :second_gear,
16
+ :second_gear => :third_gear
17
+ end
18
+
19
+ state :first_gear, :second_gear do
20
+ validates_presence_of :seatbelt_on
21
+ end
22
+ end
23
+
24
+ def put_on_seatbelt
25
+ sleep(0.1)
26
+ self.seatbelt = 'on'
27
+ end
28
+
29
+ def benchmark
30
+ yield
31
+ end
32
+
33
+ def seatbelt_on
34
+ self.seatbelt == 'on'
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module StateMachine::Integrations::ActiveModel
2
+ public :around_validation
3
+ end if defined?(StateMachine)
@@ -1,4 +1,5 @@
1
1
  Rails400::Application.routes.draw do
2
2
  resources :entities
3
3
  resources :purchases, only: %i(create)
4
+ resources :transitions, only: %i(create)
4
5
  end
@@ -15,6 +15,8 @@ ActiveRecord::Schema.define(:version => 20130103115400) do
15
15
 
16
16
  create_table "entities", :force => true do |t|
17
17
  t.string "name"
18
+ t.string "state"
19
+ t.string "seatbelt"
18
20
  t.datetime "created_at", :null => false
19
21
  t.datetime "updated_at", :null => false
20
22
  end
@@ -4,3 +4,9 @@ gem 'rails', '5.1.1'
4
4
  gem 'sqlite3'
5
5
  gem 'chillout', :path => '../../../'
6
6
  gem "sidekiq", ENV['SIDEKIQ_VERSION'] || ">= 5"
7
+ if ENV['STATE_MACHINES_ACTIVERECORD_VERSION']
8
+ gem "state_machines-activerecord", ENV['STATE_MACHINES_ACTIVERECORD_VERSION']
9
+ gem "state_machines", ENV['STATE_MACHINES_VERSION'] || ENV['STATE_MACHINES_ACTIVERECORD_VERSION']
10
+ else
11
+ gem "state_machine", ENV['STATE_MACHINE_VERSION'] || ">= 1.2"
12
+ end
@@ -31,7 +31,7 @@ class EntitiesController < ApplicationController
31
31
  end
32
32
 
33
33
  def create
34
- @entity = Entity.new(params.require(:entity).permit!)
34
+ @entity = Entity.new(params.require(:entity).permit!.merge(state: "parked"))
35
35
 
36
36
  respond_to do |format|
37
37
  if @entity.save
@@ -0,0 +1,8 @@
1
+ class TransitionsController < ApplicationController
2
+ def create
3
+ e = Entity.new(state: "parked")
4
+ e.ignite
5
+ e.shift_up
6
+ head :ok
7
+ end
8
+ end