に渡すために参加し、私はリードのモデルを持っているとコントローラ#インデックスはRSpecの
# A Lead is a type of User that might be interested in using our service.
class Lead < User
validates :first_name, presence: true
has_many :notes, dependent: :destroy
def self.search(search)
...
end
end
を取得鉛は、すべてのユーザーが:address, :city, :state
のようなデータを含むものLocation
を、持っているユーザー
class User < ActiveRecord::Base
has_one :location, dependent: :destroy
accepts_nested_attributes_for :location
delegate :address, :city, :state, :zip_code,
:full_location, :latitude, :longitude,
to: :location, allow_nil: true
end
から継承します
私はこのコントローラを持っています
class LeadsController < ApplicationController
helper_method :sort_column
def index
@leads = Lead.search(params[:search])
.joins(:location)
.order("#{sort_column} #{sort_direction}")
.page(params[:page])
.per(8)
end
end
私はこのテスト
describe LeadsController, type: :controller do
before do
@lead = create :lead
end
describe 'GET #index' do
it 'populates an array of leads' do
get :index
assigns(:leads).should eq [@lead]
end
end
にがを失敗し、@leads
が空であると言うスペックを持っています。私はすべてがdevelopment
で正常に動作LeadsController
にライン.joins(:location)
を削除すると
スペックはを渡します。アプリはすべての正しいデータをプルアップして表示することができます。
何らかの理由により、test
環境の.joins
は、@leads
を空にします。
私はその行が必要です。私はリード(ユーザー)をzip_codeでソートできるようにする必要があります。 zip_codeはLocation
オブジェクトに格納されています。
私の質問は:郵便番号のソート可能性を維持しながら仕様をパスするにはどうすればよいですか? test
環境ではどうなりますか?
ありがとうございます!
'.joins(:location)'を '.search'の前に置いてみましたか? – mmichael
@mmichael私は持っています。それでもなお失敗します。 –
あなたの工場はどのように見えますか? –