2014-11-15 46 views
0

Travis的Rails構建失敗所以我有一個使用Devise gem的用戶模型。由於未定義的方法'encrypted_pa​​ssword =',用戶

# == Schema Information 
# 
# Table name: USERS 
# 
# u_id     :integer   not null, primary key 
# email     :string(255)  default(""), not null 
# encrypted_password  :string(255)  default(""), not null 
# reset_password_token :string(255) 
# reset_password_sent_at :datetime 
# remember_created_at :datetime 
# sign_in_count   :integer   default(0), not null 
# current_sign_in_at  :datetime 
# last_sign_in_at  :datetime 
# current_sign_in_ip  :string(255) 
# last_sign_in_ip  :string(255) 
# join_date    :datetime 
# organization   :string(255) 
# created_at    :datetime 
# updated_at    :datetime 
# 

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 
    self.table_name = "USERS" 
end 

我也有一個工廠女孩工廠來創建用戶對象爲我的RSpec的測試

FactoryGirl.define do 
    factory :user do |user| 
    user.email '[email protected]' 
    user.password Devise.friendly_token[0,20] 
    end 
end 

所有我對我的本地環境的測試與rake spec通,但是當我運行特拉維斯打造,它始終未能在RSpec的測試用:

undefined method `encrypted_password=' for #<User:0x67c24931> 
# ./spec/models/user_spec.rb:26:in `(root)' 

這裏是我的user_spec.rb

require 'rails_helper' 

RSpec.describe User, :type => :model do 
    it "successfully creates a user" do 
    @user = FactoryGirl.create :user 
    expect(@user.save).to be_truthy 
    end 
end 

我通過rails c檢查了User.new.respond_to?(:encrypted_password=)返回true。我不確定什麼可能是錯誤的,我找不到我的問題的任何答案。那麼,我錯過了什麼嗎?

編輯:

漏填了.travis.yml

language: ruby 
rvm: 
    - jruby-1.7.15 
env: 
    - DB=mysql 

script: 
    - export JRUBY_OPTS=--1.9 
    - RAILS_ENV=test bundle exec rake --trace db:migrate spec 
before_script: 
    - mysql -e 'create database test_db' 

EDIT2: 添加特拉維斯日誌數據庫遷移

$ RAILS_ENV=test bundle exec rake --trace db:migrate spec 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:load_config (first_time) 
** Execute db:load_config 
** Execute db:migrate 
== 20141031200108 CreateAllTables: migrating ================================== 
-- create_table("GROUPS", {:primary_key=>"g_id", :force=>true}) 
    -> 0.0130s 
-- create_table("TICKET_PRIORITY", {:primary_key=>"tp_id", :force=>true}) 
    -> 0.0120s 
-- create_table("USERS", {:primary_key=>"u_id", :force=>true}) 
    -> 0.0110s 
-- create_table("BOARDS", {:primary_key=>"b_id", :force=>true}) 
    -> 0.0120s 
-- add_index("BOARDS", ["current_sprint_id"], {:name=>"current_sprint_id", :using=>:btree}) 
    -> 0.0370s 
    -> 0 rows 
-- add_index("BOARDS", ["p_id"], {:name=>"p_id", :using=>:btree}) 
    -> 0.0200s 
    -> 0 rows 
-- create_table("COMMENTS", {:primary_key=>"c_id", :force=>true}) 
    -> 0.0120s 
-- add_index("COMMENTS", ["u_id"], {:name=>"u_id", :using=>:btree}) 
    -> 0.0210s 
    -> 0 rows 
-- create_table("GROUP_PERMISSIONS", {:id=>false, :force=>true}) 
    -> 0.0120s 
-- add_index("GROUP_PERMISSIONS", ["g_id"], {:name=>"g_id", :using=>:btree}) 
    -> 0.0190s 
    -> 0 rows 
-- create_table("PROJECTS", {:primary_key=>"p_id", :force=>true}) 
    -> 0.0150s 
-- add_index("PROJECTS", ["owner_id"], {:name=>"owner_id", :using=>:btree}) 
    -> 0.0190s 
    -> 0 rows 
-- create_table("SPRINTS", {:primary_key=>"s_id", :force=>true}) 
    -> 0.0110s 
-- add_index("SPRINTS", ["b_id"], {:name=>"b_id", :using=>:btree}) 
    -> 0.0190s 
    -> 0 rows 
-- create_table("TICKET_ASSIGNMENT_HISTORY", {:id=>false, :force=>true}) 
    -> 0.0140s 
-- add_index("TICKET_ASSIGNMENT_HISTORY", ["t_id"], {:name=>"t_id", :using=>:btree}) 
    -> 0.0210s 
    -> 0 rows 
-- add_index("TICKET_ASSIGNMENT_HISTORY", ["u_id"], {:name=>"u_id", :using=>:btree}) 
    -> 0.0210s 
    -> 0 rows 
-- create_table("TICKET_STATUS_HISTORY", {:primary_key=>"tsh_id", :force=>true}) 
    -> 0.0130s 
-- add_index("TICKET_STATUS_HISTORY", ["t_id"], {:name=>"t_id", :using=>:btree}) 
    -> 0.0180s 
    -> 0 rows 
-- create_table("TICKET_TAGS", {:id=>false, :force=>true}) 
    -> 0.0120s 
-- add_index("TICKET_TAGS", ["t_id"], {:name=>"t_id", :using=>:btree}) 
    -> 0.0170s 
    -> 0 rows 
-- create_table("TICKETS", {:primary_key=>"t_id", :force=>true}) 
    -> 0.0150s 
-- add_index("TICKETS", ["b_id"], {:name=>"b_id", :using=>:btree}) 
    -> 0.0180s 
    -> 0 rows 
-- add_index("TICKETS", ["current_status_id"], {:name=>"current_status_id", :using=>:btree}) 
    -> 0.0180s 
    -> 0 rows 
-- add_index("TICKETS", ["s_id"], {:name=>"s_id", :using=>:btree}) 
    -> 0.0220s 
    -> 0 rows 
-- add_index("TICKETS", ["tp_id"], {:name=>"tp_id", :using=>:btree}) 
    -> 0.0220s 
    -> 0 rows 
-- create_table("USER_GROUP", {:id=>false, :force=>true}) 
    -> 0.0160s 
-- add_index("USER_GROUP", ["g_id"], {:name=>"g_id", :using=>:btree}) 
    -> 0.0190s 
    -> 0 rows 
-- add_index("USER_GROUP", ["u_id"], {:name=>"u_id", :using=>:btree}) 
    -> 0.0180s 
    -> 0 rows 
== 20141031200108 CreateAllTables: migrated (0.5070s) ========================= 
== 20141031201446 UpdateEnumsInTables: migrating ============================== 
-- remove_column(:TICKETS, :type, :string) 
    -> 0.0290s 
    -> 0 rows 
-- add_column(:TICKETS, :type, :integer) 
    -> 0.0250s 
    -> 0 rows 
-- remove_column(:TICKET_ASSIGNMENT_HISTORY, :relationship, :string) 
    -> 0.0240s 
    -> 0 rows 
-- add_column(:TICKET_ASSIGNMENT_HISTORY, :relationship, :integer) 
    -> 0.0280s 
    -> 0 rows 
-- remove_column(:TICKET_STATUS_HISTORY, :new_status, :string) 
    -> 0.0250s 
    -> 0 rows 
-- add_column(:TICKET_STATUS_HISTORY, :new_status, :integer) 
    -> 0.0250s 
    -> 0 rows 
== 20141031201446 UpdateEnumsInTables: migrated (0.1580s) ===================== 
== 20141106220707 ModifyGroupPermissions: migrating =========================== 
-- remove_column(:GROUP_PERMISSIONS, :name) 
    -> 0.0230s 
    -> 0 rows 
-- remove_column(:GROUP_PERMISSIONS, :rank) 
    -> 0.0250s 
    -> 0 rows 
-- add_column(:GROUP_PERMISSIONS, :pm_id, :integer) 
    -> 0.0280s 
    -> 0 rows 
-- create_table("PERMISSIONS", {:primary_key=>"pm_id", :force=>true}) 
    -> 0.0110s 
== 20141106220707 ModifyGroupPermissions: migrated (0.0880s) ================== 
== 20141107011729 DeviseCreateUsers: migrating ================================ 
-- create_table(:users, {:primary_key=>"u_id", :force=>true}) 
    -> 0.0160s 
-- add_index(:users, :email, {:unique=>true}) 
    -> 0.0350s 
    -> 0 rows 
-- add_index(:users, :reset_password_token, {:unique=>true}) 
    -> 0.0200s 
    -> 0 rows 
== 20141107011729 DeviseCreateUsers: migrated (0.0790s) ======================= 
** Invoke db:_dump (first_time) 
** Execute db:_dump 
** Invoke db:schema:dump (first_time) 
** Invoke environment 
** Invoke db:load_config 
** Execute db:schema:dump 
** Invoke spec (first_time) 
** Invoke spec:prepare (first_time) 
** Execute spec:prepare 
** Invoke test:prepare (first_time) 
** Execute test:prepare 
** Execute spec 

編輯:

我也在運行0123之前嘗試運行在travis上,它顯示用戶表具有encrypted_pa​​ssword列。我也運行了cat db/schema.rb以查看遷移是否完全發生,並且encrypted_pa​​ssword也在那裏。現在我不確定這個字段在數據庫中會出現什麼問題。

+0

可能是遷移測試數據庫的問題。顯示您的Travis日誌 –

+0

添加了Travis db遷移日誌 –

+0

- create_table(「USERS」,{:primary_key =>「u_id」,:force => true}) 此遷移包含缺少列​​嗎? –

回答

0

那麼,當我在MySQL中創建我的表時,我對所有表名使用了大寫字母。出於某種原因,在本地運行時,表名在開發模式下仍爲大寫,但在測試模式下爲小寫。所以,在我的用戶模型中,我只是將self.table_name = "USERS"更改爲self.table_name = "users",並解決了我的問題。

相關問題