-
+
<% if @search_terms %> @@ -27,17 +27,7 @@ <%= t("debates.index.select_order_long") %> <% end %> -
- -
-
+ <%= render 'shared/order_select', i18n_namespace: "debates.index" %>
<%= link_to t("debates.index.start_debate"), new_debate_path, class: 'button radius expand' %> diff --git a/app/views/shared/_order_select.html.erb b/app/views/shared/_order_select.html.erb new file mode 100644 index 000000000..de1576199 --- /dev/null +++ b/app/views/shared/_order_select.html.erb @@ -0,0 +1,15 @@ +<% # Params: + # + # i18n_namespace: for example "moderation.debates.index" +%> + +
+ +
diff --git a/spec/controllers/concerns/has_orders_spec.rb b/spec/controllers/concerns/has_orders_spec.rb new file mode 100644 index 000000000..082c4c068 --- /dev/null +++ b/spec/controllers/concerns/has_orders_spec.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +describe 'HasOrders' do + + class FakeController < ActionController::Base; end + + controller(FakeController) do + include HasOrders + has_orders ['created_at', 'votes_count', 'flags_count'], only: :index + + def index + render text: "#{@current_order} (#{@valid_orders.join(' ')})" + end + end + + it "has the valid orders set up" do + get :index + expect(response.body).to eq('created_at (created_at votes_count flags_count)') + end + + describe "the current order" do + it "defaults to the first one on the list" do + get :index + expect(response.body).to eq('created_at (created_at votes_count flags_count)') + end + + it "can be changed by the order param" do + get :index, order: 'votes_count' + expect(response.body).to eq('votes_count (created_at votes_count flags_count)') + end + + it "defaults to the first one on the list if given a bogus order" do + get :index, order: 'foobar' + expect(response.body).to eq('created_at (created_at votes_count flags_count)') + end + end +end