spec/controllers/flyboy/tasks_controller_spec.rb in flyboy-1.0.4 vs spec/controllers/flyboy/tasks_controller_spec.rb in flyboy-1.0.5

- old
+ new

@@ -44,11 +44,11 @@ end describe "GET index" do it "assigns all tasks as @tasks" do get :index, {} - expect(assigns(:tasks)).to eq Flyboy::Task.all + expect(assigns(:tasks).to_a).to eq Flyboy::Task.all.to_a end context "when applying filter" do before do Flyboy::Task.destroy_all @@ -69,9 +69,63 @@ it 'should filter by status opened' do Flyboy::SmallData::FilterForTasks.new(request.cookies).store({'status' => "opened"}) get :index assigns(:tasks).should eq [@task2] + end + end + + context "when sorting" do + before do + Flyboy::Goal.destroy_all + Flyboy::Task.destroy_all + @goal1 = FactoryGirl.create(:flyboy_goal, title: "Abc") + @goal2 = FactoryGirl.create(:flyboy_goal, title: "dEF") + @goal3 = FactoryGirl.create(:flyboy_goal, title: "xyz") + + @task1 = FactoryGirl.create(:flyboy_task, goal: @goal1, title: "Abc", progress: 100, term: "21/12/2012", reminder: "21/12/2012") + @task2 = FactoryGirl.create(:flyboy_task, goal: @goal2, title: "dEF", progress: 0, term: "23/12/2012", reminder: "23/12/2012") + @task3 = FactoryGirl.create(:flyboy_task, goal: @goal3, title: "xyz", progress: 35, term: "22/12/2012", reminder: "22/12/2012") + end + + it "sorting by goal asc" do + get :index, sort: "goal" + expect(assigns(:tasks).to_a).to eq [@task1, @task2, @task3] + end + + it "sorting by goal desc" do + get :index, sort: "-goal" + expect(assigns(:tasks).to_a).to eq [@task3, @task2, @task1] + end + + it "sorting by title asc" do + get :index, sort: "title" + expect(assigns(:tasks).to_a).to eq [@task1, @task2, @task3] + end + + it "sorting by title desc" do + get :index, sort: "-title" + expect(assigns(:tasks).to_a).to eq [@task3, @task2, @task1] + end + + it "sorting by progress asc" do + get :index, sort: "progress" + expect(assigns(:tasks).to_a).to eq [@task2, @task3, @task1] + end + + it "sorting by progress desc" do + get :index, sort: "-progress" + expect(assigns(:tasks).to_a).to eq [@task1, @task3, @task2] + end + + it "sorting by term asc" do + get :index, sort: "term" + expect(assigns(:tasks).to_a).to eq [@task1, @task3, @task2] + end + + it "sorting by term desc" do + get :index, sort: "-term" + expect(assigns(:tasks).to_a).to eq [@task2, @task3, @task1] end end end describe "GET show" do