Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow actions to be forked for testing #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/grand_central/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def self.with_attributes *attributes, &body
instance_variable_set "@#{attribute}", args[index]
end
end
define_singleton_method :fork do
with_attributes *attributes, &body
end

klass.send :attr_reader, *attributes
klass.class_exec &body if block_given?

Expand Down
12 changes: 12 additions & 0 deletions spec/grand_central/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,17 @@ def promise.always &block

expect(store.state).to eq [1, 2, 3]
end

it 'can be forked into a new action with the same attributes' do
klass = Action.with_attributes(:foo, :bar)
forked = klass.fork

expect(forked).not_to be klass
expect(forked.superclass).to be klass

action = forked.new(1, 2)
expect(action.foo).to eq 1
expect(action.bar).to eq 2
end
end
end