please help solve the problem. i have associated models:
class Album < ActiveRecord::Base
validates :title, presence: true, length: { maximum: 50, minimum: 3 }, uniqueness: { case_sensitive: false }
validates :description, presence: true, length: { maximum: 600, minimum: 10 }
belongs_to :user
has_many :images
end
class Status < ActiveRecord::Base
has_many :users
end
class User < ActiveRecord::Base
belongs_to :status
has_many :albums, dependent: :destroy
validates :name, presence: true
validates :email, presence: true
has_attached_file :avatar,
:styles => {
:large => "300x300>",
:medium => "100x100>",
:thumb => "30x30>"
},
:default_url => "no_user_ava_3.png"
validates_attachment_content_type :avatar, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
validates_attachment_file_name :avatar, :matches => [/png\Z/, /jpe?g\Z/, /gif\Z/]
end
I'm trying to write a test for the model. im create follow factories:
FactoryGirl.define do
factory :status do
sequence(:id){ |id| id }
title 'user'
end
end
FactoryGirl.define do
factory :user do
sequence(:name){ |i| "us#{i}" }
sequence(:email){ |i| "us#{i}@ad.ad" }
password 'qwerty'
password_confirmation{ |u| u.password }
association :status
end
end
FactoryGirl.define do
factory :album do
sequence(:title){ |i| "title#{i}" }
association :user
closed nil
description 'The behavior of or the parent object.'
end
end
my model test:
require 'spec_helper'
describe Album do
it "has a valid factory" do
Factory.create(:album).should be_valid
end
end
after I run the test, I get the following:
kalinin@kalinin ~/rails/phs $ rspec spec/models --format documentation
Album has a valid factory (FAILED - 1)
Failures:
1) Album has a valid factory Failure/Error: Factory.create(:album).should be_valid NameError: uninitialized constant Factory # ./spec/models/album_spec.rb:5:in `block (2 levels) in '
Finished in 0.96458 seconds (files took 2.34 seconds to load) 1 example, 1 failure
Failed examples:
rspec ./spec/models/album_spec.rb:4 # Album has a valid factory