Тесты Rspec-rails начали проваливаться после добавления Aasm gem .
Все основные настройки сделаны. Миграция с добавлением столбца aasm_state. Добавление состояния в модель заказа.
Журнал испытаний:
Searching book Visitor searches books by title
Failure/Error: order = Order.create
ActionView::Template::Error:
undefined method `aasm_state' for #<Order:0x0000000008e48740>
Did you mean? aasm_state=
Однако в тесте нет Порядка:
require 'spec_helper'
require 'rails_helper'
feature 'Searching book' do
before do
book = Book.create title: "Geralt"
author = Author.create full_name: "Swiss"
category = Category.create title: "Programming"
category.books << book
book.authors << author
author.books << book
visit books_path
end
scenario 'Visitor searches books by title' do
fill_in 'search', with: "Geralt"
click_button('Search')
expect(page).to have_content 'Geralt'
end
end
Возможно, проблема в вспомогательном методе контроллера приложения:
class ApplicationController < ActionController::Base
helper_method :current_order
protect_from_forgery with: :exception
def current_order
if session[:order_id].nil?
order = Order.create
session[:order_id] = order.id
order
else
Order.find(session[:order_id])
end
end
end
Order.rb с аазмом, часть:
include AASM
aasm do
state :in_progress, initial: true
state :processing
state :in_delivery
state :delivered
state :canceled
end
Шаблон:
= form_tag books_path, method: :get do
.form-group.col-sm-2
= text_field_tag :search, params[:search], class: "form-control", id: "search",placeholder: "Search book"
= submit_tag "Search", class: "btn btn-primary"
= render @books
= "Items in cart #{current_order.order_items.count}"