Skip to content

Instantly share code, notes, and snippets.

@tfausak
Created January 1, 2015 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfausak/72bf689fb1c9ac9bdf65 to your computer and use it in GitHub Desktop.
Save tfausak/72bf689fb1c9ac9bdf65 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'active_interaction' # 1.4.1
require 'active_record' # 4.2.0
require 'sqlite3' # 1.3.10
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :cars
create_table :wheels do |table|
table.column :car_id, :integer
end
end
class Car < ActiveRecord::Base
has_many :wheels
end
class Wheel < ActiveRecord::Base
belongs_to :car
end
class CountWheels < ActiveInteraction::Base
array :wheels
def execute
wheels.size
end
end
car = Car.create!
car.wheels.create!
inputs = { wheels: car.wheels }
inputs[:wheels].class
# => Wheel::ActiveRecord_Associations_CollectionProxy
CountWheels.run!(inputs)
# => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment