Permalink
Browse files

name shouldn't be changed once created

  • Loading branch information...
orenomba committed Aug 8, 2012
1 parent 3f64c1a commit b3dcaca8ed4b54f2736c549454a182a70b7b0de1
@@ -4,6 +4,7 @@ class UsersController < ApplicationController
def new
@user = User.new
+ render :form
end
def create
@@ -12,7 +13,28 @@ def create
flash[:success] = "ユーザー登録しました!"
redirect_to root_url
else
- render :new
+ render :form
end
end
+
+ def edit
+ find
+ render :form
+ end
+
+ def update
+ find
+
+ if @user.update_attributes(params[:user].reject{|key| key == :name})
+ flash[:success] = "ユーザー編集しました!"
+ redirect_to edit_user_path @user
+ else
+ render :form
+ end
+ end
+
+ private
+ def find
+ @user = User.find params[:id]
+ end
end
@@ -48,11 +48,10 @@
<ul class="nav">
<% unless logged_in? %>
<li><%= link_to "ユーザー登録", signup_path %></li>
- <% end %>
- <% unless logged_in? %>
<li><%= link_to "ログイン", login_path %></li>
<% end %>
<% if logged_in? %>
+ <li><%= link_to "ユーザー編集", edit_user_path(current_user) %></li>
<li><%= link_to "ログアウト", logout_path %></li>
<% end %>
</ul>
@@ -1,5 +1,12 @@
+<%
+
+ name_options = {}
+ name_options = {class: "disabled", disabled: true} unless @user.new_record?
+%>
+
<%= semantic_form_for @user do |form| %>
- <%= form.input :name %>
+ <%= form.input :avatar %>
+ <%= form.input :name, input_html: name_options %>
<%= form.input :email %>
<%= form.input :password %>
<%= form.input :password_confirmation %>
View
@@ -205,10 +205,12 @@ ja:
hints:
user:
+ name: アルファベット、数字 _(アンダースコア)のみで入力してください
password_confirmation: パスワードと同じものを入力してください
labels:
user:
+ avatar: アバター
name: ユーザー名
email: Eメール
password: パスワード
@@ -221,6 +223,8 @@ ja:
actions:
create: 登録
+ user:
+ update: 編集
session:
create: "ログイン"
@@ -60,5 +60,50 @@
end
end
end
+
+ describe "edit" do
+ before(:each) do
+ @user = FactoryGirl.create :user, name: "test", email: "test@domain.local", password: "a" * 8
+ visit login_path
+ fill_in "session_identification", with: "test"
+ fill_in "session_password", with: "a" * 8
+ click_button "ログイン"
+ visit edit_user_path(@user)
+ end
+
+ it "should show page" do
+ page.should have_content "編集"
+ end
+
+ it "should have name disabled" do
+ page.should have_selector "#user_name.disabled"
+ end
+
+ describe "update" do
+ before(:each) do
+ end
+
+ it "should update" do
+ lambda{
+ fill_in "user_email", with: "edit@domain.local"
+ click_button "編集"
+ @user.reload
+ }.should change(@user, :email).from("test@domain.local").to("edit@domain.local")
+ end
+
+ it "should show message" do
+ click_button "編集"
+ page.should have_content "編集しました"
+ end
+
+ it "should not update name" do
+ lambda{
+ fill_in "user_name", with: "changed"
+ click_button "編集"
+ @user.reload
+ }.should_not change(@user, :name).from("test").to("changed")
+ end
+ end
+ end
end

0 comments on commit b3dcaca

Please sign in to comment.