<commit_before>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe ResponseController, "processing GET requests" do

  it "should flash and redirect to event/new if no event is found by permalink" do
    Event.should_receive(:find_by_permalink).with("foo").and_return(nil)
    get :post, :id => "foo"
    flash[:notice].should_not be_nil
    response.should redirect_to(:controller => "event", :action => "new")
  end

  it "should render the 'post' template if event is found" do
    Event.should_receive(:find_by_permalink).with("bar").and_return(mock_model(Event))
    get :post, :id => "bar"
    flash[:notice].should be_nil
    response.should render_template('post')
  end

  it "should output an RSS feed ordered in reverse chronology (most recent first)" do
    alice = mock_model(Response, :created_at => 5.minutes.ago, :name => "Alice")
    bob   = mock_model(Response, :created_at => 10.minutes.ago, :name => "Bob")
    event = mock_model(Event, :responses => [bob, alice])
    Event.should_receive(:find_by_permalink).and_return(event)
    event.should_receive(:guests_by_reverse_chron)
    get :feed
  end

end

describe ResponseController, "processing POST requests" do

  before do
    @event = mock_model(Event)
    @options = { :name => "bob", :rsvp => false}
  end

  it "should pass the params to Response when creating an instance" do
    Response.should_receive(:new).with(@options.stringify_keys).and_return(@response)
    @response.stub!(:save)
    @response.stub!(:event=)
    post :post, :response => @options
  end

  describe "if event is not found" do

    before :each do
      Event.should_receive(:find_by_permalink).with("foo").and_return(nil)
    end

    it "should not save the response" do
      lambda { post :post, :id => "foo", :response => @options }.should_not change(Response, :count)
    end

    it "should flash and redirect" do
      post :post, :id => "foo", :response => @options
      flash[:notice].should_not be_nil
      response.should redirect_to(home_path)
    end

  end

  describe "if event is found by permalink" do

    before :each do
      Event.should_receive(:find_by_permalink).with("bar").and_return(@event)
      @event.should_receive(:valid?).and_return(true)
    end

    it "should save the response" do
      lambda { post :post, :id => "bar", :response => @options }.should change(Response, :count).from(0).to(1)
    end

    it "should not flash and render anew" do
      post :post, :id => "bar", :response => @options
      flash[:notice].should_not be_nil
      response.should render_template('post')
    end

  end

  describe "if event is found but response is invalid" do

    before :each do
      Event.should_receive(:find_by_permalink).with("bar").and_return(@event)
      @event.should_receive(:valid?).and_return(true)
    end

    it "should not save the response" do
      lambda { post :post, :id => "bar", :response => @options.merge(:rsvp => nil) }.should_not change(Response, :count)
    end

    it "should flash and render anew" do
      post :post, :id => "bar", :response => @options.merge(:rsvp => nil)
      flash[:notice].should be_nil
      response.should render_template('post')
    end

  end

end
<commit_msg>Fixed tests that were broken by error flashes<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe ResponseController, "processing GET requests" do

  it "should flash and redirect to event/new if no event is found by permalink" do
    Event.should_receive(:find_by_permalink).with("foo").and_return(nil)
    get :post, :id => "foo"
    flash[:error].should_not be_nil
    response.should redirect_to(:controller => "event", :action => "new")
  end

  it "should render the 'post' template if event is found" do
    Event.should_receive(:find_by_permalink).with("bar").and_return(mock_model(Event))
    get :post, :id => "bar"
    flash[:notice].should be_nil
    response.should render_template('post')
  end

  it "should output an RSS feed ordered in reverse chronology (most recent first)" do
    alice = mock_model(Response, :created_at => 5.minutes.ago, :name => "Alice")
    bob   = mock_model(Response, :created_at => 10.minutes.ago, :name => "Bob")
    event = mock_model(Event, :responses => [bob, alice])
    Event.should_receive(:find_by_permalink).and_return(event)
    event.should_receive(:guests_by_reverse_chron)
    get :feed
  end

end

describe ResponseController, "processing POST requests" do

  before do
    @event = mock_model(Event)
    @options = { :name => "bob", :rsvp => false}
  end

  it "should pass the params to Response when creating an instance" do
    Response.should_receive(:new).with(@options.stringify_keys).and_return(@response)
    @response.stub!(:save)
    @response.stub!(:event=)
    post :post, :response => @options
  end

  describe "if event is not found" do

    before :each do
      Event.should_receive(:find_by_permalink).with("foo").and_return(nil)
    end

    it "should not save the response" do
      lambda { post :post, :id => "foo", :response => @options }.should_not change(Response, :count)
    end

    it "should flash and redirect" do
      post :post, :id => "foo", :response => @options
      flash[:error].should_not be_nil
      response.should redirect_to(home_path)
    end

  end

  describe "if event is found by permalink" do

    before :each do
      Event.should_receive(:find_by_permalink).with("bar").and_return(@event)
      @event.should_receive(:valid?).and_return(true)
    end

    it "should save the response" do
      lambda { post :post, :id => "bar", :response => @options }.should change(Response, :count).from(0).to(1)
    end

    it "should not flash and render anew" do
      post :post, :id => "bar", :response => @options
      flash[:notice].should_not be_nil
      response.should render_template('post')
    end

  end

  describe "if event is found but response is invalid" do

    before :each do
      Event.should_receive(:find_by_permalink).with("bar").and_return(@event)
      @event.should_receive(:valid?).and_return(true)
    end

    it "should not save the response" do
      lambda { post :post, :id => "bar", :response => @options.merge(:rsvp => nil) }.should_not change(Response, :count)
    end

    it "should flash and render anew" do
      post :post, :id => "bar", :response => @options.merge(:rsvp => nil)
      flash[:notice].should be_nil
      response.should render_template('post')
    end

  end

end

{'fraction_non_alphanumeric': 0.12780337941628264, 'fraction_numerical': 0.0015360983102918587, 'mean_word_length': 3.690922190201729, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '518533', 'n_tokens_mistral': 2097, 'n_tokens_neox': 2011, 'n_words': 579}