0
有一個測試參數的比較。在rails 5 params
已經是該對象,並且每個新散列都在這個對象的參數中。我如何比較這些參數?參數比較ActionController ::測試中的參數
我得到這個錯誤。
Failure/Error: expect(session[:last_ticket_search]).to eq(params)
expected: <ActionController::Parameters {"q"=>{"ticket_number_eq"=>"123-123-123"}, "advanced_search"=>"t", "selected_columns"=>["ticket_number", "our_service_areas"], "commit"=>"Apply"} permitted: false>
got: {:q=><ActionController::Parameters {"ticket_number_eq"=>"123-123-123"} permitted: false>, :advanced_search=>"t", :selected_columns=>["ticket_number", "our_service_areas"], :commit=>"Apply"}
(compared using ==)
Diff:
@@ -1,2 +1,5 @@
-<ActionController::Parameters {"q"=>{"ticket_number_eq"=>"123-123-123"}, "advanced_search"=>"t", "selected_columns"=>["ticket_number", "our_service_areas"], "commit"=>"Apply"} permitted: false>
+:advanced_search => "t",
+:commit => "Apply",
+:q => <ActionController::Parameters {"ticket_number_eq"=>"123-123-123"} permitted: false>,
+:selected_columns => ["ticket_number", "our_service_areas"],
在這個測試中。
it 'will save last search params to session when saved advanced search is applied' do
search = FactoryGirl.create(:search, account: @account)
get :index, params: {advanced_search: 't', search_id: search.id, q: {ticket_number_eq: '123-123-123'}, selected_columns: ['ticket_number', 'our_service_areas']}
params = {
advanced_search: 't',
search_id: search.id.to_s,
selected_columns: ['ticket_number', 'our_service_areas'],
q: {'ticket_number_eq' => '123-123-123'}
}
expect(session[:last_ticket_search]).to eq(params)
end
索引操作。
def index
authorize Ticket
@search = current_account.searches.find_by(id: params[:search_id])
@autorefresh_interval = autorefresh('tickets')
@q = policy_scope(Ticket).ransack(params[:q])
if params[:q].blank? && params[:advanced_search].blank?
@q.add_default_condition('status', 'in', 'open')
session[:last_ticket_search] = nil
else
# This is required for Chrome to redirect back to the applied search.
# Firefox and Edge act a bit different than Chrome and do that without this
# when using the back link functionality in navigation.coffee.
session[:last_ticket_search] = {q: params[:q]}
if params[:advanced_search].present?
session[:last_ticket_search].merge!(advanced_search: 't', selected_columns: params[:selected_columns])
session[:last_ticket_search].merge!(params[:search_id].present? ? {search_id: params[:search_id]} : {commit: 'Apply'})
end
end
@selected_columns = selected_columns
@tickets = @q.result.select('tickets.*')
.includes(:account, :ticket_responses, :assignee, :tags)
.order('tickets.created_at DESC')
.group('tickets.id')
.paginate(page: params[:page], per_page: per_page('tickets'))
end
請顯示控制器代碼。 – margo
@margo編輯了這個問題。 –