diff --git a/Gemfile b/Gemfile index f136a5f12..2b84ee40c 100644 --- a/Gemfile +++ b/Gemfile @@ -29,7 +29,7 @@ gem "discard" gem "activeadmin" # Admin charts gem "chartkick" -#Json Schema +# Json Schema gem "json-schema" gem "uk_postcode" # Authentication diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index 68c87a123..a77e5e1f3 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -1,9 +1,8 @@ class Users::PasswordsController < Devise::PasswordsController - def reset_confirmation @email = params["email"] render "devise/confirmations/reset" - end + end def create self.resource = resource_class.send_reset_password_instructions(resource_params) @@ -12,9 +11,9 @@ class Users::PasswordsController < Devise::PasswordsController respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name)) end - protected +protected - def after_sending_reset_password_instructions_path_for(resource) - confirmations_reset_path(email: params.dig("user", "email")) if is_navigational_format? - end -end \ No newline at end of file + def after_sending_reset_password_instructions_path_for(_resource) + confirmations_reset_path(email: params.dig("user", "email")) if is_navigational_format? + end +end diff --git a/config/environments/development.rb b/config/environments/development.rb index 9a0bc479a..bf9761c3a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -44,14 +44,14 @@ Rails.application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { - address: 'smtp.gmail.com', - port: 465, - domain: 'gmail.com', - user_name: ENV["CORE_EMAIL_USERNAME"], - password: ENV["CORE_EMAIL_PASSWORD"], - authentication: 'plain', + address: "smtp.gmail.com", + port: 465, + domain: "gmail.com", + user_name: ENV["CORE_EMAIL_USERNAME"], + password: ENV["CORE_EMAIL_PASSWORD"], + authentication: "plain", enable_starttls_auto: true, - ssl: true + ssl: true, } # Print deprecation notices to the Rails logger. diff --git a/db/migrate/20211112105348_add_incref_field.rb b/db/migrate/20211112105348_add_incref_field.rb index 65df53aca..ece9a458b 100644 --- a/db/migrate/20211112105348_add_incref_field.rb +++ b/db/migrate/20211112105348_add_incref_field.rb @@ -5,4 +5,3 @@ class AddIncrefField < ActiveRecord::Migration[6.1] end end end - diff --git a/lib/tasks/form_definition.rake b/lib/tasks/form_definition.rake index 565728064..3a5128138 100644 --- a/lib/tasks/form_definition.rake +++ b/lib/tasks/form_definition.rake @@ -1,50 +1,51 @@ require "json" require "json-schema" - +# rubocop:disable Lint/ShadowingOuterLocalVariable def get_all_form_paths(directories) - form_paths = [] - directories.each do |directory| - Dir.glob("#{directory}/*.json").each do |form_path| - form_paths.push(form_path) - end + form_paths = [] + directories.each do |directory| + Dir.glob("#{directory}/*.json").each do |form_path| + form_paths.push(form_path) end - form_paths + end + form_paths end namespace :form_definition do - desc "Validate JSON against Generic Form Schema" - task :validate do - puts "#{Rails.root}" - path = "config/forms/schema/generic.json" - - file = File.open(path) - schema = JSON.parse(file.read) - metaschema = JSON::Validator.validator_for_name("draft4").metaschema - - puts path - - if JSON::Validator.validate(metaschema, schema) - puts "schema valid" - else - puts "schema not valid" - return - end - - directories = ["config/forms", "spec/fixtures/forms"] - # directories = ["config/forms"] - - get_all_form_paths(directories).each do |path| - puts path - file = File.open(path) - data = JSON.parse(file.read) - - puts JSON::Validator.fully_validate(schema, data, :strict => true) - - begin - JSON::Validator.validate!(schema, data) - rescue JSON::Schema::ValidationError => e - e.message - end - end + desc "Validate JSON against Generic Form Schema" + task validate: :environment do + puts Rails.root.to_s + path = "config/forms/schema/generic.json" + + file = File.open(path) + schema = JSON.parse(file.read) + metaschema = JSON::Validator.validator_for_name("draft4").metaschema + + puts path + + if JSON::Validator.validate(metaschema, schema) + puts "schema valid" + else + puts "schema not valid" + return end - end \ No newline at end of file + + directories = ["config/forms", "spec/fixtures/forms"] + # directories = ["config/forms"] + + get_all_form_paths(directories).each do |path| + puts path + file = File.open(path) + data = JSON.parse(file.read) + + puts JSON::Validator.fully_validate(schema, data, strict: true) + + begin + JSON::Validator.validate!(schema, data) + rescue JSON::Schema::ValidationError => e + e.message + end + end + end +end +# rubocop:enable Lint/ShadowingOuterLocalVariable diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index d5b245521..3f758ec74 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -47,7 +47,7 @@ RSpec.describe "User Features" do it " is sent a reset password email" do visit("/users/password/new") fill_in("user_email", with: "test@example.com") - expect{click_button("Send email")}.to change{ActionMailer::Base.deliveries.count}.by(1) + expect { click_button("Send email") }.to change { ActionMailer::Base.deliveries.count }.by(1) end end end