benzelano / test_lh_import

1 stars 0 forks source link

State event translation missing #67

Closed benzelano closed 13 years ago

benzelano commented 13 years ago

Morgan Christiansson opened this issue

I get the following validation error: ActiveRecord::RecordInvalid: Validation failed: State event translation missing: en, activerecord, errors, models, my_model, attributes, state_event, invalid_event

So the default message isn’t loading..

This is what I was expecting: StateMachine::InvalidTransition: Cannot transition state via :acknowledge from :resolved

This behaviour was introduced by this commit in event_collection.rb

Where

machine.invalidate(object, :state, :invalid_transition, [[:event, name]])

was changed to

machine.invalidate(object, :state, :invalid_transition, [[:event, human_name(object.class)]])

Thanks for a great gem! :-)

original LH ticket

This ticket has 0 attachment(s).

benzelano commented 13 years ago

Morgan Christiansson commented

It’s strange though. I thought adding the following in test/unit/integrations/active_record_test.rb

record = @model.new(:state => ’idling’)

machine.invalidate(record, :event, :invalid_event, [[:state, machine.states.match!(record).human_name(record.class)]])
assert_equal [’State cannot transition when ignite’], record.errors.full_messages

would reproduce it. But it does not.

Running Rails 2.3.10

benzelano commented 13 years ago

Hey Morgan -

My only possible explanation there is that perhaps there is another library you’re using that is modifying I18n.load_path in an unexpected manner. Even when I18n.reload! is called, all of the necessary files for state_machine should be in the load_path and get used. I’ve been unable to reproduce this locally.

If you can provide a reproducible test case in state_machine, please feel free to reopen this bug.

benzelano commented 13 years ago

Re-opening as I was able to reproduce this in the test environment.

benzelano commented 13 years ago

(from [105c9039f8be713dfbf52c62df3f839f4d439ee6]) Fix translations not being available under certain environments in Rails applications [#67 state:resolved] https://github.com/pluginaweek/state_machine/commit/105c9039f8be713dfbf52c62df3f839f4d439ee6

benzelano commented 13 years ago

Morgan Christiansson commented

Hi Aaron, using your advice on I18n I added I18n.reload! to our test and spec_helpers and the validation messages started working.

If you managed to fix it so it works without it that’s great!

Thanks, Morgan