-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4653 from alphagov/model-organisations
Model organisations
- Loading branch information
Showing
11 changed files
with
175 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
class CaseStudy < ContentItem | ||
include EmphasisedOrganisations | ||
include Updatable | ||
include WorldwideOrganisations | ||
include Organisations | ||
|
||
def contributors | ||
(organisations_ordered_by_emphasis + worldwide_organisations).uniq | ||
contributors_list = (organisations_ordered_by_emphasis + worldwide_organisations).uniq | ||
super(contributors_list) | ||
end | ||
end |
10 changes: 2 additions & 8 deletions
10
app/models/concerns/organisations.rb → ...dels/concerns/emphasised_organisations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Logo | ||
attr_reader :crest, :formatted_title, :image | ||
|
||
def initialize(logo) | ||
@image = get_image(logo["image"]) | ||
@crest = logo["crest"] | ||
@formatted_title = logo["formatted_title"] | ||
end | ||
|
||
def get_image(logo_image) | ||
return unless logo_image | ||
|
||
OpenStruct.new( | ||
alt_text: logo_image["alt_text"], | ||
url: logo_image["url"], | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Organisation < ContentItem | ||
attr_reader :logo | ||
|
||
def initialize(organisation_data) | ||
super(organisation_data) | ||
@logo = Logo.new(organisation_data.dig("details", "logo")) | ||
@organisation_data = organisation_data | ||
end | ||
|
||
def brand | ||
organisation_data.dig("details", "brand") | ||
end | ||
|
||
private | ||
|
||
attr_reader :organisation_data | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
RSpec.describe Logo do | ||
let(:logo) do | ||
{ | ||
"crest" => "dbt", | ||
"formatted_title" => "Department for<br/>Business & Trade", | ||
} | ||
end | ||
|
||
describe "#crest" do | ||
it "gets the crest" do | ||
expect(described_class.new(logo).crest) | ||
.to eq(logo["crest"]) | ||
end | ||
end | ||
|
||
describe "#formatted_title" do | ||
it "gets the formatted title" do | ||
expect(described_class.new(logo).formatted_title) | ||
.to eq(logo["formatted_title"]) | ||
end | ||
end | ||
|
||
describe "#image" do | ||
context "when there is an image" do | ||
let(:logo) do | ||
{ | ||
"formatted_title" => "Forensic Science <br/>Regulator", | ||
"image" => { | ||
"alt_text" => "Forensic Science Regulator", | ||
"url" => "https://example.com/sample.png", | ||
}, | ||
} | ||
end | ||
|
||
it "gets the image alt_text" do | ||
expect(described_class.new(logo).image.alt_text).to eq(logo["image"]["alt_text"]) | ||
end | ||
|
||
it "gets the image url" do | ||
expect(described_class.new(logo).image.url).to eq(logo["image"]["url"]) | ||
end | ||
end | ||
|
||
context "when there is no image" do | ||
it "returns nil" do | ||
expect(described_class.new(logo).image).to be_nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
RSpec.describe Organisation do | ||
let(:content_store_response) do | ||
GovukSchemas::Example.find("organisation", example_name: "organisation") | ||
end | ||
|
||
describe "#brand" do | ||
it "gets the brand" do | ||
expect(described_class.new(content_store_response).brand).not_to be_nil | ||
expect(described_class.new(content_store_response).brand).to eq(content_store_response.dig("details", "brand")) | ||
end | ||
end | ||
|
||
describe "#logo" do | ||
it "gets the logo" do | ||
expect(described_class.new(content_store_response).logo).to be_instance_of(Logo) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters