describe Flyboy::GoalsController, type: :controller do routes { Flyboy::Engine.routes } let(:goal){ FactoryGirl.create(:flyboy_goal) } describe '#index' do context 'when applying filter' do before(:each) do Flyboy::Goal.destroy_all @goal1 = FactoryGirl.create(:flyboy_goal, status: "open") @goal2 = FactoryGirl.create(:flyboy_goal, status: "closed") end it 'should display both when not filtered' do get :index assigns(:goals).should eq [@goal2, @goal1] end it 'should filter by status closed' do Flyboy::SmallData::FilterForGoals.new(request.cookies) .store(status: "closed") get :index assigns(:goals).should eq [@goal2] end it 'should filter by status open' do Flyboy::SmallData::FilterForGoals.new(request.cookies) .store(status: "open") get :index assigns(:goals).should eq [@goal1] end end end describe "#close" do before(:each) do @goal = FactoryGirl.create(:flyboy_goal, status: "open") end it "should close goal" do patch :close, id: @goal expect(@goal.reload.status).to eq "closed" end it "should redirect to goals path" do patch :close, id: @goal expect(response).to redirect_to goals_path end end describe "#open" do before(:each) do @goal = FactoryGirl.create(:flyboy_goal, status: "closed") end it "should open goal" do patch :open, id: @goal expect(@goal.reload.status).to eq "open" end it "should redirect to goal path" do patch :open, id: @goal expect(response).to redirect_to goal_path(@goal) end end end