Skip to content

Commit

Permalink
change location/locality to postcode and add fields to store parish/w…
Browse files Browse the repository at this point in the history
…ard etc.
  • Loading branch information
dereke committed Dec 22, 2019
1 parent e44c42b commit 49b3acb
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 79 deletions.
3 changes: 1 addition & 2 deletions app/controllers/initiatives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def initiative_params
:name,
:summary,
:anticipated_carbon_saving,
:locality,
:location,
:postcode,
:latitude,
:longitude,
:lead_group_id,
Expand Down
16 changes: 14 additions & 2 deletions app/models/initiative.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength
class Initiative < ApplicationRecord
belongs_to :lead_group, class_name: 'Group'
belongs_to :status, class_name: 'InitiativeStatus'
Expand Down Expand Up @@ -104,15 +105,26 @@ def self.create_solution(mapped_solution)
}
end

def location
[parish, ward, district, county, region].join(', ')
end

# rubocop:disable Metrics/MethodLength
def location_attributes
{
name: locality,
address: location,
parish: parish,
ward: ward,
district: district,
county: county,
region: region,
postcode: postcode,
latlng: {
# "Down to Earth Stroud, PO Box 427, Stonehouse, Gloucestershire, GL6 1JG",
lat: latitude,
lng: longitude
}
}
end
# rubocop:enable Metrics/MethodLength
end
# rubocop:enable Metrics/ClassLength
11 changes: 3 additions & 8 deletions app/views/initiatives/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,9 @@

<h2>Location</h2>

<%= f.form_field :locality do %>
<%= f.label :locality %>
<%= f.text_field :locality %>
<% end %>

<%= f.form_field :location do %>
<%= f.label :location %>
<%= f.text_field :location %>
<%= f.form_field :postcode do %>
<%= f.label :postcode %>
<%= f.text_field :postcode %>
<% end %>

<label class="FormField">
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20191222211340_add_location_to_initiatives.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class AddLocationToInitiatives < ActiveRecord::Migration[6.0]
def change
remove_column :initiatives, :locality, :string
remove_column :initiatives, :location, :string

add_column :initiatives, :postcode, :string
add_column :initiatives, :parish, :string
add_column :initiatives, :ward, :string
add_column :initiatives, :district, :string
add_column :initiatives, :county, :string
add_column :initiatives, :region, :string
end
end
10 changes: 7 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_12_21_223723) do
ActiveRecord::Schema.define(version: 2019_12_22_211340) do
# These are extensions that must be enabled in order to support this database
enable_extension 'plpgsql'

Expand Down Expand Up @@ -114,8 +114,6 @@
t.string 'name'
t.string 'summary'
t.integer 'anticipated_carbon_saving'
t.string 'locality'
t.string 'location'
t.bigint 'lead_group_id', null: false
t.string 'contact_name'
t.string 'contact_email'
Expand All @@ -127,6 +125,12 @@
t.float 'latitude'
t.float 'longitude'
t.boolean 'consent_to_share', default: false, null: false
t.string 'postcode'
t.string 'parish'
t.string 'ward'
t.string 'district'
t.string 'county'
t.string 'region'
t.index %w[lead_group_id], name: 'index_initiatives_on_lead_group_id'
t.index %w[status_id], name: 'index_initiatives_on_status_id'
end
Expand Down
58 changes: 41 additions & 17 deletions frontend/packs/initiative_solution_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,17 @@ class SolutionPicker {
<ul>
{this.taxonomy_hierarchy.map(sector => {
return (
<li onclick={() => this.navigate({ sector })}>{sector.name}</li>
<li>
<a
href="#"
onclick={() => {
this.navigate({ sector });
return false;
}}
>
{sector.name}
</a>
</li>
);
})}
</ul>
Expand All @@ -212,15 +222,19 @@ class SolutionPicker {
{this.navigation.sector.themes.map(theme => {
return (
<li class="Taxonomy-item">
<span
<a
class="Taxonomy-itemName"
onclick={() => this.navigate({ theme })}
href="#"
onclick={() => {
this.navigate({ theme });
return false;
}}
>
{theme.name}
</span>
<img
src={plusCircle}
</a>
<a
class="AddInitiativeSolution-add Taxonomy-itemAction"
title={`Add ${theme.name}`}
onclick={() => {
this.addTheme({
sector: this.navigation.sector.name,
Expand All @@ -229,7 +243,9 @@ class SolutionPicker {
});
return false;
}}
/>
>
<img src={plusCircle} />
</a>
</li>
);
})}
Expand All @@ -252,13 +268,19 @@ class SolutionPicker {
<ul>
{this.navigation.theme.classes.map(solutionClass => {
return (
<li
onclick={() => {
this.resetProposedSolution(solutionClass.solution_class_id);
this.navigate({ solutionClass });
}}
>
{solutionClass.name}
<li>
<a
href="#"
onclick={() => {
this.resetProposedSolution(
solutionClass.solution_class_id
);
this.navigate({ solutionClass });
return false;
}}
>
{solutionClass.name}
</a>
</li>
);
})}
Expand Down Expand Up @@ -311,9 +333,9 @@ class SolutionPicker {
<span class="Taxonomy-itemName">
{this.renderSolutionInput(solution)}{" "}
</span>
<img
src={plusCircle}
<a
class="AddInitiativeSolution-add"
title={`Add ${solution.name}`}
onclick={() => {
this.addSolution({
sector: this.navigation.sector.name,
Expand All @@ -326,7 +348,9 @@ class SolutionPicker {
});
return false;
}}
/>
>
<img src={plusCircle} />
</a>
</li>
);
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/styles/components/initiative-solution-picker.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
overflow: hidden;
}

.AddInitiativeSolution-group a {
display: block;
text-decoration: none;
}

.AddInitiativeSolution-clear {
}

Expand Down
6 changes: 6 additions & 0 deletions run_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -e

bundle exec rails test
bundle exec rails test:system
2 changes: 2 additions & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def self.ac_lens_sftp?
using: ENV['GUI'] ? :chrome : :headless_chrome,
screen_size: [1_400, 1_400]

Capybara.enable_aria_label = true

def sign_in_as(user_fixture_name)
user = users user_fixture_name
fill_in 'Email', with: user.email
Expand Down
4 changes: 0 additions & 4 deletions test/controllers/initiatives_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ def create_params(initiative, lead_group: nil, images: nil, solutions: nil)
contact_phone: initiative.contact_phone,
lead_group_id: lead_group ? 'new' : initiative.lead_group_id,
lead_group_attributes: lead_group,
locality: initiative.locality,
location: initiative.location,
name: initiative.name,
partner_groups_role: initiative.partner_groups_role,
status_id: initiative.status_id,
Expand All @@ -159,8 +157,6 @@ def update_params(initiative, images: nil, solutions: nil)
contact_name: initiative.contact_name,
contact_phone: initiative.contact_phone,
lead_group_id: initiative.lead_group_id,
locality: initiative.locality,
location: initiative.location,
name: initiative.name,
partner_groups_role: initiative.partner_groups_role,
status_id: initiative.status_id,
Expand Down
9 changes: 6 additions & 3 deletions test/fixtures/initiatives.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

fruit_exchange:
locality: Stonehouse
location: GL6 1JG
# address:Down to Earth Stroud, PO Box 427, Stonehouse, Gloucestershire, GL6 1JG
postcode: GL6 1JG
parish: Stroud
ward: Stroud Uplands
district: Stroud
county: Gloucestershire
region: South West
latitude: 51.749252
longitude: -2.283587
name: The Fruit Exchange
Expand Down
8 changes: 6 additions & 2 deletions test/models/initiative_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ def expected_initiative_attributes
[
{
location: {
name: 'Stonehouse',
address: 'GL6 1JG',
parish: 'Stroud',
ward: 'Stroud Uplands',
district: 'Stroud',
county: 'Gloucestershire',
region: 'South West',
postcode: 'GL6 1JG',
latlng: { lat: 51.749252, lng: -2.283587 }
},
name: 'The Fruit Exchange',
Expand Down
82 changes: 44 additions & 38 deletions test/system/initiatives_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,51 @@ class InitiativesTest < ApplicationSystemTestCase
assert_selector 'h1', text: 'Initiatives'
end

test 'creating a Initiative' do
visit initiatives_url
sign_in_as :georgie
click_on 'New Initiative'

fill_in 'Name', with: 'Initiative name', match: :first
fill_in 'Summary', with: 'Summary'
fill_in 'Anticipated carbon saving', with: '200'
fill_in 'Contact email', with: '[email protected]', match: :first
fill_in 'Contact name', with: 'contact name', match: :first
fill_in 'Contact phone', with: 'contact phone', match: :first
select 'Down to Earth Stroud', from: 'Lead group'
fill_in 'Locality', with: 'Postcode'
fill_in 'Location', with: 'Parish'
fill_in 'Partner groups role', with: 'Partner role'
select 'Operational', from: 'Status'
click_on 'Create Initiative'

assert_text 'Initiative was successfully created'
if js?
test 'creating a Initiative' do
visit initiatives_url
sign_in_as :georgie
click_on 'New Initiative'

fill_in 'Name', with: 'Initiative name', match: :first
fill_in 'Summary', with: 'Summary'
fill_in 'Anticipated carbon saving', with: '200'
fill_in 'Contact email', with: '[email protected]', match: :first
fill_in 'Contact name', with: 'contact name', match: :first
fill_in 'Contact phone', with: 'contact phone', match: :first
select 'Down to Earth Stroud', from: 'Lead group'
fill_in 'Postcode', with: 'Postcode'
fill_in 'Partner groups role', with: 'Partner role'
select 'Operational', from: 'Status'
click_on 'Energy'
click_by_title 'Add Heating'
click_on 'Create Initiative'

assert_text 'Initiative was successfully created'
end

test 'updating a Initiative' do
visit initiatives_url
sign_in_as :georgie
click_on 'Edit', match: :first

fill_in 'Name', with: 'Initiative name', match: :first
fill_in 'Summary', with: 'Summary'
fill_in 'Anticipated carbon saving', with: '200'
fill_in 'Contact email', with: '[email protected]', match: :first
fill_in 'Contact name', with: 'contact name', match: :first
fill_in 'Contact phone', with: 'contact phone', match: :first
select 'Down to Earth Stroud', from: 'Lead group'
fill_in 'Postcode', with: 'Postcode'
fill_in 'Partner groups role', with: 'Partner role'
select 'Operational', from: 'Status'
click_on 'Update Initiative'

assert_text 'Initiative was successfully updated'
end
end

test 'updating a Initiative' do
visit initiatives_url
sign_in_as :georgie
click_on 'Edit', match: :first

fill_in 'Name', with: 'Initiative name', match: :first
fill_in 'Summary', with: 'Summary'
fill_in 'Anticipated carbon saving', with: '200'
fill_in 'Contact email', with: '[email protected]', match: :first
fill_in 'Contact name', with: 'contact name', match: :first
fill_in 'Contact phone', with: 'contact phone', match: :first
select 'Down to Earth Stroud', from: 'Lead group'
fill_in 'Locality', with: 'Postcode'
fill_in 'Location', with: 'Parish'
fill_in 'Partner groups role', with: 'Partner role'
select 'Operational', from: 'Status'
click_on 'Update Initiative'

assert_text 'Initiative was successfully updated'
def click_by_title(title)
find("a[title='#{title}']").click
end
end

0 comments on commit 49b3acb

Please sign in to comment.