Browse Source

Create merge_request table and paths

pull/1535/head
Kat 3 years ago
parent
commit
7b85d54dd0
  1. 27
      app/controllers/merge_requests_controller.rb
  2. 4
      app/controllers/organisations_controller.rb
  3. 3
      app/models/merge_request.rb
  4. 0
      app/views/merge_requests/organisations.html.erb
  5. 8
      app/views/organisations/merge_request.html.erb
  6. 2
      app/views/organisations/show.html.erb
  7. 7
      config/routes.rb
  8. 9
      db/migrate/20230412111338_add_merge_requests_table.rb
  9. 7
      db/schema.rb
  10. 10
      spec/requests/organisations_controller_spec.rb

27
app/controllers/merge_requests_controller.rb

@ -0,0 +1,27 @@
class MergeRequestsController < ApplicationController
before_action :authenticate_user!
# before_action :authenticate_scope!
def create
@merge_request = MergeRequest.new
end
def create
@merge_request = MergeRequest.create!(merge_request_params)
redirect_to merge_request_organisations_path(@merge_request)
end
def organisations
end
private
def merge_request_params
required_params = {}
required_params[:requesting_organisation] = current_user.organisation
required_params
end
end

4
app/controllers/organisations_controller.rb

@ -137,6 +137,10 @@ class OrganisationsController < ApplicationController
end
end
def merge_request
@merge_request = MergeRequest.new
end
private
def org_params

3
app/models/merge_request.rb

@ -0,0 +1,3 @@
class MergeRequest < ApplicationRecord
belongs_to :requesting_organisation, class_name: "Organisation"
end

0
app/views/merge_requests/organisations.html.erb

8
app/views/organisations/merge.html.erb → app/views/organisations/merge_request.html.erb

@ -40,9 +40,9 @@
</ul>
<%= govuk_warning_text text: "You will not be able to submit your request without the above information. Do not start the form until you have obtained all of the information. " %>
<%= govuk_start_button(
text: "Start now",
href: "#",
) %>
<%= form_for @merge_request, url: merge_requests_path do |f| %>
<%= f.submit "Start now", class: "govuk-button govuk-button--start" %>
<% end %>
</div>
</div>

2
app/views/organisations/show.html.erb

@ -36,7 +36,7 @@
<% end %>
<% end %>
<% if FeatureToggle.merge_organisations_enabled? %>
<p>Is your organisation merging with another? <%= govuk_link_to "Let us know using this form", merge_organisation_path %></p>
<p>Is your organisation merging with another? <%= govuk_link_to "Let us know using this form", merge_request_organisation_path %></p>
<% end %>
</div>

7
config/routes.rb

@ -119,10 +119,15 @@ Rails.application.routes.draw do
get "managing-agents/remove", to: "organisation_relationships#remove_managing_agent"
post "managing-agents", to: "organisation_relationships#create_managing_agent"
delete "managing-agents", to: "organisation_relationships#delete_managing_agent"
get "merge", to: "organisations#merge"
get "merge-request", to: "organisations#merge_request"
end
end
resources :merge_requests, path: "/merge-request" do
post "merge-request", to: "merge_request#create_merge_request"
get "organisations", to: "merge_requests#organisations"
end
resources :lettings_logs, path: "/lettings-logs" do
collection do
post "bulk-upload", to: "bulk_upload#bulk_upload"

9
db/migrate/20230412111338_add_merge_requests_table.rb

@ -0,0 +1,9 @@
class AddMergeRequestsTable < ActiveRecord::Migration[7.0]
def change
create_table :merge_requests do |t|
t.integer :requesting_organisation_id
t.integer :merging_organisations, array: true
t.timestamps
end
end
end

7
db/schema.rb

@ -354,6 +354,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_12_143245) do
t.string "collection"
end
create_table "merge_requests", force: :cascade do |t|
t.integer "requesting_organisation_id"
t.integer "merging_organisations", array: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "organisation_relationships", force: :cascade do |t|
t.integer "child_organisation_id"
t.integer "parent_organisation_id"

10
spec/requests/organisations_controller_spec.rb

@ -230,7 +230,7 @@ RSpec.describe OrganisationsController, type: :request do
it "displays a link to merge organisations" do
expect(page).to have_content("Is your organisation merging with another?")
expect(page).to have_link("Let us know using this form", href: "/organisations/#{organisation.id}/merge")
expect(page).to have_link("Let us know using this form", href: "/organisations/#{organisation.id}/merge-request")
end
end
@ -441,10 +441,10 @@ RSpec.describe OrganisationsController, type: :request do
end
end
describe "#merge" do
fdescribe "#merge" do
context "with an organisation that the user belongs to" do
before do
get "/organisations/#{organisation.id}/merge", headers:, params: {}
get "/organisations/#{organisation.id}/merge-request", headers:, params: {}
end
it "shows the correct content" do
@ -456,13 +456,13 @@ RSpec.describe OrganisationsController, type: :request do
end
it "has a correct start no button" do
expect(page).to have_link("Start now", href: "#")
expect(page).to have_link("Start now", href: "/merge-request/new")
end
end
context "with organisation that are not in scope for the user, i.e. that they do not belong to" do
before do
get "/organisations/#{unauthorised_organisation.id}/merge", headers:, params: {}
get "/organisations/#{unauthorised_organisation.id}/merge-request", headers:, params: {}
end
it "returns not found 404 from org details route" do

Loading…
Cancel
Save