Вот код rspec для создания в контроллере:
describe "'create' successful" do
before(:each) do
@customer = mock_model(Customer)
@customer.stub(:save).and_return(true)
session[:sales] = true
session[:user_id] = 1
session[:user_name] = "sales.name"
session[:page_step] = 1
session['page1'] = customers_path
end
it "should create one customer record" do
lambda do
put 'create', @customer
end.should change(Customer, :count).by(1)
end
it "should redirect to customers path" do
put 'create', @customer
flash[:notice].should_not be_nil
response.should redirect_to(customers_path)
end
end
Вот код создания в контроллере:
def create
if session[:sales]
@customer = Customer.new(params[:customer], :as => :roles_new_update)
@customer.sales_id = session[:user_id]
if @customer.save
@message = "New customer #{params[:name]} was created. Please check it out"
@subject = "New customer #{params[:name]} was created BY {#session[:user_name]}"
UserMailer.notify_tl_dh_ch_ceo(@message, @subject, session[:user_id])
redirect_to session[('page' + session[:page_step].to_s).to_sym], :notice => 'Customer was created successfaully!'
else
render 'new', :notice => 'Customer was not saved!'
end
end
end
Вот ошибка в rspec:
1) CustomersController GET customer page 'create' successful should create one customer record
Failure/Error: put 'create', @customer
NoMethodError:
undefined method `symbolize_keys' for "1001":String
# ./spec/controllers/customers_controller_spec.rb:40:in `block (5 levels) in <top (required)>'
# ./spec/controllers/customers_controller_spec.rb:39:in `block (4 levels) in <top (required)>'
2) CustomersController GET customer page 'create' successful should redirect to customers path
Failure/Error: put 'create', @customer
NoMethodError:
undefined method `symbolize_keys' for "1002":String
# ./spec/controllers/customers_controller_spec.rb:45:i
Проблема связана с насмешливыми данными @customer.Что не так с насмешкой в спец?
Спасибо.