Files
grecia/spec/controllers/concerns/has_orders_spec.rb
2016-06-03 18:30:47 +02:00

48 lines
1.3 KiB
Ruby

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
has_orders ->{ ['votes_count', 'flags_count'] }, only: :new
def index
render text: "#{@current_order} (#{@valid_orders.join(' ')})"
end
def new
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
it "allows specifying the orders via a lambda" do
get :new
expect(response.body).to eq('votes_count (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