Browse Source

further refactorings

pull/671/head
JG 3 years ago
parent
commit
79ed7f6a8f
  1. 16
      app/models/scheme.rb
  2. 2
      app/views/schemes/_scheme_list.html.erb
  3. 10
      spec/features/schemes_spec.rb
  4. 20
      spec/requests/organisations_controller_spec.rb
  5. 14
      spec/requests/schemes_controller_spec.rb

16
app/models/scheme.rb

@ -1,6 +1,4 @@
class Scheme < ApplicationRecord class Scheme < ApplicationRecord
before_create :create_code
belongs_to :organisation belongs_to :organisation
has_many :locations has_many :locations
has_many :case_logs has_many :case_logs
@ -87,9 +85,13 @@ class Scheme < ApplicationRecord
enum intended_stay: INTENDED_STAY, _suffix: true enum intended_stay: INTENDED_STAY, _suffix: true
enum has_other_client_group: HAS_OTHER_CLIENT_GROUP, _suffix: true enum has_other_client_group: HAS_OTHER_CLIENT_GROUP, _suffix: true
def id_to_display
"S#{id}"
end
def check_details_attributes def check_details_attributes
[ [
{ name: "Service code", value: code }, { name: "Service code", value: id_to_display },
{ name: "Name", value: service_name }, { name: "Name", value: service_name },
{ name: "Confidential information", value: sensitive }, { name: "Confidential information", value: sensitive },
{ name: "Managed by", value: organisation.name }, { name: "Managed by", value: organisation.name },
@ -126,7 +128,7 @@ class Scheme < ApplicationRecord
def display_attributes def display_attributes
[ [
{ name: "Service code", value: code }, { name: "Service code", value: id_to_display },
{ name: "Name", value: service_name }, { name: "Name", value: service_name },
{ name: "Confidential information", value: sensitive }, { name: "Confidential information", value: sensitive },
{ name: "Managed by", value: organisation.name }, { name: "Managed by", value: organisation.name },
@ -139,10 +141,4 @@ class Scheme < ApplicationRecord
{ name: "Intended length of stay", value: intended_stay }, { name: "Intended length of stay", value: intended_stay },
] ]
end end
private
def create_code
self.code = Scheme.last.nil? ? "S1" : "S#{Scheme.last.code[1..].to_i + 1}"
end
end end

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

@ -22,7 +22,7 @@
<% @schemes.each do |scheme| %> <% @schemes.each do |scheme| %>
<%= table.body do |body| %> <%= table.body do |body| %>
<%= body.row do |row| %> <%= body.row do |row| %>
<% row.cell(text: scheme.code) %> <% row.cell(text: scheme.id_to_display) %>
<% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: scheme.organisation.name) %> <% row.cell(text: scheme.organisation.name) %>
<% row.cell(text: scheme.created_at.to_formatted_s(:govuk_date)) %> <% row.cell(text: scheme.created_at.to_formatted_s(:govuk_date)) %>

10
spec/features/schemes_spec.rb

@ -25,7 +25,7 @@ RSpec.describe "Schemes scheme Features" do
it "shows list of schemes" do it "shows list of schemes" do
schemes.each do |scheme| schemes.each do |scheme|
expect(page).to have_content(scheme.code) expect(page).to have_content(scheme.id)
end end
end end
@ -53,9 +53,9 @@ RSpec.describe "Schemes scheme Features" do
it "displays all schemes after I clear the search results" do it "displays all schemes after I clear the search results" do
click_link("Clear search") click_link("Clear search")
expect(page).to have_content(scheme_to_search.code) expect(page).to have_content(scheme_to_search.id)
schemes.each do |scheme| schemes.each do |scheme|
expect(page).to have_content(scheme.code) expect(page).to have_content(scheme.id)
end end
end end
end end
@ -100,7 +100,7 @@ RSpec.describe "Schemes scheme Features" do
it "shows list of schemes" do it "shows list of schemes" do
schemes.each do |scheme| schemes.each do |scheme|
expect(page).to have_content(scheme.code) expect(page).to have_content(scheme.id)
end end
end end
@ -130,7 +130,7 @@ RSpec.describe "Schemes scheme Features" do
click_link("Clear search") click_link("Clear search")
expect(page).to have_content(scheme_to_search.code) expect(page).to have_content(scheme_to_search.code)
schemes.each do |scheme| schemes.each do |scheme|
expect(page).to have_content(scheme.code) expect(page).to have_content(scheme.id)
end end
end end
end end

20
spec/requests/organisations_controller_spec.rb

@ -65,15 +65,15 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "shows only schemes belonging to the same organisation" do it "shows only schemes belonging to the same organisation" do
expect(page).to have_content(same_org_scheme.code) expect(page).to have_content(same_org_scheme.id)
schemes.each do |scheme| schemes.each do |scheme|
expect(page).not_to have_content(scheme.code) expect(page).not_to have_content(scheme.id)
end end
end end
context "when searching" do context "when searching" do
let!(:searched_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } let!(:searched_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) }
let(:search_param) { searched_scheme.code } let(:search_param) { searched_scheme.id }
before do before do
FactoryBot.create(:location, scheme: searched_scheme) FactoryBot.create(:location, scheme: searched_scheme)
@ -82,9 +82,9 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "returns matching results" do it "returns matching results" do
expect(page).to have_content(searched_scheme.code) expect(page).to have_content(searched_scheme.id)
schemes.each do |scheme| schemes.each do |scheme|
expect(page).not_to have_content(scheme.code) expect(page).not_to have_content(scheme.id)
end end
end end
@ -122,9 +122,9 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "shows only schemes belonging to the same organisation" do it "shows only schemes belonging to the same organisation" do
expect(page).to have_content(same_org_scheme.code) expect(page).to have_content(same_org_scheme.id)
schemes.each do |scheme| schemes.each do |scheme|
expect(page).not_to have_content(scheme.code) expect(page).not_to have_content(scheme.id)
end end
end end
@ -142,7 +142,7 @@ RSpec.describe OrganisationsController, type: :request do
context "when searching" do context "when searching" do
let!(:searched_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } let!(:searched_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) }
let(:search_param) { searched_scheme.code } let(:search_param) { searched_scheme.id }
before do before do
FactoryBot.create(:location, scheme: searched_scheme) FactoryBot.create(:location, scheme: searched_scheme)
@ -150,9 +150,9 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "returns matching results" do it "returns matching results" do
expect(page).to have_content(searched_scheme.code) expect(page).to have_content(searched_scheme.id)
schemes.each do |scheme| schemes.each do |scheme|
expect(page).not_to have_content(scheme.code) expect(page).not_to have_content(scheme.id)
end end
end end

14
spec/requests/schemes_controller_spec.rb

@ -56,7 +56,7 @@ RSpec.describe SchemesController, type: :request do
it "shows all schemes" do it "shows all schemes" do
schemes.each do |scheme| schemes.each do |scheme|
expect(page).to have_content(scheme.code) expect(page).to have_content(scheme.id)
end end
end end
@ -145,9 +145,9 @@ RSpec.describe SchemesController, type: :request do
end end
it "returns matching results" do it "returns matching results" do
expect(page).to have_content(searched_scheme.code) expect(page).to have_content(searched_scheme.id)
schemes.each do |scheme| schemes.each do |scheme|
expect(page).not_to have_content(scheme.code) expect(page).not_to have_content(scheme.id)
end end
end end
@ -196,11 +196,11 @@ RSpec.describe SchemesController, type: :request do
it "has page heading" do it "has page heading" do
get "/schemes/#{specific_scheme.id}" get "/schemes/#{specific_scheme.id}"
expect(page).to have_content(specific_scheme.code) expect(page).to have_content(specific_scheme.id)
expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.service_name)
expect(page).to have_content(specific_scheme.organisation.name) expect(page).to have_content(specific_scheme.organisation.name)
expect(page).to have_content(specific_scheme.sensitive) expect(page).to have_content(specific_scheme.sensitive)
expect(page).to have_content(specific_scheme.code) expect(page).to have_content(specific_scheme.id)
expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.service_name)
expect(page).to have_content(specific_scheme.sensitive) expect(page).to have_content(specific_scheme.sensitive)
expect(page).to have_content(specific_scheme.scheme_type) expect(page).to have_content(specific_scheme.scheme_type)
@ -230,11 +230,11 @@ RSpec.describe SchemesController, type: :request do
end end
it "has page heading" do it "has page heading" do
expect(page).to have_content(specific_scheme.code) expect(page).to have_content(specific_scheme.id)
expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.service_name)
expect(page).to have_content(specific_scheme.organisation.name) expect(page).to have_content(specific_scheme.organisation.name)
expect(page).to have_content(specific_scheme.sensitive) expect(page).to have_content(specific_scheme.sensitive)
expect(page).to have_content(specific_scheme.code) expect(page).to have_content(specific_scheme.id)
expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.service_name)
expect(page).to have_content(specific_scheme.sensitive) expect(page).to have_content(specific_scheme.sensitive)
expect(page).to have_content(specific_scheme.scheme_type) expect(page).to have_content(specific_scheme.scheme_type)

Loading…
Cancel
Save