Sha256: 464b974efc7fd56f9927d50567112a67486c701c534a7486dd200b967281a0fc

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
  
  fixtures :all
  include ActionDispatch::TestProcess
  
  def setup
    reset_config
  end
  
  # resetting default configuration
  def reset_config
    SofaGallery.configure do |config|
      config.admin_route_prefix = 'admin'
      config.upload_options     = { }
      config.admin_controller   = 'ApplicationController'
      config.form_builder       = 'SofaGallery::FormBuilder'
    end
  end
  
  # Example usage:
  #   assert_has_errors_on( @record, [:field_1, :field_2] )
  #   assert_has_errors_on( @record, {:field_1 => 'Message1', :field_2 => 'Message 2'} )
  def assert_has_errors_on(record, fields)
    fields = [fields].flatten unless fields.is_a?(Hash)
    fields.each do |field, message|
      assert record.errors.to_hash.has_key?(field.to_sym), "#{record.class.name} should error on invalid #{field}"
      if message && record.errors[field].is_a?(Array) && !message.is_a?(Array)
        assert_not_nil record.errors[field].index(message)
      elsif message
        assert_equal message, record.errors[field]
      end
    end
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sofa_gallery-0.0.6 test/test_helper.rb
sofa_gallery-0.0.5 test/test_helper.rb
sofa_gallery-0.0.4 test/test_helper.rb
sofa_gallery-0.0.3 test/test_helper.rb
sofa_gallery-0.0.2 test/test_helper.rb
sofa_gallery-0.0.1 test/test_helper.rb