Sha256: 040f03bbf15c5d5b3d28cf55913c4056ef3c39d22a5f71945b3a94ae4ea77f85

Contents?: true

Size: 1.84 KB

Versions: 6

Compression:

Stored size: 1.84 KB

Contents

class User
  extend ActiveModel::Naming
  include ActiveModel::Conversion

  attr_accessor :id, :name, :description, :created_at, :updated_at

  def initialize(options={})
    @new_record = false
    options.each do |key, value|
      send("#{key}=", value)
    end if options
  end

  def new_record!
    @new_record = true
  end

  def persisted?
    !@new_record
  end
end

class MockController
  attr_writer :action_name

  def _routes
    self
  end

  def action_name
    defined?(@action_name) ? @action_name : "edit"
  end

  def url_for(*args)
    "http://example.com"
  end

  def url_helpers
    self
  end

  def hash_for_user_path(*args); end
  def hash_for_users_path(*args); end
end

class MockResponse

  def initialize(test_case)
    @test_case = test_case
  end

  def content_type
    'text/html'
  end

  def body
    @test_case.send :output_buffer
  end
end

class ActionView::TestCase
  include RailsJQueryAutocomplete::Autocomplete
  include SimpleForm::ActionViewExtensions::FormHelper

  setup :set_controller
  setup :set_response
  setup :setup_new_user

  def assert_no_select(selector, value = nil)
    assert_select(selector, :text => value, :count => 0)
  end

  def with_concat_form_for(*args, &block)
    concat simple_form_for(*args, &block)
  end

  def with_input_for(object, attribute_name, type, options={})
    with_concat_form_for(object) do |f|
      f.input(attribute_name, options.merge(:as => type))
    end
  end

  def set_controller
    @controller = MockController.new
  end

  def set_response
    @response = MockResponse.new(self)
  end

  def setup_new_user
    @user = User.new(
      :id => 1,
      :name => 'New in SimpleForm!',
      :description => 'Hello!',
      :created_at => Time.now
    )
  end

  def protect_against_forgery?
    false
  end

  def user_path(*args)
    '/users'
  end
  alias :users_path :user_path
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rails-jquery-autocomplete-1.0.5 test/view_test_helper.rb
rails-jquery-autocomplete-1.0.4 test/view_test_helper.rb
rails-autocomplete-1.1.0 test/view_test_helper.rb
rails-jquery-autocomplete-1.0.3 test/view_test_helper.rb
rails-jquery-autocomplete-1.0.2 test/view_test_helper.rb
rails-jquery-autocomplete-1.0.1 test/view_test_helper.rb