Browse Source

lint fixes

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

2
Gemfile

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

13
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
def after_sending_reset_password_instructions_path_for(_resource)
confirmations_reset_path(email: params.dig("user", "email")) if is_navigational_format?
end
end

14
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.

1
db/migrate/20211112105348_add_incref_field.rb

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

85
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
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

2
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

Loading…
Cancel
Save