2014-04-23 2 views
0

나는 전에 사용하지 않은 state_machine 보석을 사용하는 프로젝트에서 일하고있다. , 나는 컨트롤러 쓰고 있어요 내 테스트에서state_machine 전환이 false를 반환하는 이유를 모르겠다.

if @booking.propose_offer_as_guest 
    # do some stuff 
end 

@booking.propose_offer_as_guest는 항상 false를 반환 내가 왜 모르는 :

컨트롤러 중 하나에 있습니다.

app/models/booking.rb의 상태 머신의 정의는 다음과 같습니다 : 나는 propose_offer_as_guest이 작동하지 만들 수있는 것 같아 아무것도 표시되지 않습니다

state_machine :initial => :unaccepted_by_guest_or_host do                             [353/467] 

    #states: 
    # guest_accepted_offer 
    # guest_proposed_offer 
    # host_proposed_offer 
    # host_accepted_offer 
    # paid (when paid for) 
    # canceled 

    # to be used only by the host 
    event :propose_offer_as_host do 
     transition :unaccepted_by_guest_or_host => :host_proposed_offer 
    end 

    # to be used only by the host 
    event :revise_offer_as_host do 
     transition [:guest_proposed_offer, :host_proposed_offer, :host_accepted_offer, :guest_accepted_offer] => :host_proposed_offer 
    end 

    # to be used only by the host 
    event :accept_offer_as_host do 
     transition :guest_proposed_offer => :host_accepted_offer 
    end 

    # to be used only by the guest 
    event :propose_offer_as_guest do 
     transition :unaccepted_by_guest_or_host => :guest_proposed_offer 
    end 

    # to be used only by the guest 
    event :revise_offer_as_guest do 
     transition [:host_proposed_offer, :guest_proposed_offer, :host_accepted_offer, :guest_accepted_offer] => :guest_proposed_offer 
    end 

    # to be used only by the guest 
    event :accept_offer_as_guest do 
     transition :host_proposed_offer => :guest_accepted_offer 
    end 

    event :mark_as_paid do 
     transition [:guest_accepted_offer, :host_accepted_offer] => :paid 
    end 

    # process the credit card safely, if this fails with an exception, state won't be transitioned 
    # around_transition on: :pay do |booking, transition, block| 
    # booking.transaction do 
    #  block.call # block is an event's proc. we need to perform it 
    #  booking.process_credit_card 
    # end 
    # end 

    event :cancel do 
     transition all => :canceled 
    end 
    end 

. 거래는 뭐니?

편집는 :

require 'spec_helper' 

describe BookingsController do 

    include Capybara::DSL 
    include Capybara::RSpecMatchers 
    render_views 

    describe "POST create" do 
    before do 
     @params = { 
     "booking" => { 
      "start_date" => "April 24, 2014", 
      "end_date" => "April 25, 2014", 
      "guests"  => "1", 
      "message" => "test", 
      "email"  => "[email protected]", 
      "captcha" => "wet" 
     } 
     } 
    end 

    it "sends new booking notification email" do 
     expect(BookingMailer).to receive(:new_booking_notification) 
     post :create, @params 
    end 
    end 
end 
+0

테스트를 게시 할 수 있습니까? – JoJoS

+0

테스트를 추가했습니다. –

답변

0

@booking가 유효하기 때문에 이유는 밝혀 : 여기 내 테스트입니다. 나는이 질문이 그 좁음 때문에 닫히게 될 것이라고 의심한다.

관련 문제