devise - Rails spec failed after adding paperclip avatar - undefined method `avatar_content_type' -



devise - Rails spec failed after adding paperclip avatar - undefined method `avatar_content_type' -

after adding avatar (with paperclip gem) user model (user model generated devise) of specs started fail - returning errors like:

1) user should require lastname set failure/error: { should validate_presence_of :lastname } nomethoderror: undefined method `avatar_content_type' #<user:0x00000008aac910> # ./spec/models/user_spec.rb:5:in `block (2 levels) in <top (required)>' 2) user should require firstname set failure/error: { should validate_presence_of :firstname } nomethoderror: undefined method `avatar_content_type' #<user:0x00000008ee1148> # ./spec/models/user_spec.rb:4:in `block (2 levels) in <top (required)>'

this user model:

class user < activerecord::base # include default devise modules. others available are: # :confirmable, :lockable, :timeoutable , :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png" validates_attachment_content_type :avatar, :content_type => /\aimage\/.*\z/ has_many :reviews has_many :products validates :firstname, presence: true validates :lastname, presence: true def admin? homecoming admin end end

this db/schema.rb users table:

create_table "users", force: true |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" t.boolean "admin", default: false t.string "firstname" t.string "lastname" t.string "avatar_file_name" t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree

user model spec:

require 'spec_helper' describe user { should validate_presence_of :firstname } { should validate_presence_of :lastname } "by default isn't admin" expect(user.new).to_not be_admin end end

can give me clue why tests fail after adding avatar user , homecoming 'undefined method `avatar_content_type' error?

you can alter validate below:

validates_attachment_content_type :avatar, :content_type => /\aimage\/.*\z/

to:

validates_attachment_content_type :avatar, :content_type => /\aimage\/.*\z/ unless rails.env.test?

which skip validate in rspec.

ruby-on-rails devise paperclip

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -