Sha256: 2d0b2b7cfa49556c1a146218cee4805fd786b4841d390ff01c303a7b70786c76

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'test_helper'

require 'smarter_listing'

class ListingsControllerTest < ActionController::TestCase
  setup do
    @listing = listings(:one)
    ListingsController.smarter_listing
  end

  test 'correct layout' do
    get :index
    assert_template 'default'
  end

  test 'should have the methods from all helpers' do
    assert_includes @controller.methods, :create
    assert_includes @controller.methods, :show
    assert_includes @controller.methods, :update
    assert_includes @controller.methods, :destroy
    assert_includes @controller.methods, :new
  end

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:listings)
  end

  test "should get new" do
    xhr :get, :new, format: :js
    assert_response :success
  end

  test "should create listing" do
    assert_difference('Listing.count') do
      resource_params = {content: @listing.content, deleted_at: @listing.deleted_at, name: 'newName'}
      xhr :post, :create, listing: resource_params, format: :js
      assert_empty @listing.errors
    end
    assert_response :success
  end

  test "should get edit" do
    xhr :get, :edit, id: @listing, format: :js
    assert_response :success
  end

  test "should update listing" do
    resource_params = {content: @listing.content, deleted_at: @listing.deleted_at, name: 'newName'}
    xhr :patch, :update, id: @listing, listing: resource_params, format: :js
    assert_empty @listing.errors
    assert_response :success
  end

  test "should destroy listing" do
    assert_difference('Listing.count', -1) do
      xhr :delete, :destroy, id: @listing, format: :js
    end
    assert_response :success
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smarter_listing-0.1.2 test/controllers/listings_controller_test.rb