Browse Source

new is fixed

pull/704/head
JG 3 years ago
parent
commit
ef1486c323
  1. 2
      app/controllers/locations_controller.rb
  2. 6
      app/controllers/schemes_controller.rb
  3. 10
      spec/requests/locations_controller_spec.rb

2
app/controllers/locations_controller.rb

@ -54,7 +54,7 @@ private
end end
def authenticate_action! def authenticate_action!
if %w[details edit update].include?(action_name) && !((current_user.organisation == @scheme.organisation) || current_user.support?) if %w[new edit update].include?(action_name) && !((current_user.organisation == @scheme.organisation) || current_user.support?)
render_not_found and return render_not_found and return
end end
end end

6
app/controllers/schemes_controller.rb

@ -20,12 +20,6 @@ class SchemesController < ApplicationController
@scheme = Scheme.find_by(id: params[:id]) @scheme = Scheme.find_by(id: params[:id])
end end
def locations
@scheme = Scheme.find_by(id: params[:id])
@pagy, @locations = pagy(@scheme.locations)
@total_count = @scheme.locations.size
end
def new def new
@scheme = Scheme.new @scheme = Scheme.new
end end

10
spec/requests/locations_controller_spec.rb

@ -8,7 +8,7 @@ RSpec.describe LocationsController, type: :request do
describe "#new" do describe "#new" do
context "when not signed in" do context "when not signed in" do
it "redirects to the sign in page" do it "redirects to the sign in page" do
get "/schemes/1/location/new" get "/schemes/1/locations/new"
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
end end
@ -18,7 +18,7 @@ RSpec.describe LocationsController, type: :request do
before do before do
sign_in user sign_in user
get "/schemes/1/location/new" get "/schemes/1/locations/new"
end end
it "returns 401 unauthorized" do it "returns 401 unauthorized" do
@ -33,7 +33,7 @@ RSpec.describe LocationsController, type: :request do
before do before do
sign_in user sign_in user
get "/schemes/#{scheme.id}/location/new" get "/schemes/#{scheme.id}/locations/new"
end end
it "returns a template for a new location" do it "returns a template for a new location" do
@ -45,7 +45,7 @@ RSpec.describe LocationsController, type: :request do
let(:another_scheme) { FactoryBot.create(:scheme) } let(:another_scheme) { FactoryBot.create(:scheme) }
it "displays the new page with an error message" do it "displays the new page with an error message" do
get "/schemes/#{another_scheme.id}/location/new" get "/schemes/#{another_scheme.id}/locations/new"
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end end
end end
@ -55,7 +55,7 @@ RSpec.describe LocationsController, type: :request do
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
get "/schemes/#{scheme.id}/location/new" get "/schemes/#{scheme.id}/locations/new"
end end
it "returns a template for a new location" do it "returns a template for a new location" do

Loading…
Cancel
Save