-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: kiqr_routes and kiqr_flash_message
- Loading branch information
Showing
16 changed files
with
138 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class KiqrController < ApplicationController | ||
private | ||
|
||
def kiqr_flash_message(type, message) | ||
flash[type] = I18n.t("kiqr.flash_messages.#{message}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
en: | ||
kiqr: | ||
flash_messages: | ||
account_created: "Your account has been created successfully." | ||
account_updated: "Your account has been updated successfully." | ||
accounts: | ||
new: | ||
title: "Create a new team account" | ||
description: "Complete the form below to create a new team account" | ||
edit: | ||
title: "Profile settings" | ||
description: "Edit your account profile." | ||
select: | ||
title: "Select account" | ||
description: "Select a team account to manage." | ||
continue_as: "Continue as %{name}" | ||
or: "or" | ||
form: | ||
name: | ||
personal: "Your full name" | ||
team: "Team / organization name" | ||
button: | ||
save: "Save changes" | ||
create: "Create new account" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require "kiqr/rails/routes" | ||
|
||
module Kiqr | ||
class Engine < ::Rails::Engine | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module ActionDispatch | ||
module Routing | ||
class Mapper | ||
def kiqr_routes(options = {}) | ||
# Set default options for controllers if not set. | ||
options = default_controllers(options) | ||
|
||
account_routes(options) | ||
devise_routes(options) | ||
end | ||
|
||
private | ||
|
||
# => Default controllers | ||
# Set default options for controllers if not set. | ||
def default_controllers(options) | ||
options[:controllers] ||= {} | ||
options[:controllers][:accounts] ||= "kiqr/accounts" | ||
options[:controllers][:sessions] ||= "users/sessions" | ||
options[:controllers][:registrations] ||= "users/registrations" | ||
options | ||
end | ||
|
||
# => Account routes | ||
def account_routes(options) | ||
resources :accounts, controller: options[:controllers][:accounts], only: [:new, :create] | ||
get "select-account", controller: options[:controllers][:accounts], action: :select, as: :select_account | ||
|
||
scope "(/team/:account_id)", account_id: %r{[^/]+} do | ||
resource :account, only: [:edit, :update], path: "profile", controller: options[:controllers][:accounts] | ||
end | ||
end | ||
|
||
# => Authentication routes | ||
def devise_routes(options) | ||
devise_for :users, path_names: {sign_in: "login", sign_up: "create-account"}, controllers: { | ||
registrations: options[:controllers][:registrations], | ||
sessions: options[:controllers][:sessions] | ||
} | ||
end | ||
|
||
# => Teamable routes | ||
# Routes inside this block will be prefixed with /team/<team_id> if | ||
# the user is signed in to a team account. Otherwise, they won't be prefixed at all. | ||
def teamable_scope(&) | ||
scope "(/team/:account_id)", account_id: %r{[^/]+} do | ||
yield | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require "test_helper" | ||
|
||
class RoutingTest < ActionDispatch::IntegrationTest | ||
include ActionDispatch::Routing::UrlFor | ||
include Rails.application.routes.url_helpers | ||
|
||
setup do | ||
@routes = Rails.application.routes | ||
end | ||
|
||
test "kiqr routes setup default controllers" do | ||
assert_recognizes({controller: "kiqr/accounts", action: "new"}, "/accounts/new") | ||
assert_recognizes({controller: "kiqr/accounts", action: "select"}, "/select-account") | ||
# assert_recognizes({controller: "users/sessions", action: "new"}, "/users/login") | ||
end | ||
|
||
test "account routes are correctly configured" do | ||
assert_routing "/accounts/new", {controller: "kiqr/accounts", action: "new"} | ||
assert_routing "/select-account", {controller: "kiqr/accounts", action: "select"} | ||
assert_routing({method: "post", path: "/accounts"}, {controller: "kiqr/accounts", action: "create"}) | ||
end | ||
|
||
# test "devise routes for users are correctly configured" do | ||
# assert_routing "/users/login", {controller: "users/sessions", action: "new"} | ||
# assert_routing "/users/create-account", {controller: "users/registrations", action: "new"} | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters