Browse Source

lint fixes

pull/81/head
MadeTech Dushan 3 years ago
parent
commit
f0f75dc48f
  1. 2
      Gemfile
  2. 9
      app/controllers/users/passwords_controller.rb
  3. 14
      config/environments/development.rb
  4. 1
      db/migrate/20211112105348_add_incref_field.rb
  5. 83
      lib/tasks/form_definition.rake
  6. 2
      spec/features/user_spec.rb

2
Gemfile

@ -29,7 +29,7 @@ gem "discard"
gem "activeadmin" gem "activeadmin"
# Admin charts # Admin charts
gem "chartkick" gem "chartkick"
#Json Schema # Json Schema
gem "json-schema" gem "json-schema"
gem "uk_postcode" gem "uk_postcode"
# Authentication # Authentication

9
app/controllers/users/passwords_controller.rb

@ -1,5 +1,4 @@
class Users::PasswordsController < Devise::PasswordsController class Users::PasswordsController < Devise::PasswordsController
def reset_confirmation def reset_confirmation
@email = params["email"] @email = params["email"]
render "devise/confirmations/reset" render "devise/confirmations/reset"
@ -12,9 +11,9 @@ class Users::PasswordsController < Devise::PasswordsController
respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name)) respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
end end
protected protected
def after_sending_reset_password_instructions_path_for(resource) def after_sending_reset_password_instructions_path_for(_resource)
confirmations_reset_path(email: params.dig("user", "email")) if is_navigational_format? confirmations_reset_path(email: params.dig("user", "email")) if is_navigational_format?
end end
end end

14
config/environments/development.rb

@ -44,14 +44,14 @@ Rails.application.configure do
config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com', address: "smtp.gmail.com",
port: 465, port: 465,
domain: 'gmail.com', domain: "gmail.com",
user_name: ENV["CORE_EMAIL_USERNAME"], user_name: ENV["CORE_EMAIL_USERNAME"],
password: ENV["CORE_EMAIL_PASSWORD"], password: ENV["CORE_EMAIL_PASSWORD"],
authentication: 'plain', authentication: "plain",
enable_starttls_auto: true, enable_starttls_auto: true,
ssl: true ssl: true,
} }
# Print deprecation notices to the Rails logger. # Print deprecation notices to the Rails logger.

1
db/migrate/20211112105348_add_incref_field.rb

@ -5,4 +5,3 @@ class AddIncrefField < ActiveRecord::Migration[6.1]
end end
end end
end end

83
lib/tasks/form_definition.rake

@ -1,50 +1,51 @@
require "json" require "json"
require "json-schema" require "json-schema"
# rubocop:disable Lint/ShadowingOuterLocalVariable
def get_all_form_paths(directories) def get_all_form_paths(directories)
form_paths = [] form_paths = []
directories.each do |directory| directories.each do |directory|
Dir.glob("#{directory}/*.json").each do |form_path| Dir.glob("#{directory}/*.json").each do |form_path|
form_paths.push(form_path) form_paths.push(form_path)
end
end end
form_paths end
form_paths
end end
namespace :form_definition do namespace :form_definition do
desc "Validate JSON against Generic Form Schema" desc "Validate JSON against Generic Form Schema"
task :validate do task validate: :environment do
puts "#{Rails.root}" puts Rails.root.to_s
path = "config/forms/schema/generic.json" path = "config/forms/schema/generic.json"
file = File.open(path) file = File.open(path)
schema = JSON.parse(file.read) schema = JSON.parse(file.read)
metaschema = JSON::Validator.validator_for_name("draft4").metaschema metaschema = JSON::Validator.validator_for_name("draft4").metaschema
puts path puts path
if JSON::Validator.validate(metaschema, schema) if JSON::Validator.validate(metaschema, schema)
puts "schema valid" puts "schema valid"
else else
puts "schema not valid" puts "schema not valid"
return return
end end
directories = ["config/forms", "spec/fixtures/forms"] directories = ["config/forms", "spec/fixtures/forms"]
# directories = ["config/forms"] # directories = ["config/forms"]
get_all_form_paths(directories).each do |path| get_all_form_paths(directories).each do |path|
puts path puts path
file = File.open(path) file = File.open(path)
data = JSON.parse(file.read) data = JSON.parse(file.read)
puts JSON::Validator.fully_validate(schema, data, :strict => true) puts JSON::Validator.fully_validate(schema, data, strict: true)
begin begin
JSON::Validator.validate!(schema, data) JSON::Validator.validate!(schema, data)
rescue JSON::Schema::ValidationError => e rescue JSON::Schema::ValidationError => e
e.message e.message
end end
end
end end
end end
end
# rubocop:enable Lint/ShadowingOuterLocalVariable

2
spec/features/user_spec.rb

@ -47,7 +47,7 @@ RSpec.describe "User Features" do
it " is sent a reset password email" do it " is sent a reset password email" do
visit("/users/password/new") visit("/users/password/new")
fill_in("user_email", with: "test@example.com") 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 end
end end

Loading…
Cancel
Save