<commit_before>require "spec_helper"

describe AttendeesController do
  render_views
  let(:activities) { 1.upto(3).map{ FactoryGirl.create :activity } }

  context "as a visitor" do
    describe "#create" do
      it "is forbidden for visitors" do
        attrs = FactoryGirl.attributes_for :attendee
        expect { post :create, attendee: attrs, year: attrs[:year]
          }.to_not change{ Attendee.count }
        response.should be_forbidden
      end
    end

    describe "#edit" do
      it "is forbidden" do
        a = FactoryGirl.create :attendee
        get :edit, :id => a.id, :year => a.year
        response.should be_forbidden
      end
    end

    describe "#index" do
      render_views

      it "succeeds" do
        get :index, :year => Time.now.year
        response.should be_successful
      end

      it "lists attendees with at least one plan" do
        p = FactoryGirl.create :plan
        a = FactoryGirl.create :attendee, {plans: [p]}
        a2 = FactoryGirl.create :attendee, {plans: []}
        get :index, year: a.year
        response.should be_successful
        assigns(:attendees).should include(a)
        assigns(:attendees).should_not include(a2)
      end
    end

    describe "#new" do
      it "is forbidden" do
        get :new, :year => Time.now.year
        response.should be_forbidden
      end
    end
  end

  context "as a user" do
    let!(:attendee) { FactoryGirl.create :attendee }
    let!(:user) { attendee.user }
    before { sign_in user }

    describe "#create" do
      it "succeeds under own account" do
        a = FactoryGirl.attributes_for(:attendee, :user_id => user.id)
        expect { post :create, :attendee => a, :year => user.year
          }.to change { user.attendees.count }.by(+1)
        response.should redirect_to \
          user_terminus_path(:user_id => user.id, :year => user.year)
      end

      it "note to self" do
        pending "the discount_ids and all the airport fields cause
          mass-assigment warnings before create, in cancan's
          load_resource. they should probably be moved outside of
          params[:attendee]"
      end

      it "is forbidden to create attendee under a different user" do
        user_two = FactoryGirl.create :user
        a = FactoryGirl.attributes_for(:attendee, :user_id => user_two.id)
        expect { post :create, :attendee => a, :year => a[:year]
          }.not_to change { Attendee.count }
        response.should be_forbidden<commit_msg>post to create fails without any attributes<commit_after>require "spec_helper"

describe AttendeesController do
  render_views
  let(:activities) { 1.upto(3).map{ FactoryGirl.create :activity } }

  context "as a visitor" do
    describe "#create" do
      it "is forbidden for visitors" do
        attrs = FactoryGirl.attributes_for :attendee
        expect { post :create, attendee: attrs, year: attrs[:year]
          }.to_not change{ Attendee.count }
        response.should be_forbidden
      end
    end

    describe "#edit" do
      it "is forbidden" do
        a = FactoryGirl.create :attendee
        get :edit, :id => a.id, :year => a.year
        response.should be_forbidden
      end
    end

    describe "#index" do
      render_views

      it "succeeds" do
        get :index, :year => Time.now.year
        response.should be_successful
      end

      it "lists attendees with at least one plan" do
        p = FactoryGirl.create :plan
        a = FactoryGirl.create :attendee, {plans: [p]}
        a2 = FactoryGirl.create :attendee, {plans: []}
        get :index, year: a.year
        response.should be_successful
        assigns(:attendees).should include(a)
        assigns(:attendees).should_not include(a2)
      end
    end

    describe "#new" do
      it "is forbidden" do
        get :new, :year => Time.now.year
        response.should be_forbidden
      end
    end
  end

  context "as a user" do
    let!(:attendee) { FactoryGirl.create :attendee }
    let!(:user) { attendee.user }
    before { sign_in user }

    describe "#create" do
      it "succeeds under own account" do
        a = FactoryGirl.attributes_for(:attendee, :user_id => user.id)
        expect { post :create, :attendee => a, :year => user.year
          }.to change { user.attendees.count }.by(+1)
        response.should redirect_to \
          user_terminus_path(:user_id => user.id, :year => user.year)
      end

      it "fails without any attributes" do
        attrs = {:user_id => user.id}
        expect { post :create, :attendee => attrs, :year => user.year
          }.to_not change { Attendee.count }
        response.should render_template :new
        assigns(:attendee).errors.should_not be_empty
      end

      it "note to self" do
        pending "the discount_ids and all the airport fields cause
          mass-assigment warnings before create, in cancan's
          load_resource. they should probably be moved outside of
          params[:attendee]"
      end

      it "is forbidden to create attendee under a different user" do
        user_two = FactoryGirl.create :user
        a = FactoryGirl.attributes_for(:attendee, :user_id => user_two.id)
        expect { post :create, :attendee => a, :year => a[:year]
          }.not_to change { Attendee.count }
        response.should be_forbidden
{'fraction_non_alphanumeric': 0.09706546275395034, 'fraction_numerical': 0.0018811136192626034, 'mean_word_length': 2.341923318667505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, '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': '3824173', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1596, 'n_words': 486}