Skip to content

Commit

Permalink
Merge pull request #166 from tvdeyen/standardrb
Browse files Browse the repository at this point in the history
Use standard.rb to lint code
  • Loading branch information
tvdeyen committed Apr 28, 2023
2 parents d28068a + c8c60ca commit 3bf18bd
Show file tree
Hide file tree
Showing 33 changed files with 237 additions and 220 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,16 @@ jobs:
with:
name: Screenshots
path: spec/dummy/tmp/screenshots

Lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
bundler-cache: true
- name: Lint Ruby files
run: bundle exec standardrb
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require: standard

AllCops:
TargetRubyVersion: 3.0

inherit_gem:
standard: config/base.yml
3 changes: 3 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parallel: true
ignore:
- "spec/dummy/**/*"
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ group :test do
end

gem "github_fast_changelog", require: false

gem "standardrb", "~> 1.0", require: false
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => ["alchemy:spec:prepare", :spec]
task default: ["alchemy:spec:prepare", :spec]

Bundler::GemHelper.install_tasks

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/alchemy/admin/user_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UserSessionsController < ::Devise::SessionsController

protect_from_forgery prepend: true

before_action :check_user_count, :only => :new
before_action :check_user_count, only: :new

helper "Alchemy::Admin::Base"

Expand All @@ -19,11 +19,11 @@ def create
authenticate_user!

if user_signed_in?
if session[:redirect_path].blank?
redirect_path = admin_dashboard_path
redirect_path = if session[:redirect_path].blank?
admin_dashboard_path
else
# We have to strip double slashes from beginning of path, because of strange rails/rack bug.
redirect_path = session[:redirect_path].gsub(/\A\/{2,}/, "/")
session[:redirect_path].gsub(/\A\/{2,}/, "/")
end
redirect_to redirect_path,
notice: t(:signed_in, scope: "devise.sessions")
Expand Down
11 changes: 5 additions & 6 deletions app/controllers/alchemy/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Alchemy
module Admin
class UsersController < ResourcesController

before_action :set_roles, except: [:index, :destroy]

load_and_authorize_resource class: Alchemy::User,
Expand All @@ -14,7 +13,7 @@ class UsersController < ResourcesController

def index
@query = User.ransack(params[:q])
@query.sorts = 'login asc' if @query.sorts.empty?
@query.sorts = "login asc" if @query.sorts.empty?
@users = @query.result
.page(params[:page] || 1)
.per(items_per_page)
Expand Down Expand Up @@ -53,7 +52,7 @@ def update
deliver_welcome_mail
render_errors_or_redirect @user,
admin_users_path,
Alchemy.t("User updated", :name => @user.name)
Alchemy.t("User updated", name: @user.name)
end

def destroy
Expand Down Expand Up @@ -92,9 +91,9 @@ def while_signup?
end

def signup_admin_or_redirect
@user.alchemy_roles = %w(admin)
@user.alchemy_roles = %w[admin]
if @user.save
flash[:notice] = Alchemy.t('Successfully signup admin user')
flash[:notice] = Alchemy.t("Successfully signup admin user")
sign_in :user, @user
deliver_welcome_mail
redirect_to admin_pages_path
Expand All @@ -116,7 +115,7 @@ def can_update_role?
end

def deliver_welcome_mail
if @user.valid? && @user.send_credentials == '1'
if @user.valid? && @user.send_credentials == "1"
@user.deliver_welcome_mail
end
end
Expand Down
5 changes: 2 additions & 3 deletions app/mailers/alchemy/notifications.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Alchemy
class Notifications < ActionMailer::Base

default(from: Config.get(:mailer)['mail_from'])
default(from: Config.get(:mailer)["mail_from"])

def member_created(user)
@user = user
Expand All @@ -21,7 +20,7 @@ def alchemy_user_created(user)
)
end

def reset_password_instructions(user, token, opts={})
def reset_password_instructions(user, token, opts = {})
@user = user
@token = token
mail(
Expand Down
8 changes: 4 additions & 4 deletions app/models/alchemy/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class User < ActiveRecord::Base
:password,
:password_confirmation,
:send_credentials,
:tag_list,
:tag_list
]

devise *Alchemy.devise_modules
devise(*Alchemy.devise_modules)

include Alchemy::Taggable

Expand Down Expand Up @@ -86,7 +86,7 @@ def alchemy_roles=(roles_string)
end

def add_role(role)
self.alchemy_roles = self.alchemy_roles.push(role.to_s).uniq
self.alchemy_roles = alchemy_roles.push(role.to_s).uniq
end

# Returns true if the user ahs admin role
Expand Down Expand Up @@ -127,7 +127,7 @@ def fullname(options = {})
if lastname.blank? && firstname.blank?
login
else
options = { flipped: false }.merge(options)
options = {flipped: false}.merge(options)
fullname = options[:flipped] ? "#{lastname}, #{firstname}" : "#{firstname} #{lastname}"
fullname.squeeze(" ").strip
end
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/alchemy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
name: "modules.users",
controller: "/alchemy/admin/users",
action: "index",
icon: "users",
},
icon: "users"
}
})

Alchemy.signup_path = "/admin/signup"
Expand Down
27 changes: 13 additions & 14 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,34 @@
path: Alchemy.admin_path,
constraints: Alchemy.admin_constraints
} do

devise_for :user,
class_name: 'Alchemy::User',
class_name: "Alchemy::User",
singular: :user,
skip: :all,
controllers: {
sessions: 'alchemy/admin/user_sessions',
passwords: 'alchemy/admin/passwords'
sessions: "alchemy/admin/user_sessions",
passwords: "alchemy/admin/passwords"
},
router_name: :alchemy

devise_scope :user do
get '/dashboard' => 'dashboard#index',
get "/dashboard" => "dashboard#index",
:as => :user_root
get '/signup' => 'users#signup',
get "/signup" => "users#signup",
:as => :signup
get '/login' => 'user_sessions#new',
get "/login" => "user_sessions#new",
:as => :login
post '/login' => 'user_sessions#create'
match '/logout' => 'user_sessions#destroy',
:as => :logout, via: Devise.sign_out_via
post "/login" => "user_sessions#create"
match "/logout" => "user_sessions#destroy",
:as => :logout, :via => Devise.sign_out_via

get '/passwords' => 'passwords#new',
get "/passwords" => "passwords#new",
:as => :new_password
get '/passwords/:id/edit/:reset_password_token' => 'passwords#edit',
get "/passwords/:id/edit/:reset_password_token" => "passwords#edit",
:as => :edit_password
post '/passwords' => 'passwords#create',
post "/passwords" => "passwords#create",
:as => :reset_password
patch '/passwords' => 'passwords#update',
patch "/passwords" => "passwords#update",
:as => :update_password
end

Expand Down
2 changes: 1 addition & 1 deletion config/spring.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Spring.application_root = 'spec/dummy'
Spring.application_root = "spec/dummy"
34 changes: 17 additions & 17 deletions db/migrate/20131015124700_create_alchemy_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ class CreateAlchemyUsers < ActiveRecord::Migration[4.2]
def up
return if table_exists?(:alchemy_users)
create_table "alchemy_users" do |t|
t.string "firstname"
t.string "lastname"
t.string "login"
t.string "email"
t.string "language"
t.string "encrypted_password", limit: 128, default: "", null: false
t.string "password_salt", limit: 128, default: "", null: false
t.integer "sign_in_count", default: 0, null: false
t.integer "failed_attempts", default: 0, null: false
t.string "firstname"
t.string "lastname"
t.string "login"
t.string "email"
t.string "language"
t.string "encrypted_password", limit: 128, default: "", null: false
t.string "password_salt", limit: 128, default: "", null: false
t.integer "sign_in_count", default: 0, null: false
t.integer "failed_attempts", default: 0, null: false
t.datetime "last_request_at"
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "creator_id"
t.integer "updater_id"
t.text "cached_tag_list"
t.string "reset_password_token"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "creator_id"
t.integer "updater_id"
t.text "cached_tag_list"
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
end

Expand Down
4 changes: 2 additions & 2 deletions lib/alchemy/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module Alchemy
# === Default modules
#
# [
#. :database_authenticatable,
# . :database_authenticatable,
# :trackable,
# :validatable,
# :timeoutable,
# :recoverable
#. ]
# . ]
#
# If you want to add additional modules into the Alchemy user class append
# them to this collection in an initializer in your app.
Expand Down
12 changes: 6 additions & 6 deletions lib/alchemy/devise/engine.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
require 'alchemy_cms'
require 'devise'
require "alchemy_cms"
require "devise"

module Alchemy
module Devise
class Engine < ::Rails::Engine
isolate_namespace Alchemy
engine_name 'alchemy_devise'
engine_name "alchemy_devise"

initializer "alchemy_devise.user_class", before: "alchemy.userstamp" do
Alchemy.user_class_name = "Alchemy::User"
end

initializer 'alchemy_devise.assets' do |app|
initializer "alchemy_devise.assets" do |app|
app.config.assets.precompile += [
'alchemy-devise.css'
"alchemy-devise.css"
]
end

config.to_prepare do
require_relative '../../../app/controllers/alchemy/base_controller_extension.rb'
require_relative "../../../app/controllers/alchemy/base_controller_extension"
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/alchemy/devise/test_support/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
factory :alchemy_user, class: Alchemy::User do
sequence(:login) { |n| "john_#{n}.doe" }
sequence(:email) { |n| "john_#{n}@doe.com" }
firstname { 'John' }
lastname { 'Doe' }
password { 's3cr3t' }
password_confirmation { 's3cr3t' }
firstname { "John" }
lastname { "Doe" }
password { "s3cr3t" }
password_confirmation { "s3cr3t" }

factory :alchemy_admin_user do
alchemy_roles { 'admin' }
alchemy_roles { "admin" }
end

factory :alchemy_member_user do
alchemy_roles { 'member' }
alchemy_roles { "member" }
end

factory :alchemy_author_user do
alchemy_roles { 'author' }
alchemy_roles { "author" }
end

factory :alchemy_editor_user do
alchemy_roles { 'editor' }
alchemy_roles { "editor" }
end
end
end
8 changes: 4 additions & 4 deletions lib/generators/alchemy/devise/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ module Devise
module Generators
class InstallGenerator < Rails::Generators::Base
desc "Installs Alchemy Devise based authentication into your app."
source_root File.expand_path('templates', File.dirname(__FILE__))
source_root File.expand_path("templates", File.dirname(__FILE__))

def copy_devise_config
template 'devise.rb.tt', 'config/initializers/devise.rb'
template "devise.rb.tt", "config/initializers/devise.rb"
end

def add_migrations
run 'bundle exec rake alchemy_devise:install:migrations'
run "bundle exec rake alchemy_devise:install:migrations"
end

def run_migrations
run 'bundle exec rake db:migrate'
run "bundle exec rake db:migrate"
end

def append_assets
Expand Down

0 comments on commit 3bf18bd

Please sign in to comment.