Browse Source

refacotred update/create and added test creating location as a coord user

pull/704/head
JG 3 years ago
parent
commit
02e6d1eee0
  1. 2
      app/views/schemes/check_answers.html.erb
  2. 4
      spec/features/schemes_spec.rb
  3. 27
      spec/requests/locations_controller_spec.rb
  4. 26
      spec/requests/schemes_controller_spec.rb

2
app/views/schemes/check_answers.html.erb

@ -1,6 +1,6 @@
<% content_for :title, "Check your answers before creating this scheme" %> <% content_for :title, "Check your answers before creating this scheme" %>
<%= render partial: "organisations/headings", locals: { main: "Check your changes before updating this scheme", sub: @scheme.service_name } %> <%= render partial: "organisations/headings", locals: { main: "Check your changes before creating this scheme", sub: @scheme.service_name } %>
<%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %> <%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %>
<% component.tab(label: "Scheme") do %> <% component.tab(label: "Scheme") do %>

4
spec/features/schemes_spec.rb

@ -389,7 +389,7 @@ RSpec.describe "Schemes scheme Features" do
end end
it "lets me check my answers" do it "lets me check my answers" do
expect(page).to have_content "Check your changes before updating this scheme" expect(page).to have_content "Check your changes before creating this scheme"
end end
context "and I select to create a scheme" do context "and I select to create a scheme" do
@ -412,7 +412,7 @@ RSpec.describe "Schemes scheme Features" do
end end
# it "lets me check my answers" do # it "lets me check my answers" do
# expect(page).to have_content "Check your changes before updating this scheme" # expect(page).to have_content "Check your changes before creating this scheme"
# end # end
end end
end end

27
spec/requests/locations_controller_spec.rb

@ -77,5 +77,32 @@ RSpec.describe LocationsController, type: :request do
expect(response).to have_http_status(:unauthorized) expect(response).to have_http_status(:unauthorized)
end end
end end
context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) }
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } }
before do
sign_in user
post "/schemes/#{scheme.id}/location/create", params: params
end
it "creates a new location for scheme with valid params and redirects to correct page" do
expect { post "/schemes/#{scheme.id}/location/create", params: }.to change(Location, :count).by(1)
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your answers before creating this scheme")
end
it "creates a new location for scheme with valid params" do
expect(Location.last.scheme.organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No")
end
end
end end
end end

26
spec/requests/schemes_controller_spec.rb

@ -662,7 +662,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -707,7 +707,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -737,7 +737,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -768,7 +768,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -802,7 +802,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -846,7 +846,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -891,7 +891,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -921,7 +921,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -937,7 +937,7 @@ RSpec.describe SchemesController, type: :request do
it "renders confirm secondary group after successful update" do it "renders confirm secondary group after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -952,7 +952,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -997,7 +997,7 @@ RSpec.describe SchemesController, type: :request do
it "renders check answers page after successful update" do it "renders check answers page after successful update" do
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
it "updates a scheme with valid params" do it "updates a scheme with valid params" do
@ -1310,7 +1310,7 @@ RSpec.describe SchemesController, type: :request do
it "returns a template for a support" do it "returns a template for a support" do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
context "when attempting to access check-answers scheme page for another organisation" do context "when attempting to access check-answers scheme page for another organisation" do
@ -1337,7 +1337,7 @@ RSpec.describe SchemesController, type: :request do
it "returns a template for a support" do it "returns a template for a support" do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Check your changes before updating this scheme") expect(page).to have_content("Check your changes before creating this scheme")
end end
end end
end end

Loading…
Cancel
Save