Мой features
файл выглядит так:
Given there are the following users:
| email | password | admin |
| admin@ticketee.com | password | true |
И моя user
модель не объявляет атрибут admin как attr_accessible
для предотвращения массового назначения.Соответственно, я внес изменения в файл user_steps.rb
для решения этой проблемы.
Given /^there are the following users:$/ do |table|
table.hashes.each do |attributes|
unconfirmed = attributes.delete("unconfirmed") == "true"
@user = User.create!(attributes)
@user.update_attribute("admin", attributes["admin"] == "true")
@user.confirm! unless unconfirmed
end
end
Теперь это должно работать в соответствии с книгой - Rails3 в действии.Я также проверил код на их онлайн-репо .Запуск этого с огурцом дает следующую ошибку:
Can't mass-assign protected attributes: admin (ActiveModel::MassAssignmentSecurity::Error)
./features/step_definitions/user_steps.rb:4:in `block (2 levels) in <top (required)>'
./features/step_definitions/user_steps.rb:2:in `each'
./features/step_definitions/user_steps.rb:2:in `/^there are the following users:$/'
features/creating_projects.feature:7:in `Given there are the following users:'
Любая помощь будет принята с благодарностью.Я действительно не могу понять, что здесь не так.
Большое спасибо!