From 5c2d091fd3044c4c000efe73254b0a94c16b8b2f Mon Sep 17 00:00:00 2001 From: Sajjad Ahmad Date: Wed, 27 Sep 2023 19:16:49 +0500 Subject: [PATCH] Add a controller spec for index action to test the mileage rates are in ascending order --- spec/controllers/mileage_rates_controller_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/controllers/mileage_rates_controller_spec.rb diff --git a/spec/controllers/mileage_rates_controller_spec.rb b/spec/controllers/mileage_rates_controller_spec.rb new file mode 100644 index 0000000000..90a271de58 --- /dev/null +++ b/spec/controllers/mileage_rates_controller_spec.rb @@ -0,0 +1,14 @@ +require "rails_helper" + +RSpec.describe MileageRatesController, type: :controller do + describe "#index" do + it "render the mileage rates by effective date in ascending order" do + mileage_rate1 = FactoryBot.create(:mileage_rate, effective_date: Date.new(2023, 3, 1)) + mileage_rate2 = FactoryBot.create(:mileage_rate, effective_date: Date.new(2023, 1, 1)) + mileage_rate3 = FactoryBot.create(:mileage_rate, effective_date: Date.new(2023, 2, 1)) + mileage_rates = MileageRate.order(effective_date: :asc) + get :index + expect(mileage_rates).to eq([mileage_rate2, mileage_rate3, mileage_rate1]) + end + end +end