Commit e7a49cd4 by Đường Sỹ Hoàng

Fixed coding styles

parent 070c8332
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the AccountActivations controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class AccountActivationsController < ApplicationController
end
class UsersController < ApplicationController class UsersController < ApplicationController
before_action :logged_in_user, only: [:index, :edit, :update,:destroy] before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update] before_action :correct_user, only: [:edit, :update]
before_action :admin_user, only: :destroy before_action :admin_user, only: :destroy
def index def index
@users = User.paginate(page: params[:page]) @users = User.paginate(page: params[:page])
end end
...@@ -52,11 +53,11 @@ class UsersController < ApplicationController ...@@ -52,11 +53,11 @@ class UsersController < ApplicationController
end end
def user_params def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation) params.require(:user).permit(:name, :email, :password, :password_confirmation)
end end
# Before filters # Before filters
# Confirms a logged-in user. # Confirms a logged-in user.
def logged_in_user def logged_in_user
unless logged_in? unless logged_in?
......
module AccountActivationsHelper
end
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
<%= gravatar_for user, size: 50 %> <%= gravatar_for user, size: 50 %>
<%= link_to user.name, user %> <%= link_to user.name, user %>
<% if current_user.admin? && !current_user?(user) %> <% if current_user.admin? && !current_user?(user) %>
| <%= link_to "delete", user, method: :delete,data: {confirm: "You sure?" } %> | <%= link_to "delete", user, method: :delete, data: { confirm: "You sure?" } %>
<% end %> <% end %>
</li> </li>
<% provide(:title, 'All users') %> <% provide(:title, "All users") %>
<h1>All users</h1> <h1>All users</h1>
<%= will_paginate %> <%= will_paginate %>
......
<% provide(:title, 'Sign up') %> <% provide(:title, "Sign up") %>
<% provide(:button_text, 'Create my account') %> <% provide(:button_text, "Create my account") %>
<h1>Sign up</h1> <h1>Sign up</h1>
<div class="row"> <div class="row">
<div class="col-md-6 col-md-offset-3"> <div class="col-md-6 col-md-offset-3">
<%= render 'form' %> <%= render "form" %>
</div> </div>
</div> </div>
class AddActivationToUsers < ActiveRecord::Migration[5.1]
def change
add_column :users, :activation_digest, :string
add_column :users, :activated, :boolean, default: false
add_column :users, :activated_at, :datetime
end
end
User.create!(name: "Example User", User.create!(name: "Example User",
email: "example@railstutorial.org", email: "example@railstutorial.org",
password: "foobar", password: "foobar",
password_confirmation: "foobar") password_confirmation: "foobar")
99.times do |n| 99.times do |n|
name = Faker::Name.name name = Faker::Name.name
email = "example-#{n+1}@railstutorial.org" email = "example-#{n+1}@railstutorial.org"
password = "password" password = "password"
User.create!(name: name, User.create!(name: name,
email: email, email: email,
password: password, password: password,
password_confirmation: password) password_confirmation: password)
......
require 'test_helper'
class AccountActivationsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
...@@ -39,7 +39,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest ...@@ -39,7 +39,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
test "should not allow the admin attribute to be edited via the web" do test "should not allow the admin attribute to be edited via the web" do
log_in_as(@other_user) log_in_as(@other_user)
assert_not @other_user.admin? assert_not @other_user.admin?
patch user_path(@other_user), params: {user:{ password: @other_user.password, password_confirmation: @other_user.password, admin: true } } patch user_path(@other_user), params: { user: { password: @other_user.password, password_confirmation: @other_user.password, admin: true } }
assert_not @other_user.reload.admin? assert_not @other_user.reload.admin?
end end
end end
...@@ -34,7 +34,7 @@ class UsersEditTest < ActionDispatch::IntegrationTest ...@@ -34,7 +34,7 @@ class UsersEditTest < ActionDispatch::IntegrationTest
assert_redirected_to edit_user_url(@user) assert_redirected_to edit_user_url(@user)
name = "Foo Bar" name = "Foo Bar"
email = "foo@bar.com" email = "foo@bar.com"
patch user_path(@user), params: { user: { name: name, email: email, password:"", password_confirmation: "" } } patch user_path(@user), params: { user: { name: name, email: email, password: "", password_confirmation: "" } }
assert_not flash.empty? assert_not flash.empty?
assert_redirected_to @user assert_redirected_to @user
@user.reload @user.reload
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment