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

Event localizer improvement #723

Merged
merged 2 commits into from Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/aasm/core/event.rb
Expand Up @@ -110,6 +110,10 @@ def failed_callbacks
transitions.flat_map(&:failures)
end

def to_s
name.to_s
end

private

def attach_event_guards(definitions)
Expand Down
48 changes: 40 additions & 8 deletions spec/unit/localizer_spec.rb
Expand Up @@ -29,12 +29,28 @@
end

context 'aasm.human_event_name' do
it 'should return translated event name' do
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
context 'with event name' do
it 'should return translated event name' do
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
end

it 'should return humanized event name' do
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
end
end

it 'should return humanized event name' do
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
context 'with event object' do
it 'should return translated event name' do
event = LocalizerTestModel.aasm.events.detect { |e| e.name == :close }

expect(LocalizerTestModel.aasm.human_event_name(event)).to eq("Let's close it!")
end

it 'should return humanized event name' do
event = LocalizerTestModel.aasm.events.detect { |e| e.name == :open }

expect(LocalizerTestModel.aasm.human_event_name(event)).to eq("Open")
end
end
end
end
Expand Down Expand Up @@ -65,12 +81,28 @@
end

context 'aasm.human_event_name' do
it 'should return translated event name' do
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
context 'with event name' do
it 'should return translated event name' do
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
end

it 'should return humanized event name' do
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
end
end

it 'should return humanized event name' do
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
context 'with event object' do
it 'should return translated event name' do
event = LocalizerTestModel.aasm.events.detect { |e| e.name == :close }

expect(LocalizerTestModel.aasm.human_event_name(event)).to eq("Let's close it!")
end

it 'should return humanized event name' do
event = LocalizerTestModel.aasm.events.detect { |e| e.name == :open }

expect(LocalizerTestModel.aasm.human_event_name(event)).to eq("Open")
end
end
end
end
Expand Down