Commit d17f3bf9 by vulehuan

rspec: product - using FactoryGirl

parent 0810358a
FactoryGirl.define do
factory :user do
# name "Michael Hartl"
# email "michael@example.com"
sequence(:name) { |n| "Person #{n}" }
sequence(:email) { |n| "person_#{n}@example.com"}
password "foobar"
......@@ -11,6 +9,29 @@ FactoryGirl.define do
admin true
end
end
factory :product_category do
sequence(:name) { |n| "Category #{n}" }
end
factory :product do
sequence(:name) { |n| "Product name #{n}" }
sequence(:description) { |n| "Description #{n}" }
headline "foobar"
availability "instock"
code 'Code'
condition 'Condition'
image_small ''
image_medium 'Image Path'
review_rate 0
review_count 0
price_currency 'USD'
price 0
product_category_id 0
user_id 0
status true
end
end
def sign_in(user, options={})
......
......@@ -15,32 +15,9 @@ describe "Products Page" do
describe "pagination" do
before(:all) {
@product_category = ProductCategory.new(
name: "Product category name"
)
@product_category.save
@user = User.new(name: "Example User", email: "user_product_test@example.com", password: "foobar", password_confirmation: "foobar")
@user.save
99.times do |n|
@product = Product.new(
name: "Example #{n} User",
description: "user@example.com",
headline: "foobar",
availability: "instock",
code: 'Code',
condition: 'Condition',
image_small: '',
image_medium: 'Image Path',
review_rate: 0,
review_count: 0,
price_currency: 'USD',
price: 0,
product_category_id: @product_category.id,
user_id: @user.id,
status: true
)
@product.save
end
@product_category = FactoryGirl.create(:product_category)
@user = FactoryGirl.create(:user)
99.times { FactoryGirl.create(:product, product_category_id: @product_category.id, user_id: @user.id) }
}
after(:all) do
Product.delete_all
......@@ -63,10 +40,7 @@ describe "Products Page" do
describe "category page" do
describe "with valid category id" do
before do
@product_category = ProductCategory.new(
name: "Product category name"
)
@product_category.save
@product_category = FactoryGirl.create(:product_category)
visit product_category_path(@product_category)
end
......@@ -98,30 +72,9 @@ describe "Products Page" do
describe "with valid product id" do
before do
@product_category = ProductCategory.new(
name: "Product category name"
)
@product_category.save
@user = User.new(name: "Example User", email: "user_product_test@example.com", password: "foobar", password_confirmation: "foobar")
@user.save
@product = Product.new(
name: "Example User",
description: "user@example.com",
headline: "foobar",
availability: "instock",
code: 'Code',
condition: 'Condition',
image_small: '',
image_medium: 'Image Path',
review_rate: 0,
review_count: 0,
price_currency: 'USD',
price: 0,
product_category_id: @product_category.id,
user_id: @user.id,
status: 1
)
@product.save
@product_category = FactoryGirl.create(:product_category)
@user = FactoryGirl.create(:user)
@product = FactoryGirl.create(:product, product_category_id: @product_category.id, user_id: @user.id)
visit product_path(@product)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment