app/controller/new_controller.rb:
class NewController < ApplicationController
def enter_time
session[:dr] = 'dr'
if !params[:time].nil? then
Time.zone = @franchise.time_zone
inanhour = 1.hour.since(Time.zone.now)
delivery_time = delivery_time_format(params[:time])
delivery_time = delivery_time.change(offset: (Time.zone.now.utc_offset / 3600).to_s)
session[:target_time] = [delivery_time, inanhour].max.to_s
end
end
end
spec/controllers/new_controller_spec.rb:
require 'spec_helper'
describe NewController, :type => :controller do
before do
allow(controller).to receive(:current_user) { nil }
end
describe "POST /enter_time" do
let(:addr_str) { '2810 Derby St, Berkeley, CA, United States' }
let(:delivery_time) { '06/06/2015 12:15 PM' }
it "sets current time of time zone" do
address = VCR.use_cassette('retrieve_address #{addr_str}', record: :new_episodes) do
Address.retrieve_address(addr_str)
end
a = { id: address.id, text: addr_str, lat: address.lat, lng: address.lng, src: :text }
post :enter_time, { time: delivery_time }
expect(assigns(session['dr'])).to eq("dr")
end
end
end
抛出错误:
expected: "dr" got: nil
expect(assigns(session['dr'])).to eq("dr")
和expect(assigns(session[:dr])).to eq("dr")
都不能工作
尝试:expect(session['dr']).to eq("dr")
。
CCD_ 4的值与CCD_。