Révision | 0445b3e73ebc342e818bea9a09c5e6da331cb229 (tree) |
---|---|
l'heure | 2017-07-25 00:31:16 |
Auteur | HMML <hmml3939@gmai...> |
Commiter | HMML |
Add user with cancancan and devise.
@@ -47,6 +47,8 @@ gem 'yaml_db' | ||
47 | 47 | gem 'awesome_print' |
48 | 48 | gem 'webpacker', '~> 2.0' |
49 | 49 | gem 'webpacker-react', "~> 0.3.1" |
50 | +gem 'cancancan' | |
51 | +gem 'devise' | |
50 | 52 | |
51 | 53 | group :development, :test do |
52 | 54 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console |
@@ -54,6 +54,7 @@ GEM | ||
54 | 54 | autoprefixer-rails (7.1.2.2) |
55 | 55 | execjs |
56 | 56 | awesome_print (1.8.0) |
57 | + bcrypt (3.1.11) | |
57 | 58 | better_errors (2.1.1) |
58 | 59 | coderay (>= 1.0.0) |
59 | 60 | erubis (>= 2.6.6) |
@@ -66,6 +67,7 @@ GEM | ||
66 | 67 | sass (>= 3.3.4) |
67 | 68 | builder (3.2.3) |
68 | 69 | byebug (9.0.6) |
70 | + cancancan (2.0.0) | |
69 | 71 | capistrano (3.8.2) |
70 | 72 | airbrussh (>= 1.0.0) |
71 | 73 | i18n |
@@ -106,6 +108,12 @@ GEM | ||
106 | 108 | delayed_job_active_record (4.1.2) |
107 | 109 | activerecord (>= 3.0, < 5.2) |
108 | 110 | delayed_job (>= 3.0, < 5) |
111 | + devise (4.3.0) | |
112 | + bcrypt (~> 3.0) | |
113 | + orm_adapter (~> 0.1) | |
114 | + railties (>= 4.1.0, < 5.2) | |
115 | + responders | |
116 | + warden (~> 1.2.3) | |
109 | 117 | diff-lcs (1.3) |
110 | 118 | enum_help (0.0.17) |
111 | 119 | activesupport (>= 3.0.0) |
@@ -215,6 +223,7 @@ GEM | ||
215 | 223 | notiffany (0.1.1) |
216 | 224 | nenv (~> 0.1) |
217 | 225 | shellany (~> 0.0) |
226 | + orm_adapter (0.5.0) | |
218 | 227 | pg (0.18.4) |
219 | 228 | pry (0.10.4) |
220 | 229 | coderay (~> 1.1.0) |
@@ -350,6 +359,8 @@ GEM | ||
350 | 359 | thread_safe (~> 0.1) |
351 | 360 | uglifier (3.2.0) |
352 | 361 | execjs (>= 0.3.0, < 3) |
362 | + warden (1.2.7) | |
363 | + rack (>= 1.0) | |
353 | 364 | web-console (3.5.1) |
354 | 365 | actionview (>= 5.0) |
355 | 366 | activemodel (>= 5.0) |
@@ -383,6 +394,7 @@ DEPENDENCIES | ||
383 | 394 | binding_of_caller |
384 | 395 | bootstrap-sass |
385 | 396 | byebug |
397 | + cancancan | |
386 | 398 | capistrano-bundler |
387 | 399 | capistrano-deploy_into_docker (>= 0.2.1) |
388 | 400 | capistrano-rails |
@@ -390,6 +402,7 @@ DEPENDENCIES | ||
390 | 402 | coffee-rails (~> 4.2) |
391 | 403 | database_cleaner |
392 | 404 | delayed_job_active_record |
405 | + devise | |
393 | 406 | enum_help |
394 | 407 | factory_girl_rails (>= 4.0.0) |
395 | 408 | faker |
@@ -0,0 +1,3 @@ | ||
1 | +# Place all the behaviors and hooks related to the matching controller here. | |
2 | +# All this logic will automatically be available in application.js. | |
3 | +# You can use CoffeeScript in this file: http://coffeescript.org/ |
@@ -1,17 +1,16 @@ | ||
1 | 1 | body { |
2 | 2 | background-color: #fff; |
3 | 3 | color: #333; |
4 | + margin: 33px; | |
4 | 5 | font-family: verdana, arial, helvetica, sans-serif; |
5 | 6 | font-size: 13px; |
6 | 7 | line-height: 18px; |
7 | - margin: 33px; | |
8 | 8 | } |
9 | 9 | |
10 | 10 | p, ol, ul, td { |
11 | 11 | font-family: verdana, arial, helvetica, sans-serif; |
12 | 12 | font-size: 13px; |
13 | 13 | line-height: 18px; |
14 | - margin: 33px; | |
15 | 14 | } |
16 | 15 | |
17 | 16 | pre { |
@@ -38,9 +37,7 @@ th { | ||
38 | 37 | } |
39 | 38 | |
40 | 39 | td { |
41 | - padding-bottom: 7px; | |
42 | - padding-left: 5px; | |
43 | - padding-right: 5px; | |
40 | + padding: 0 5px 7px; | |
44 | 41 | } |
45 | 42 | |
46 | 43 | div { |
@@ -62,8 +59,7 @@ div { | ||
62 | 59 | #error_explanation { |
63 | 60 | width: 450px; |
64 | 61 | border: 2px solid red; |
65 | - padding: 7px; | |
66 | - padding-bottom: 0; | |
62 | + padding: 7px 7px 0; | |
67 | 63 | margin-bottom: 20px; |
68 | 64 | background-color: #f0f0f0; |
69 | 65 |
@@ -72,8 +68,7 @@ div { | ||
72 | 68 | font-weight: bold; |
73 | 69 | padding: 5px 5px 5px 15px; |
74 | 70 | font-size: 12px; |
75 | - margin: -7px; | |
76 | - margin-bottom: 0; | |
71 | + margin: -7px -7px 0; | |
77 | 72 | background-color: #c00; |
78 | 73 | color: #fff; |
79 | 74 | } |
@@ -0,0 +1,3 @@ | ||
1 | +// Place all the styles related to the Users controller here. | |
2 | +// They will automatically be included in application.css. | |
3 | +// You can use Sass (SCSS) here: http://sass-lang.com/ |
@@ -19,8 +19,4 @@ class ApplicationController < ActionController::Base | ||
19 | 19 | def _log(level, msg) |
20 | 20 | logger.public_send level, "#{msg} (addr: #{request.remote_ip}, ua: #{request.user_agent})" |
21 | 21 | end |
22 | - | |
23 | - def current_user | |
24 | - :todo | |
25 | - end | |
26 | 22 | end |
@@ -1,10 +1,7 @@ | ||
1 | 1 | class AreasController < ApplicationController |
2 | - before_action :set_area, only: [:show, :edit, :update, :destroy] | |
3 | - | |
4 | - respond_to :html | |
2 | + load_and_authorize_resource | |
5 | 3 | |
6 | 4 | def index |
7 | - @areas = Area.all | |
8 | 5 | respond_with(@areas) |
9 | 6 | end |
10 | 7 |
@@ -13,7 +10,6 @@ class AreasController < ApplicationController | ||
13 | 10 | end |
14 | 11 | |
15 | 12 | def new |
16 | - @area = Area.new | |
17 | 13 | respond_with(@area) |
18 | 14 | end |
19 | 15 |
@@ -21,7 +17,6 @@ class AreasController < ApplicationController | ||
21 | 17 | end |
22 | 18 | |
23 | 19 | def create |
24 | - @area = Area.new(area_params) | |
25 | 20 | @area.save |
26 | 21 | respond_with(@area) |
27 | 22 | end |
@@ -37,11 +32,11 @@ class AreasController < ApplicationController | ||
37 | 32 | end |
38 | 33 | |
39 | 34 | private |
40 | - def set_area | |
41 | - @area = Area.find(params[:id]) | |
42 | - end | |
35 | + def set_area | |
36 | + @area = Area.find(params[:id]) | |
37 | + end | |
43 | 38 | |
44 | - def area_params | |
45 | - params.require(:area).permit(:ns, :code, :country, :pref, :name) | |
46 | - end | |
39 | + def area_params | |
40 | + params.require(:area).permit(:ns, :code, :country, :pref, :name) | |
41 | + end | |
47 | 42 | end |
@@ -0,0 +1,47 @@ | ||
1 | +class UsersController < ApplicationController | |
2 | + before_action :set_user, only: [:show, :edit, :update, :destroy] | |
3 | + | |
4 | + respond_to :html | |
5 | + | |
6 | + def index | |
7 | + @users = User.all | |
8 | + respond_with(@users) | |
9 | + end | |
10 | + | |
11 | + def show | |
12 | + respond_with(@user) | |
13 | + end | |
14 | + | |
15 | + def new | |
16 | + @user = User.new | |
17 | + respond_with(@user) | |
18 | + end | |
19 | + | |
20 | + def edit | |
21 | + end | |
22 | + | |
23 | + def create | |
24 | + @user = User.new(user_params) | |
25 | + @user.save | |
26 | + respond_with(@user) | |
27 | + end | |
28 | + | |
29 | + def update | |
30 | + @user.update(user_params) | |
31 | + respond_with(@user) | |
32 | + end | |
33 | + | |
34 | + def destroy | |
35 | + @user.destroy | |
36 | + respond_with(@user) | |
37 | + end | |
38 | + | |
39 | + private | |
40 | + def set_user | |
41 | + @user = User.find(params[:id]) | |
42 | + end | |
43 | + | |
44 | + def user_params | |
45 | + params.require(:user).permit(:name, :lang, :tw_uid, :tw_nick, :tw_name, :tw_img_url, :tw_updated_at) | |
46 | + end | |
47 | +end |
@@ -0,0 +1,2 @@ | ||
1 | +module UsersHelper | |
2 | +end |
@@ -0,0 +1,7 @@ | ||
1 | +class Ability | |
2 | + include CanCan::Ability | |
3 | + | |
4 | + def initialize(user) | |
5 | + can :manage, :all | |
6 | + end | |
7 | +end |
@@ -0,0 +1,6 @@ | ||
1 | +class User < ApplicationRecord | |
2 | + # Include default devise modules. Others available are: | |
3 | + # :confirmable, :lockable, :timeoutable and :omniauthable | |
4 | + devise :database_authenticatable, :registerable, | |
5 | + :recoverable, :rememberable, :trackable, :validatable | |
6 | +end |
@@ -0,0 +1,14 @@ | ||
1 | += simple_form_for(@user) do |f| | |
2 | + = f.error_notification | |
3 | + | |
4 | + .form-inputs | |
5 | + = f.input :name | |
6 | + = f.input :lang | |
7 | + = f.input :tw_uid | |
8 | + = f.input :tw_nick | |
9 | + = f.input :tw_name | |
10 | + = f.input :tw_img_url | |
11 | + = f.input :tw_updated_at | |
12 | + | |
13 | + .form-actions | |
14 | + = f.button :submit |
@@ -0,0 +1,2 @@ | ||
1 | +json.extract! user, :id, :name, :lang, :tw_uid, :tw_nick, :tw_name, :tw_img_url, :tw_updated_at, :created_at, :updated_at | |
2 | +json.url user_url(user, format: :json) |
@@ -0,0 +1,7 @@ | ||
1 | +%h1 Editing user | |
2 | + | |
3 | += render 'form' | |
4 | + | |
5 | += link_to 'Show', @user | |
6 | +\| | |
7 | += link_to 'Back', users_path |
@@ -0,0 +1,33 @@ | ||
1 | +%h1 Listing users | |
2 | + | |
3 | +%table | |
4 | + %thead | |
5 | + %tr | |
6 | + %th Name | |
7 | + %th Lang | |
8 | + %th Tw uid | |
9 | + %th Tw nick | |
10 | + %th Tw name | |
11 | + %th Tw img url | |
12 | + %th Tw updated at | |
13 | + %th | |
14 | + %th | |
15 | + %th | |
16 | + | |
17 | + %tbody | |
18 | + - @users.each do |user| | |
19 | + %tr | |
20 | + %td= user.name | |
21 | + %td= user.lang | |
22 | + %td= user.tw_uid | |
23 | + %td= user.tw_nick | |
24 | + %td= user.tw_name | |
25 | + %td= user.tw_img_url | |
26 | + %td= user.tw_updated_at | |
27 | + %td= link_to 'Show', user | |
28 | + %td= link_to 'Edit', edit_user_path(user) | |
29 | + %td= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } | |
30 | + | |
31 | +%br | |
32 | + | |
33 | += link_to 'New User', new_user_path |
@@ -0,0 +1 @@ | ||
1 | +json.array! @users, partial: 'users/user', as: :user |
@@ -0,0 +1,5 @@ | ||
1 | +%h1 New user | |
2 | + | |
3 | += render 'form' | |
4 | + | |
5 | += link_to 'Back', users_path |
@@ -0,0 +1,27 @@ | ||
1 | +%p#notice= notice | |
2 | + | |
3 | +%p | |
4 | + %b Name: | |
5 | + = @user.name | |
6 | +%p | |
7 | + %b Lang: | |
8 | + = @user.lang | |
9 | +%p | |
10 | + %b Tw uid: | |
11 | + = @user.tw_uid | |
12 | +%p | |
13 | + %b Tw nick: | |
14 | + = @user.tw_nick | |
15 | +%p | |
16 | + %b Tw name: | |
17 | + = @user.tw_name | |
18 | +%p | |
19 | + %b Tw img url: | |
20 | + = @user.tw_img_url | |
21 | +%p | |
22 | + %b Tw updated at: | |
23 | + = @user.tw_updated_at | |
24 | + | |
25 | += link_to 'Edit', edit_user_path(@user) | |
26 | +\| | |
27 | += link_to 'Back', users_path |
@@ -0,0 +1 @@ | ||
1 | +json.partial! "users/user", user: @user |
@@ -18,10 +18,23 @@ module MmwPsh | ||
18 | 18 | # Application configuration should go into files in config/initializers |
19 | 19 | # -- all .rb files in that directory are automatically loaded. |
20 | 20 | |
21 | + config.generators do |g| | |
22 | + g.test_framework :rspec, | |
23 | + fixtures: true, | |
24 | + view_specs: false, | |
25 | + helper_specs: false, | |
26 | + routing_specs: true, | |
27 | + controller_specs: true, | |
28 | + request_specs: false | |
29 | + g.fixture_replacement :factory_girl, dir: "spec/factories" | |
30 | + end | |
31 | + | |
21 | 32 | #config.i18n.default_locale = :en |
22 | 33 | #config.i18n.available_locales = [:en, :ja] |
23 | 34 | #config.i18n.enforce_available_locales = true |
24 | 35 | config.encoding = "utf-8" |
25 | 36 | |
37 | + config.hub_secret_default = '' | |
38 | + config.hub_secrets = {} | |
26 | 39 | end |
27 | 40 | end |
@@ -0,0 +1,277 @@ | ||
1 | +# Use this hook to configure devise mailer, warden hooks and so forth. | |
2 | +# Many of these configuration options can be set straight in your model. | |
3 | +Devise.setup do |config| | |
4 | + # The secret key used by Devise. Devise uses this key to generate | |
5 | + # random tokens. Changing this key will render invalid all existing | |
6 | + # confirmation, reset password and unlock tokens in the database. | |
7 | + # Devise will use the `secret_key_base` as its `secret_key` | |
8 | + # by default. You can change it below and use your own secret key. | |
9 | + # config.secret_key = '96c5eed0efb5fc47b419a0dc9c4995f065bad19602dac8a9ff0594dff7978b272b2b86a2e4917028c46a4c95d9f367bbde6587f4b59153ca3642c3068800eedc' | |
10 | + | |
11 | + # ==> Mailer Configuration | |
12 | + # Configure the e-mail address which will be shown in Devise::Mailer, | |
13 | + # note that it will be overwritten if you use your own mailer class | |
14 | + # with default "from" parameter. | |
15 | + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' | |
16 | + | |
17 | + # Configure the class responsible to send e-mails. | |
18 | + # config.mailer = 'Devise::Mailer' | |
19 | + | |
20 | + # Configure the parent class responsible to send e-mails. | |
21 | + # config.parent_mailer = 'ActionMailer::Base' | |
22 | + | |
23 | + # ==> ORM configuration | |
24 | + # Load and configure the ORM. Supports :active_record (default) and | |
25 | + # :mongoid (bson_ext recommended) by default. Other ORMs may be | |
26 | + # available as additional gems. | |
27 | + require 'devise/orm/active_record' | |
28 | + | |
29 | + # ==> Configuration for any authentication mechanism | |
30 | + # Configure which keys are used when authenticating a user. The default is | |
31 | + # just :email. You can configure it to use [:username, :subdomain], so for | |
32 | + # authenticating a user, both parameters are required. Remember that those | |
33 | + # parameters are used only when authenticating and not when retrieving from | |
34 | + # session. If you need permissions, you should implement that in a before filter. | |
35 | + # You can also supply a hash where the value is a boolean determining whether | |
36 | + # or not authentication should be aborted when the value is not present. | |
37 | + # config.authentication_keys = [:email] | |
38 | + | |
39 | + # Configure parameters from the request object used for authentication. Each entry | |
40 | + # given should be a request method and it will automatically be passed to the | |
41 | + # find_for_authentication method and considered in your model lookup. For instance, | |
42 | + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. | |
43 | + # The same considerations mentioned for authentication_keys also apply to request_keys. | |
44 | + # config.request_keys = [] | |
45 | + | |
46 | + # Configure which authentication keys should be case-insensitive. | |
47 | + # These keys will be downcased upon creating or modifying a user and when used | |
48 | + # to authenticate or find a user. Default is :email. | |
49 | + config.case_insensitive_keys = [:email] | |
50 | + | |
51 | + # Configure which authentication keys should have whitespace stripped. | |
52 | + # These keys will have whitespace before and after removed upon creating or | |
53 | + # modifying a user and when used to authenticate or find a user. Default is :email. | |
54 | + config.strip_whitespace_keys = [:email] | |
55 | + | |
56 | + # Tell if authentication through request.params is enabled. True by default. | |
57 | + # It can be set to an array that will enable params authentication only for the | |
58 | + # given strategies, for example, `config.params_authenticatable = [:database]` will | |
59 | + # enable it only for database (email + password) authentication. | |
60 | + # config.params_authenticatable = true | |
61 | + | |
62 | + # Tell if authentication through HTTP Auth is enabled. False by default. | |
63 | + # It can be set to an array that will enable http authentication only for the | |
64 | + # given strategies, for example, `config.http_authenticatable = [:database]` will | |
65 | + # enable it only for database authentication. The supported strategies are: | |
66 | + # :database = Support basic authentication with authentication key + password | |
67 | + # config.http_authenticatable = false | |
68 | + | |
69 | + # If 401 status code should be returned for AJAX requests. True by default. | |
70 | + # config.http_authenticatable_on_xhr = true | |
71 | + | |
72 | + # The realm used in Http Basic Authentication. 'Application' by default. | |
73 | + # config.http_authentication_realm = 'Application' | |
74 | + | |
75 | + # It will change confirmation, password recovery and other workflows | |
76 | + # to behave the same regardless if the e-mail provided was right or wrong. | |
77 | + # Does not affect registerable. | |
78 | + # config.paranoid = true | |
79 | + | |
80 | + # By default Devise will store the user in session. You can skip storage for | |
81 | + # particular strategies by setting this option. | |
82 | + # Notice that if you are skipping storage for all authentication paths, you | |
83 | + # may want to disable generating routes to Devise's sessions controller by | |
84 | + # passing skip: :sessions to `devise_for` in your config/routes.rb | |
85 | + config.skip_session_storage = [:http_auth] | |
86 | + | |
87 | + # By default, Devise cleans up the CSRF token on authentication to | |
88 | + # avoid CSRF token fixation attacks. This means that, when using AJAX | |
89 | + # requests for sign in and sign up, you need to get a new CSRF token | |
90 | + # from the server. You can disable this option at your own risk. | |
91 | + # config.clean_up_csrf_token_on_authentication = true | |
92 | + | |
93 | + # When false, Devise will not attempt to reload routes on eager load. | |
94 | + # This can reduce the time taken to boot the app but if your application | |
95 | + # requires the Devise mappings to be loaded during boot time the application | |
96 | + # won't boot properly. | |
97 | + # config.reload_routes = true | |
98 | + | |
99 | + # ==> Configuration for :database_authenticatable | |
100 | + # For bcrypt, this is the cost for hashing the password and defaults to 11. If | |
101 | + # using other algorithms, it sets how many times you want the password to be hashed. | |
102 | + # | |
103 | + # Limiting the stretches to just one in testing will increase the performance of | |
104 | + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use | |
105 | + # a value less than 10 in other environments. Note that, for bcrypt (the default | |
106 | + # algorithm), the cost increases exponentially with the number of stretches (e.g. | |
107 | + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). | |
108 | + config.stretches = Rails.env.test? ? 1 : 11 | |
109 | + | |
110 | + # Set up a pepper to generate the hashed password. | |
111 | + # config.pepper = 'b8e81a80376bb42d6f44f82f116195e9ead6fcb84dfd97eba67d90ed4f9a1f6550172b8c6ab6b2ccc8b682a08a8d435bf31dc244645d38bc36f834055cba874a' | |
112 | + | |
113 | + # Send a notification to the original email when the user's email is changed. | |
114 | + # config.send_email_changed_notification = false | |
115 | + | |
116 | + # Send a notification email when the user's password is changed. | |
117 | + # config.send_password_change_notification = false | |
118 | + | |
119 | + # ==> Configuration for :confirmable | |
120 | + # A period that the user is allowed to access the website even without | |
121 | + # confirming their account. For instance, if set to 2.days, the user will be | |
122 | + # able to access the website for two days without confirming their account, | |
123 | + # access will be blocked just in the third day. Default is 0.days, meaning | |
124 | + # the user cannot access the website without confirming their account. | |
125 | + # config.allow_unconfirmed_access_for = 2.days | |
126 | + | |
127 | + # A period that the user is allowed to confirm their account before their | |
128 | + # token becomes invalid. For example, if set to 3.days, the user can confirm | |
129 | + # their account within 3 days after the mail was sent, but on the fourth day | |
130 | + # their account can't be confirmed with the token any more. | |
131 | + # Default is nil, meaning there is no restriction on how long a user can take | |
132 | + # before confirming their account. | |
133 | + # config.confirm_within = 3.days | |
134 | + | |
135 | + # If true, requires any email changes to be confirmed (exactly the same way as | |
136 | + # initial account confirmation) to be applied. Requires additional unconfirmed_email | |
137 | + # db field (see migrations). Until confirmed, new email is stored in | |
138 | + # unconfirmed_email column, and copied to email column on successful confirmation. | |
139 | + config.reconfirmable = true | |
140 | + | |
141 | + # Defines which key will be used when confirming an account | |
142 | + # config.confirmation_keys = [:email] | |
143 | + | |
144 | + # ==> Configuration for :rememberable | |
145 | + # The time the user will be remembered without asking for credentials again. | |
146 | + # config.remember_for = 2.weeks | |
147 | + | |
148 | + # Invalidates all the remember me tokens when the user signs out. | |
149 | + config.expire_all_remember_me_on_sign_out = true | |
150 | + | |
151 | + # If true, extends the user's remember period when remembered via cookie. | |
152 | + # config.extend_remember_period = false | |
153 | + | |
154 | + # Options to be passed to the created cookie. For instance, you can set | |
155 | + # secure: true in order to force SSL only cookies. | |
156 | + # config.rememberable_options = {} | |
157 | + | |
158 | + # ==> Configuration for :validatable | |
159 | + # Range for password length. | |
160 | + config.password_length = 6..128 | |
161 | + | |
162 | + # Email regex used to validate email formats. It simply asserts that | |
163 | + # one (and only one) @ exists in the given string. This is mainly | |
164 | + # to give user feedback and not to assert the e-mail validity. | |
165 | + config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ | |
166 | + | |
167 | + # ==> Configuration for :timeoutable | |
168 | + # The time you want to timeout the user session without activity. After this | |
169 | + # time the user will be asked for credentials again. Default is 30 minutes. | |
170 | + # config.timeout_in = 30.minutes | |
171 | + | |
172 | + # ==> Configuration for :lockable | |
173 | + # Defines which strategy will be used to lock an account. | |
174 | + # :failed_attempts = Locks an account after a number of failed attempts to sign in. | |
175 | + # :none = No lock strategy. You should handle locking by yourself. | |
176 | + # config.lock_strategy = :failed_attempts | |
177 | + | |
178 | + # Defines which key will be used when locking and unlocking an account | |
179 | + # config.unlock_keys = [:email] | |
180 | + | |
181 | + # Defines which strategy will be used to unlock an account. | |
182 | + # :email = Sends an unlock link to the user email | |
183 | + # :time = Re-enables login after a certain amount of time (see :unlock_in below) | |
184 | + # :both = Enables both strategies | |
185 | + # :none = No unlock strategy. You should handle unlocking by yourself. | |
186 | + # config.unlock_strategy = :both | |
187 | + | |
188 | + # Number of authentication tries before locking an account if lock_strategy | |
189 | + # is failed attempts. | |
190 | + # config.maximum_attempts = 20 | |
191 | + | |
192 | + # Time interval to unlock the account if :time is enabled as unlock_strategy. | |
193 | + # config.unlock_in = 1.hour | |
194 | + | |
195 | + # Warn on the last attempt before the account is locked. | |
196 | + # config.last_attempt_warning = true | |
197 | + | |
198 | + # ==> Configuration for :recoverable | |
199 | + # | |
200 | + # Defines which key will be used when recovering the password for an account | |
201 | + # config.reset_password_keys = [:email] | |
202 | + | |
203 | + # Time interval you can reset your password with a reset password key. | |
204 | + # Don't put a too small interval or your users won't have the time to | |
205 | + # change their passwords. | |
206 | + config.reset_password_within = 6.hours | |
207 | + | |
208 | + # When set to false, does not sign a user in automatically after their password is | |
209 | + # reset. Defaults to true, so a user is signed in automatically after a reset. | |
210 | + # config.sign_in_after_reset_password = true | |
211 | + | |
212 | + # ==> Configuration for :encryptable | |
213 | + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). | |
214 | + # You can use :sha1, :sha512 or algorithms from others authentication tools as | |
215 | + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 | |
216 | + # for default behavior) and :restful_authentication_sha1 (then you should set | |
217 | + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). | |
218 | + # | |
219 | + # Require the `devise-encryptable` gem when using anything other than bcrypt | |
220 | + # config.encryptor = :sha512 | |
221 | + | |
222 | + # ==> Scopes configuration | |
223 | + # Turn scoped views on. Before rendering "sessions/new", it will first check for | |
224 | + # "users/sessions/new". It's turned off by default because it's slower if you | |
225 | + # are using only default views. | |
226 | + # config.scoped_views = false | |
227 | + | |
228 | + # Configure the default scope given to Warden. By default it's the first | |
229 | + # devise role declared in your routes (usually :user). | |
230 | + # config.default_scope = :user | |
231 | + | |
232 | + # Set this configuration to false if you want /users/sign_out to sign out | |
233 | + # only the current scope. By default, Devise signs out all scopes. | |
234 | + # config.sign_out_all_scopes = true | |
235 | + | |
236 | + # ==> Navigation configuration | |
237 | + # Lists the formats that should be treated as navigational. Formats like | |
238 | + # :html, should redirect to the sign in page when the user does not have | |
239 | + # access, but formats like :xml or :json, should return 401. | |
240 | + # | |
241 | + # If you have any extra navigational formats, like :iphone or :mobile, you | |
242 | + # should add them to the navigational formats lists. | |
243 | + # | |
244 | + # The "*/*" below is required to match Internet Explorer requests. | |
245 | + # config.navigational_formats = ['*/*', :html] | |
246 | + | |
247 | + # The default HTTP method used to sign out a resource. Default is :delete. | |
248 | + config.sign_out_via = :delete | |
249 | + | |
250 | + # ==> OmniAuth | |
251 | + # Add a new OmniAuth provider. Check the wiki for more information on setting | |
252 | + # up on your models and hooks. | |
253 | + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' | |
254 | + | |
255 | + # ==> Warden configuration | |
256 | + # If you want to use other strategies, that are not supported by Devise, or | |
257 | + # change the failure app, you can configure them inside the config.warden block. | |
258 | + # | |
259 | + # config.warden do |manager| | |
260 | + # manager.intercept_401 = false | |
261 | + # manager.default_strategies(scope: :user).unshift :some_external_strategy | |
262 | + # end | |
263 | + | |
264 | + # ==> Mountable engine configurations | |
265 | + # When using Devise inside an engine, let's call it `MyEngine`, and this engine | |
266 | + # is mountable, there are some extra configurations to be taken into account. | |
267 | + # The following options are available, assuming the engine is mounted as: | |
268 | + # | |
269 | + # mount MyEngine, at: '/my_engine' | |
270 | + # | |
271 | + # The router that invoked `devise_for`, in the example above, would be: | |
272 | + # config.router_name = :my_engine | |
273 | + # | |
274 | + # When using OmniAuth, Devise cannot automatically set OmniAuth path, | |
275 | + # so you need to do it manually. For the users scope, it would be: | |
276 | + # config.omniauth_path_prefix = '/my_engine/users/auth' | |
277 | +end |
@@ -0,0 +1,64 @@ | ||
1 | +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n | |
2 | + | |
3 | +en: | |
4 | + devise: | |
5 | + confirmations: | |
6 | + confirmed: "Your email address has been successfully confirmed." | |
7 | + send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." | |
8 | + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." | |
9 | + failure: | |
10 | + already_authenticated: "You are already signed in." | |
11 | + inactive: "Your account is not activated yet." | |
12 | + invalid: "Invalid %{authentication_keys} or password." | |
13 | + locked: "Your account is locked." | |
14 | + last_attempt: "You have one more attempt before your account is locked." | |
15 | + not_found_in_database: "Invalid %{authentication_keys} or password." | |
16 | + timeout: "Your session expired. Please sign in again to continue." | |
17 | + unauthenticated: "You need to sign in or sign up before continuing." | |
18 | + unconfirmed: "You have to confirm your email address before continuing." | |
19 | + mailer: | |
20 | + confirmation_instructions: | |
21 | + subject: "Confirmation instructions" | |
22 | + reset_password_instructions: | |
23 | + subject: "Reset password instructions" | |
24 | + unlock_instructions: | |
25 | + subject: "Unlock instructions" | |
26 | + email_changed: | |
27 | + subject: "Email Changed" | |
28 | + password_change: | |
29 | + subject: "Password Changed" | |
30 | + omniauth_callbacks: | |
31 | + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." | |
32 | + success: "Successfully authenticated from %{kind} account." | |
33 | + passwords: | |
34 | + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." | |
35 | + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." | |
36 | + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." | |
37 | + updated: "Your password has been changed successfully. You are now signed in." | |
38 | + updated_not_active: "Your password has been changed successfully." | |
39 | + registrations: | |
40 | + destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." | |
41 | + signed_up: "Welcome! You have signed up successfully." | |
42 | + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." | |
43 | + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." | |
44 | + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." | |
45 | + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." | |
46 | + updated: "Your account has been updated successfully." | |
47 | + sessions: | |
48 | + signed_in: "Signed in successfully." | |
49 | + signed_out: "Signed out successfully." | |
50 | + already_signed_out: "Signed out successfully." | |
51 | + unlocks: | |
52 | + send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." | |
53 | + send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." | |
54 | + unlocked: "Your account has been unlocked successfully. Please sign in to continue." | |
55 | + errors: | |
56 | + messages: | |
57 | + already_confirmed: "was already confirmed, please try signing in" | |
58 | + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" | |
59 | + expired: "has expired, please request a new one" | |
60 | + not_found: "not found" | |
61 | + not_locked: "was not locked" | |
62 | + not_saved: | |
63 | + one: "1 error prohibited this %{resource} from being saved:" | |
64 | + other: "%{count} errors prohibited this %{resource} from being saved:" |
@@ -1,11 +1,12 @@ | ||
1 | 1 | Rails.application.routes.draw do |
2 | + devise_for :users | |
3 | + resources :users | |
2 | 4 | resources :forecasts |
3 | 5 | resources :areas |
4 | 6 | get 'sub', to: 'subscribe#verify' |
5 | 7 | post 'sub', to: 'subscribe#distribute' |
6 | 8 | |
7 | 9 | resources :dist_signals, only: %i(index show) |
8 | - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | |
9 | 10 | |
10 | 11 | root 'dummy_error_controller#index' |
11 | 12 | end |
@@ -0,0 +1,15 @@ | ||
1 | +class CreateUsers < ActiveRecord::Migration[5.1] | |
2 | + def change | |
3 | + create_table :users do |t| | |
4 | + t.string :name | |
5 | + t.string :lang | |
6 | + t.string :tw_uid | |
7 | + t.string :tw_nick | |
8 | + t.string :tw_name | |
9 | + t.text :tw_img_url | |
10 | + t.datetime :tw_updated_at | |
11 | + | |
12 | + t.timestamps | |
13 | + end | |
14 | + end | |
15 | +end |
@@ -0,0 +1,48 @@ | ||
1 | +class AddDeviseToUsers < ActiveRecord::Migration[5.1] | |
2 | + def self.up | |
3 | + change_table :users do |t| | |
4 | + ## Database authenticatable | |
5 | + t.string :email, null: false, default: "" | |
6 | + t.string :encrypted_password, null: false, default: "" | |
7 | + | |
8 | + ## Recoverable | |
9 | + t.string :reset_password_token | |
10 | + t.datetime :reset_password_sent_at | |
11 | + | |
12 | + ## Rememberable | |
13 | + t.datetime :remember_created_at | |
14 | + | |
15 | + ## Trackable | |
16 | + t.integer :sign_in_count, default: 0, null: false | |
17 | + t.datetime :current_sign_in_at | |
18 | + t.datetime :last_sign_in_at | |
19 | + t.string :current_sign_in_ip | |
20 | + t.string :last_sign_in_ip | |
21 | + | |
22 | + ## Confirmable | |
23 | + # t.string :confirmation_token | |
24 | + # t.datetime :confirmed_at | |
25 | + # t.datetime :confirmation_sent_at | |
26 | + # t.string :unconfirmed_email # Only if using reconfirmable | |
27 | + | |
28 | + ## Lockable | |
29 | + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts | |
30 | + # t.string :unlock_token # Only if unlock strategy is :email or :both | |
31 | + # t.datetime :locked_at | |
32 | + | |
33 | + # Uncomment below if timestamps were not included in your original model. | |
34 | + # t.timestamps null: false | |
35 | + end | |
36 | + | |
37 | + add_index :users, :email, unique: true | |
38 | + add_index :users, :reset_password_token, unique: true | |
39 | + # add_index :users, :confirmation_token, unique: true | |
40 | + # add_index :users, :unlock_token, unique: true | |
41 | + end | |
42 | + | |
43 | + def self.down | |
44 | + # By default, we don't want to make any assumption about how to roll back a migration when your | |
45 | + # model already existed. Please edit below which fields you would like to remove in this migration. | |
46 | + raise ActiveRecord::IrreversibleMigration | |
47 | + end | |
48 | +end |
@@ -10,7 +10,7 @@ | ||
10 | 10 | # |
11 | 11 | # It's strongly recommended that you check this file into your version control system. |
12 | 12 | |
13 | -ActiveRecord::Schema.define(version: 20170615165118) do | |
13 | +ActiveRecord::Schema.define(version: 20170724142504) do | |
14 | 14 | |
15 | 15 | create_table "areas", force: :cascade do |t| |
16 | 16 | t.string "ns" |
@@ -63,4 +63,28 @@ ActiveRecord::Schema.define(version: 20170615165118) do | ||
63 | 63 | t.index ["area_id"], name: "index_forecasts_on_area_id" |
64 | 64 | end |
65 | 65 | |
66 | + create_table "users", force: :cascade do |t| | |
67 | + t.string "name" | |
68 | + t.string "lang" | |
69 | + t.string "tw_uid" | |
70 | + t.string "tw_nick" | |
71 | + t.string "tw_name" | |
72 | + t.text "tw_img_url" | |
73 | + t.datetime "tw_updated_at" | |
74 | + t.datetime "created_at", null: false | |
75 | + t.datetime "updated_at", null: false | |
76 | + t.string "email", default: "", null: false | |
77 | + t.string "encrypted_password", default: "", null: false | |
78 | + t.string "reset_password_token" | |
79 | + t.datetime "reset_password_sent_at" | |
80 | + t.datetime "remember_created_at" | |
81 | + t.integer "sign_in_count", default: 0, null: false | |
82 | + t.datetime "current_sign_in_at" | |
83 | + t.datetime "last_sign_in_at" | |
84 | + t.string "current_sign_in_ip" | |
85 | + t.string "last_sign_in_ip" | |
86 | + t.index ["email"], name: "index_users_on_email", unique: true | |
87 | + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true | |
88 | + end | |
89 | + | |
66 | 90 | end |
@@ -0,0 +1,141 @@ | ||
1 | +require 'rails_helper' | |
2 | + | |
3 | +# This spec was generated by rspec-rails when you ran the scaffold generator. | |
4 | +# It demonstrates how one might use RSpec to specify the controller code that | |
5 | +# was generated by Rails when you ran the scaffold generator. | |
6 | +# | |
7 | +# It assumes that the implementation code is generated by the rails scaffold | |
8 | +# generator. If you are using any extension libraries to generate different | |
9 | +# controller code, this generated spec may or may not pass. | |
10 | +# | |
11 | +# It only uses APIs available in rails and/or rspec-rails. There are a number | |
12 | +# of tools you can use to make these specs even more expressive, but we're | |
13 | +# sticking to rails and rspec-rails APIs to keep things simple and stable. | |
14 | +# | |
15 | +# Compared to earlier versions of this generator, there is very limited use of | |
16 | +# stubs and message expectations in this spec. Stubs are only used when there | |
17 | +# is no simpler way to get a handle on the object needed for the example. | |
18 | +# Message expectations are only used when there is no simpler way to specify | |
19 | +# that an instance is receiving a specific message. | |
20 | +# | |
21 | +# Also compared to earlier versions of this generator, there are no longer any | |
22 | +# expectations of assigns and templates rendered. These features have been | |
23 | +# removed from Rails core in Rails 5, but can be added back in via the | |
24 | +# `rails-controller-testing` gem. | |
25 | + | |
26 | +RSpec.describe UsersController, type: :controller do | |
27 | + | |
28 | + # This should return the minimal set of attributes required to create a valid | |
29 | + # User. As you add validations to User, be sure to | |
30 | + # adjust the attributes here as well. | |
31 | + let(:valid_attributes) { | |
32 | + skip("Add a hash of attributes valid for your model") | |
33 | + } | |
34 | + | |
35 | + let(:invalid_attributes) { | |
36 | + skip("Add a hash of attributes invalid for your model") | |
37 | + } | |
38 | + | |
39 | + # This should return the minimal set of values that should be in the session | |
40 | + # in order to pass any filters (e.g. authentication) defined in | |
41 | + # UsersController. Be sure to keep this updated too. | |
42 | + let(:valid_session) { {} } | |
43 | + | |
44 | + describe "GET #index" do | |
45 | + it "returns a success response" do | |
46 | + user = User.create! valid_attributes | |
47 | + get :index, params: {}, session: valid_session | |
48 | + expect(response).to be_success | |
49 | + end | |
50 | + end | |
51 | + | |
52 | + describe "GET #show" do | |
53 | + it "returns a success response" do | |
54 | + user = User.create! valid_attributes | |
55 | + get :show, params: {id: user.to_param}, session: valid_session | |
56 | + expect(response).to be_success | |
57 | + end | |
58 | + end | |
59 | + | |
60 | + describe "GET #new" do | |
61 | + it "returns a success response" do | |
62 | + get :new, params: {}, session: valid_session | |
63 | + expect(response).to be_success | |
64 | + end | |
65 | + end | |
66 | + | |
67 | + describe "GET #edit" do | |
68 | + it "returns a success response" do | |
69 | + user = User.create! valid_attributes | |
70 | + get :edit, params: {id: user.to_param}, session: valid_session | |
71 | + expect(response).to be_success | |
72 | + end | |
73 | + end | |
74 | + | |
75 | + describe "POST #create" do | |
76 | + context "with valid params" do | |
77 | + it "creates a new User" do | |
78 | + expect { | |
79 | + post :create, params: {user: valid_attributes}, session: valid_session | |
80 | + }.to change(User, :count).by(1) | |
81 | + end | |
82 | + | |
83 | + it "redirects to the created user" do | |
84 | + post :create, params: {user: valid_attributes}, session: valid_session | |
85 | + expect(response).to redirect_to(User.last) | |
86 | + end | |
87 | + end | |
88 | + | |
89 | + context "with invalid params" do | |
90 | + it "returns a success response (i.e. to display the 'new' template)" do | |
91 | + post :create, params: {user: invalid_attributes}, session: valid_session | |
92 | + expect(response).to be_success | |
93 | + end | |
94 | + end | |
95 | + end | |
96 | + | |
97 | + describe "PUT #update" do | |
98 | + context "with valid params" do | |
99 | + let(:new_attributes) { | |
100 | + skip("Add a hash of attributes valid for your model") | |
101 | + } | |
102 | + | |
103 | + it "updates the requested user" do | |
104 | + user = User.create! valid_attributes | |
105 | + put :update, params: {id: user.to_param, user: new_attributes}, session: valid_session | |
106 | + user.reload | |
107 | + skip("Add assertions for updated state") | |
108 | + end | |
109 | + | |
110 | + it "redirects to the user" do | |
111 | + user = User.create! valid_attributes | |
112 | + put :update, params: {id: user.to_param, user: valid_attributes}, session: valid_session | |
113 | + expect(response).to redirect_to(user) | |
114 | + end | |
115 | + end | |
116 | + | |
117 | + context "with invalid params" do | |
118 | + it "returns a success response (i.e. to display the 'edit' template)" do | |
119 | + user = User.create! valid_attributes | |
120 | + put :update, params: {id: user.to_param, user: invalid_attributes}, session: valid_session | |
121 | + expect(response).to be_success | |
122 | + end | |
123 | + end | |
124 | + end | |
125 | + | |
126 | + describe "DELETE #destroy" do | |
127 | + it "destroys the requested user" do | |
128 | + user = User.create! valid_attributes | |
129 | + expect { | |
130 | + delete :destroy, params: {id: user.to_param}, session: valid_session | |
131 | + }.to change(User, :count).by(-1) | |
132 | + end | |
133 | + | |
134 | + it "redirects to the users list" do | |
135 | + user = User.create! valid_attributes | |
136 | + delete :destroy, params: {id: user.to_param}, session: valid_session | |
137 | + expect(response).to redirect_to(users_url) | |
138 | + end | |
139 | + end | |
140 | + | |
141 | +end |
@@ -0,0 +1,11 @@ | ||
1 | +FactoryGirl.define do | |
2 | + factory :user do | |
3 | + name "MyString" | |
4 | + lang "MyString" | |
5 | + tw_uid "MyString" | |
6 | + tw_nick "MyString" | |
7 | + tw_name "MyString" | |
8 | + tw_img_url "MyText" | |
9 | + tw_updated_at "2017-07-24 23:19:58" | |
10 | + end | |
11 | +end |
@@ -0,0 +1,5 @@ | ||
1 | +require 'rails_helper' | |
2 | + | |
3 | +RSpec.describe User, type: :model do | |
4 | + pending "add some examples to (or delete) #{__FILE__}" | |
5 | +end |
@@ -1,39 +0,0 @@ | ||
1 | -require "rails_helper" | |
2 | - | |
3 | -RSpec.describe AreasController, type: :routing do | |
4 | - describe "routing" do | |
5 | - | |
6 | - it "routes to #index" do | |
7 | - expect(:get => "/areas").to route_to("areas#index") | |
8 | - end | |
9 | - | |
10 | - it "routes to #new" do | |
11 | - expect(:get => "/areas/new").to route_to("areas#new") | |
12 | - end | |
13 | - | |
14 | - it "routes to #show" do | |
15 | - expect(:get => "/areas/1").to route_to("areas#show", :id => "1") | |
16 | - end | |
17 | - | |
18 | - it "routes to #edit" do | |
19 | - expect(:get => "/areas/1/edit").to route_to("areas#edit", :id => "1") | |
20 | - end | |
21 | - | |
22 | - it "routes to #create" do | |
23 | - expect(:post => "/areas").to route_to("areas#create") | |
24 | - end | |
25 | - | |
26 | - it "routes to #update via PUT" do | |
27 | - expect(:put => "/areas/1").to route_to("areas#update", :id => "1") | |
28 | - end | |
29 | - | |
30 | - it "routes to #update via PATCH" do | |
31 | - expect(:patch => "/areas/1").to route_to("areas#update", :id => "1") | |
32 | - end | |
33 | - | |
34 | - it "routes to #destroy" do | |
35 | - expect(:delete => "/areas/1").to route_to("areas#destroy", :id => "1") | |
36 | - end | |
37 | - | |
38 | - end | |
39 | -end |
@@ -1,39 +0,0 @@ | ||
1 | -require "rails_helper" | |
2 | - | |
3 | -RSpec.describe DistSignalsController, type: :routing do | |
4 | - describe "routing" do | |
5 | - | |
6 | - it "routes to #index" do | |
7 | - expect(:get => "/dist_signals").to route_to("dist_signals#index") | |
8 | - end | |
9 | - | |
10 | - xit "routes to #new" do | |
11 | - expect(:get => "/dist_signals/new").to route_to("dist_signals#new") | |
12 | - end | |
13 | - | |
14 | - it "routes to #show" do | |
15 | - expect(:get => "/dist_signals/1").to route_to("dist_signals#show", :id => "1") | |
16 | - end | |
17 | - | |
18 | - xit "routes to #edit" do | |
19 | - expect(:get => "/dist_signals/1/edit").to route_to("dist_signals#edit", :id => "1") | |
20 | - end | |
21 | - | |
22 | - xit "routes to #create" do | |
23 | - expect(:post => "/dist_signals").to route_to("dist_signals#create") | |
24 | - end | |
25 | - | |
26 | - xit "routes to #update via PUT" do | |
27 | - expect(:put => "/dist_signals/1").to route_to("dist_signals#update", :id => "1") | |
28 | - end | |
29 | - | |
30 | - xit "routes to #update via PATCH" do | |
31 | - expect(:patch => "/dist_signals/1").to route_to("dist_signals#update", :id => "1") | |
32 | - end | |
33 | - | |
34 | - xit "routes to #destroy" do | |
35 | - expect(:delete => "/dist_signals/1").to route_to("dist_signals#destroy", :id => "1") | |
36 | - end | |
37 | - | |
38 | - end | |
39 | -end |
@@ -1,39 +0,0 @@ | ||
1 | -require "rails_helper" | |
2 | - | |
3 | -RSpec.describe ForecastsController, type: :routing do | |
4 | - describe "routing" do | |
5 | - | |
6 | - it "routes to #index" do | |
7 | - expect(:get => "/forecasts").to route_to("forecasts#index") | |
8 | - end | |
9 | - | |
10 | - it "routes to #new" do | |
11 | - expect(:get => "/forecasts/new").to route_to("forecasts#new") | |
12 | - end | |
13 | - | |
14 | - it "routes to #show" do | |
15 | - expect(:get => "/forecasts/1").to route_to("forecasts#show", :id => "1") | |
16 | - end | |
17 | - | |
18 | - it "routes to #edit" do | |
19 | - expect(:get => "/forecasts/1/edit").to route_to("forecasts#edit", :id => "1") | |
20 | - end | |
21 | - | |
22 | - it "routes to #create" do | |
23 | - expect(:post => "/forecasts").to route_to("forecasts#create") | |
24 | - end | |
25 | - | |
26 | - it "routes to #update via PUT" do | |
27 | - expect(:put => "/forecasts/1").to route_to("forecasts#update", :id => "1") | |
28 | - end | |
29 | - | |
30 | - it "routes to #update via PATCH" do | |
31 | - expect(:patch => "/forecasts/1").to route_to("forecasts#update", :id => "1") | |
32 | - end | |
33 | - | |
34 | - it "routes to #destroy" do | |
35 | - expect(:delete => "/forecasts/1").to route_to("forecasts#destroy", :id => "1") | |
36 | - end | |
37 | - | |
38 | - end | |
39 | -end |
@@ -0,0 +1,39 @@ | ||
1 | +require "rails_helper" | |
2 | + | |
3 | +RSpec.describe UsersController, type: :routing do | |
4 | + describe "routing" do | |
5 | + | |
6 | + it "routes to #index" do | |
7 | + expect(:get => "/users").to route_to("users#index") | |
8 | + end | |
9 | + | |
10 | + it "routes to #new" do | |
11 | + expect(:get => "/users/new").to route_to("users#new") | |
12 | + end | |
13 | + | |
14 | + it "routes to #show" do | |
15 | + expect(:get => "/users/1").to route_to("users#show", :id => "1") | |
16 | + end | |
17 | + | |
18 | + it "routes to #edit" do | |
19 | + expect(:get => "/users/1/edit").to route_to("users#edit", :id => "1") | |
20 | + end | |
21 | + | |
22 | + it "routes to #create" do | |
23 | + expect(:post => "/users").to route_to("users#create") | |
24 | + end | |
25 | + | |
26 | + it "routes to #update via PUT" do | |
27 | + expect(:put => "/users/1").to route_to("users#update", :id => "1") | |
28 | + end | |
29 | + | |
30 | + it "routes to #update via PATCH" do | |
31 | + expect(:patch => "/users/1").to route_to("users#update", :id => "1") | |
32 | + end | |
33 | + | |
34 | + it "routes to #destroy" do | |
35 | + expect(:delete => "/users/1").to route_to("users#destroy", :id => "1") | |
36 | + end | |
37 | + | |
38 | + end | |
39 | +end |