diff --git a/.exrc b/.exrc index 6edac40..e1fc3b0 100644 --- a/.exrc +++ b/.exrc @@ -1,9 +1,29 @@ -let g:vigun_extra_keywords = ['test'] +let g:vigun_test_keywords = ['test', 'it', 'context', 'describe'] +let g:vjs_tags_enabled = 0 -let g:vigun_commands = [ +fun! s:watch(cmd) + return "rg --files | entr -r -c sh -c 'echo ".escape('"'.a:cmd.'"', '"')." && ".a:cmd."'" +endf + +let g:vigun_mappings = [ + \ { + \ 'pattern': 'test/.*_test.rb$', + \ 'all': 'rails test #{file}', + \ 'nearest': 'rails test #{file}:#{line}', + \ 'watch-all': s:watch('rails test #{file}'), + \ 'watch-nearest': s:watch('rails test #{file}:#{line}'), + \ }, \ { - \ 'pattern': 'test/.*_test.rb$', - \ 'normal': 'rails test', - \ 'debug': 'BACKTRACE=1 rails test', + \ 'pattern': 'test/javascript/.*_test.js$', + \ 'all': 'yarn test #{file}', + \ 'nearest': 'yarn test --fgrep #{nearest_test} #{file}', + \ 'debug-all': 'yarn test --interactive #{file}', + \ 'debug-nearest': 'yarn test --interactive --fgrep #{nearest_test} #{file}', \ } \] + +command! -nargs=0 Fixturex :cexpr system('./bin/fixturex.rb '. expand('%:t:r') .' '.shellescape(expand(''))) | copen + +" open report fixture in a split to the right +" nnoremap gj :exec "botright vnew +" test/fixtures/reports/".expand('').".json" diff --git a/.gitignore b/.gitignore index 03b6b8b..0a6875c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # Ignore bundler config. /.bundle +vendor/bundle/**/*.* # Ignore the default SQLite database. /db/*.sqlite3* diff --git a/Gemfile.lock b/Gemfile.lock index f8ba890..8f61b85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -375,4 +375,4 @@ RUBY VERSION ruby 2.6.5p114 BUNDLED WITH - 2.1.4 + 2.2.5 diff --git a/app/controllers/initiatives_controller.rb b/app/controllers/initiatives_controller.rb index 68fc572..2787fd6 100644 --- a/app/controllers/initiatives_controller.rb +++ b/app/controllers/initiatives_controller.rb @@ -2,6 +2,8 @@ # rubocop:disable Metrics/ClassLength class InitiativesController < ApplicationController + include ApplicationHelper + before_action :set_initiative, only: %i[edit update] before_action :set_edit_data, only: %i[edit new create update] skip_before_action :authenticate_user!, only: %i[index show] @@ -36,6 +38,7 @@ def new def edit @current_initiative_step = (params[:step] || 1).to_i + @initiative.websites << InitiativeWebsite.new if @initiative.websites.empty? end # rubocop:disable Metrics/MethodLength @@ -43,7 +46,6 @@ def create @initiative = Initiative.new(initiative_params.merge(owner: current_user)) add_solutions(@initiative) find_or_create_group - @initiative.update_location_from_postcode if @initiative.save(validate: @initiative.publication_status != 'draft') redirect_to edit_initiative_step_path(@initiative, step: 2) @@ -69,7 +71,7 @@ def update @initiative.assign_attributes initiative_params @initiative.update_location_from_postcode - if @initiative.save(validate: publication_status != 'draft') + if @initiative.save(validate: @initiative.publication_status != 'draft') @initiative.images.attach images if images if (params[:step] || '').empty? redirect_to initiative_path(@initiative), @@ -78,6 +80,7 @@ def update redirect_to edit_initiative_step_path(@initiative, step: params[:step]) end else + @current_initiative_step = params[:step].blank? ? 1 : params[:step].to_i - 1 render :edit end end diff --git a/app/helpers/suit_form_builder.rb b/app/helpers/suit_form_builder.rb index 2ef7e1e..1ea2617 100644 --- a/app/helpers/suit_form_builder.rb +++ b/app/helpers/suit_form_builder.rb @@ -10,9 +10,9 @@ def form_field(field, options = {}, &block) css_classes << 'FormField--required' if required css_classes << 'is-error' if field_errors.any? css_classes << options[:class_names] - # rubocop:disable HelperInstanceVariable - @template.content_tag :div, class: css_classes, &block - # rubocop:enable HelperInstanceVariable + # rubocop:disable Rails/HelperInstanceVariable + @template.tag.div(class: css_classes, &block) + # rubocop:enable Rails/HelperInstanceVariable end def label(method, text = nil, options = {}) @@ -41,9 +41,9 @@ def check_box(attribute, options = {}, checked_value = '1', unchecked_value = '0 end label(attribute, class: 'FormField-check FormField-check--checkbox') do super(attribute, options.reverse_merge(class: 'FormField-checkInput'), checked_value, unchecked_value) + - # rubocop:disable HelperInstanceVariable - @template.content_tag(:span, label_text, class: 'FormField-checkLabel') - # rubocop:enable HelperInstanceVariable + # rubocop:disable Rails/HelperInstanceVariable + @template.tag.span(label_text, class: 'FormField-checkLabel') + # rubocop:enable Rails/HelperInstanceVariable end end diff --git a/app/models/group_website.rb b/app/models/group_website.rb index fe7bfcd..6c9cf14 100644 --- a/app/models/group_website.rb +++ b/app/models/group_website.rb @@ -2,7 +2,7 @@ class GroupWebsite < ApplicationRecord belongs_to :group - validates :url, format: URI.regexp(%w[http https]) + validates :url, format: URI::DEFAULT_PARSER.make_regexp(%w[http https]) include Website delegate :name, prefix: true, to: :group end diff --git a/app/models/initiative.rb b/app/models/initiative.rb index 7655680..8718763 100644 --- a/app/models/initiative.rb +++ b/app/models/initiative.rb @@ -6,18 +6,19 @@ class Initiative < ApplicationRecord after_initialize :set_default_location after_initialize :set_default_publication_status + before_save :remove_empty_websites belongs_to :owner, class_name: 'User' belongs_to :lead_group, class_name: 'Group' belongs_to :status, class_name: 'InitiativeStatus' belongs_to :parish - delegate :name, prefix: true, to: :status - delegate :name, prefix: true, to: :lead_group - delegate :ward, to: :parish - delegate :district, to: :ward - delegate :county, to: :district - delegate :region, to: :county + delegate :name, prefix: true, to: :status, allow_nil: true + delegate :name, prefix: true, to: :lead_group, allow_nil: true + delegate :ward, to: :parish, allow_nil: true + delegate :district, to: :ward, allow_nil: true + delegate :county, to: :district, allow_nil: true + delegate :region, to: :county, allow_nil: true has_many :solutions, class_name: 'InitiativeSolution', dependent: :destroy has_many :themes, class_name: 'InitiativeTheme', dependent: :destroy @@ -111,11 +112,11 @@ def location # rubocop:disable Metrics/MethodLength def location_attributes { - parish: parish.name, - ward: ward.name, - district: district.name, - county: county.name, - region: region.name, + parish: parish&.name, + ward: ward&.name, + district: district&.name, + county: county&.name, + region: region&.name, postcode: postcode, latlng: { # "Down to Earth Stroud, PO Box 427, Stonehouse, Gloucestershire, GL6 1JG", @@ -130,6 +131,10 @@ def carbon_saving_quantified? carbon_saving_amount&.positive? end + def remove_empty_websites + websites.delete(websites.select { |website| website.url.blank? }) + end + private def set_default_location diff --git a/app/models/initiative_website.rb b/app/models/initiative_website.rb index abf5472..dc1b405 100644 --- a/app/models/initiative_website.rb +++ b/app/models/initiative_website.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class InitiativeWebsite < ApplicationRecord - validates :url, format: URI.regexp(%w[http https]) + validates :url, format: URI::DEFAULT_PARSER.make_regexp(%w[http https]) include Website belongs_to :initiative diff --git a/app/models/public_initiative.rb b/app/models/public_initiative.rb index 30ab8c0..0bb89df 100644 --- a/app/models/public_initiative.rb +++ b/app/models/public_initiative.rb @@ -3,7 +3,8 @@ # The publicly available data of an initiative class PublicInitiative include ActionView::Helpers::DateHelper - delegate :name, + delegate :id, + :name, :description_what, :description_how, :description_further_information, @@ -70,7 +71,7 @@ def websites end def last_updated - time_ago_in_words(timestamp) + ' ago' + "#{time_ago_in_words(timestamp)} ago" end def href @@ -81,6 +82,7 @@ def href # rubocop:disable Metrics/AbcSize def as_json(_options = {}) { + 'id': id, 'name': name, 'description_what': description_what, 'description_how': description_how, diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index d857803..9644b9e 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,4 +1,4 @@ -<%= javascript_packs_with_chunks_tag 'explore_tabs', 'data-turbolinks-track': 'reload' %> +<%= javascript_packs_with_chunks_tag 'home', 'data-turbolinks-track': 'reload' %>

We share community-based projects that work towards a Carbon Neutral Stroud District by 2030 and connect groups organising them.

Share knowledge. Enable Change

@@ -16,13 +16,9 @@ Or -
+
-
@@ -75,7 +71,7 @@ <% @initiatives.each do |initiative| %> - + <%= link_to initiative.name, initiative_path(initiative) %> <%= initiative.location %> <%= initiative.status_name %> diff --git a/app/views/initiatives/_form.html.erb b/app/views/initiatives/_form.html.erb index 05e9c2b..7890d6c 100644 --- a/app/views/initiatives/_form.html.erb +++ b/app/views/initiatives/_form.html.erb @@ -103,6 +103,7 @@ <%= f.form_field :contact_email, required: true do %> <%= f.label :contact_email, 'Email address to contact about this project' %> +
Find out <%= link_to 'how we use your email address', :privacy%>
<%= f.text_field :contact_email, placeholder: 'Email address' %> <% end %> @@ -119,28 +120,18 @@ <%= f.check_box :consent_to_share_phone, 'Make this phone number public. (Please ensure you have permission to share it first)' %> <% end %> -

Website & Social Media

+ <%= f.label :website, 'Website(s) or social media links for further project info' %>
- - - - - - - - - - <%= f.fields_for :websites do |website_form| %> - <%= render 'partials/website_fields_row', f: website_form %> - <% end %> - -
WebsiteDelete?
-
-
- <%= f.fields_for :websites, InitiativeWebsite.new do |website_form| %> - <%= add_object_link 'Add website', 'initiative_websites', :partial => 'partials/website_fields_row', :locals => { :f => website_form } %> + <%= f.fields_for :websites do |website_form| %> + <%= website_form.form_field :url do %> + <%= website_form.text_field :url, placeholder: 'eg: https://twitter.com/carbon-map' %> + <% end %> <% end %> + <%= javascript_packs_with_chunks_tag 'initiative_websites', 'data-turbolinks-track': 'reload' %>
+ + Add another"> + <% end %> <%= initiative_step 5, @current_initiative_step, title: 'Help us understand how you got going', next_text: 'Next: project sector and notes' do %> diff --git a/app/views/layouts/_base.html.erb b/app/views/layouts/_base.html.erb index b5a61a6..2a07851 100644 --- a/app/views/layouts/_base.html.erb +++ b/app/views/layouts/_base.html.erb @@ -115,9 +115,8 @@ set_meta_tags og: { - +