spec/controllers/flyboy/goals_controller_spec.rb in flyboy-1.0.4 vs spec/controllers/flyboy/goals_controller_spec.rb in flyboy-1.0.5
- old
+ new
@@ -32,9 +32,48 @@
get :index
assigns(:goals).should eq [@goal1]
end
end
+
+ context "when sorting" do
+ before do
+ Flyboy::Goal.destroy_all
+ @goal1 = FactoryGirl.create(:flyboy_goal, title: "Abc", progress: 100, status: "open")
+ @goal2 = FactoryGirl.create(:flyboy_goal, title: "dEF", progress: 0, status: "closed")
+ @goal3 = FactoryGirl.create(:flyboy_goal, title: "xyz", progress: 35, status: "closed")
+ end
+
+ it "sorting by title asc" do
+ get :index, sort: "title"
+ expect(assigns(:goals).to_a).to eq [@goal1, @goal2, @goal3]
+ end
+
+ it "sorting by title desc" do
+ get :index, sort: "-title"
+ expect(assigns(:goals).to_a).to eq [@goal3, @goal2, @goal1]
+ end
+
+ it "sorting by progress asc" do
+ get :index, sort: "progress"
+ expect(assigns(:goals).to_a).to eq [@goal2, @goal3, @goal1]
+ end
+
+ it "sorting by progress desc" do
+ get :index, sort: "-progress"
+ expect(assigns(:goals).to_a).to eq [@goal1, @goal3, @goal2]
+ end
+
+ it "sorting by status asc" do
+ get :index, sort: "status"
+ expect(assigns(:goals).to_a).to eq [@goal2, @goal3, @goal1]
+ end
+
+ it "sorting by status desc" do
+ get :index, sort: "-status"
+ expect(assigns(:goals).to_a).to eq [@goal1, @goal2, @goal3]
+ end
+ end
end
describe "#close" do
before(:each) do
@goal = FactoryGirl.create(:flyboy_goal, status: "open")