Railsアプリケーション、特にコントローラーでテストしたいと思います。コードは次のとおりです
customer_controller_test.rb
require 'test_helper'
class CustomersControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@user = FactoryGirl.create(:user)
@role = FactoryGirl.create(:role)
#puts @role.name
@permission = FactoryGirl.create(:permission)
#puts @permission.name
@role_permission = FactoryGirl.create(:role_permission)
#puts @role_permission.role_id
#puts @role_permission.permission_id
sign_in @user
@customer = FactoryGirl.create(:customer)
end
test "should get index" do
get :index
assert_response :success
assert_template 'index'
assert_not_nil assigns(:customers)
end
test "should show article" do
get :show, :id => @customer.to_param
assert_response :success
assert_template 'show'
assert_not_nil assigns(:customer)
assert assigns(:customer).valid?
end
test "should get new" do
#login_as(@user)
get :new
assert_response :success
end
end
factory.rb <-- factorygirl でフィクスチャをセットアップします
FactoryGirl.define do
sequence :email do |n| "admin@admin.admin#{n}" end
sequence :role_name do |n| n end
sequence :role_id do |n| n end
sequence :permission_id do |n| n end
factory :user do |u|
u.name "Admin"
u.role_id {1}
u.email do FactoryGirl.generate(:email) end
u.password "123456"
u.after(:create) do |user|
user.creator_id {1}
user.save
end
end
factory :customer do
name "Test customer-name"
code "Test customer-code"
address "Test customer-address"
phone "Test customer phone"
end
factory :permission do
name "Customer"
end
factory :role do
name do FactoryGirl.generate(:role_name) end
end
end
そして、私はエラーが発生しました
何か案が?前にThx