Question

I have a functional test in Rails (it's a Redmine plugin) which is causing me problems:

fixtures :settings

test 'error is shown on issues#show when issue custom field is not set up' do
  setting = settings(:release_notes)
  setting.value = setting.value.
    update('issue_required_field_id' => 'garbage')
  #setting.save!

  get :show, :id => '1'

  assert_response :success
  assert_select 'div.flash.error',
    :text => I18n.t(:failed_find_issue_custom_field)
end

The Setting model has fields name and value; in this particular setting, the value is a hash which is serialised. One of the keys in this hash is issue_required_field_id, which is used to find a particular IssueCustomField during the show action. If there is no custom field with this ID (which there shouldn't be, because I've set it to the string 'garbage') then it should render a div.flash.error explaining what's happened.

Unfortunately when setting.save! is commented out, the test fails because the Setting doesn't appear to have been updated -- the working value for that setting (as appears in settings.yml) is used, and the 'div.flash.error' doesn't appear. If I uncomment it, this test passes, but others fail because the change isn't rolled back at the end of the test.

Is there a way of modifying a fixture like this so that any changes are rolled back at the end of the test?

Note: self.use_transactional_fixtures is definitely set to true in ActiveSupport::TestCase (and this test case is an ActionController::TestCase, which is a subclass)

Was it helpful?

Solution

I worked out what was going on -- the test was actually behaving transactionally, but Redmine's Setting class has its own cache. Adding Setting.clear_cache! to the test's setup fixed it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top