Skip to content

Instantly share code, notes, and snippets.

@oleglukashev
Created April 28, 2015 09:33
Show Gist options
  • Save oleglukashev/e1d8f815b4fa36ac0d36 to your computer and use it in GitHub Desktop.
Save oleglukashev/e1d8f815b4fa36ac0d36 to your computer and use it in GitHub Desktop.
Тесты, пример
require 'spec_helper'
describe CategoriesController do
let!(:category) { create :category }
let!(:not_published_product) { create :product, category: category }
let!(:product) { create :published_product, category: category, published_at: Time.current - 1.month }
let!(:new_selected_product) { create :published_product, category: category, selection: create(:selection) }
let!(:new_product) { create :published_product, category: category, published_without_selection: true }
context "without current_user" do
describe 'GET #index' do
before do
get :index, category_kind: category.kind
end
specify { expect(response).to be_success }
specify { expect(response).to render_template :index }
specify { expect(assigns(:products)).not_to include(not_published_product) }
specify { expect(assigns(:products)).to include(product) }
specify { expect(assigns(:products)).not_to include(new_selected_product) }
specify { expect(assigns(:products)).to include(new_product) }
end
describe 'GET #show' do
before do
get :show, id: category.location
end
specify { expect(response).to be_success }
specify { expect(response).to render_template :index }
specify { expect(assigns(:products)).not_to include(not_published_product) }
specify { expect(assigns(:products)).to include(product) }
specify { expect(assigns(:products)).not_to include(new_selected_product) }
specify { expect(assigns(:products)).to include(new_product) }
end
end
context "with logged in user" do
let!(:user) { create :user }
before do
login_as user
controller.stub(:current_user).and_return user
end
describe 'GET #index' do
before do
get :index, category_kind: category.kind
end
specify { expect(response).to be_success }
specify { expect(response).to render_template :index }
specify { expect(assigns(:products)).not_to include(not_published_product) }
specify { expect(assigns(:products)).to include(product) }
specify { expect(assigns(:products)).to include(new_selected_product) }
specify { expect(assigns(:products)).to include(new_product) }
end
describe 'GET #show' do
before do
get :show, id: category.location
end
specify { expect(response).to be_success }
specify { expect(response).to render_template :index }
specify { expect(assigns(:products)).not_to include(not_published_product) }
specify { expect(assigns(:products)).to include(product) }
specify { expect(assigns(:products)).to include(new_selected_product) }
specify { expect(assigns(:products)).to include(new_product) }
end
end
context "set sizes" do
let!(:user) { create :user }
before do
login_as user
controller.stub(:current_user).and_return user
end
let!(:cloth) { create :product_modification, product: product, size: 'M' }
describe 'GET #index' do
before do
get :index, category_kind: category.kind, footwear_size: '38', clothes_size: 'M'
end
specify { expect(response).to be_success }
specify { expect(response).to render_template :index }
specify { expect(assigns(:products)).not_to include(not_published_product) }
specify { expect(assigns(:products)).to include(product) }
specify { expect(assigns(:products)).not_to include(new_selected_product) }
specify { expect(assigns(:products)).not_to include(new_product) }
end
describe 'GET #show' do
before do
get :show, id: category.location, footwear_size: '38', clothes_size: 'M'
end
specify { expect(response).to be_success }
specify { expect(response).to render_template :index }
specify { expect(assigns(:products)).not_to include(not_published_product) }
specify { expect(assigns(:products)).to include(product) }
specify { expect(assigns(:products)).not_to include(new_selected_product) }
specify { expect(assigns(:products)).not_to include(new_product) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment