From 0fbe26ac598ad6e8ce4810009d394edeb850312a Mon Sep 17 00:00:00 2001
From: yasushiito
Date: Sat, 1 Dec 2012 16:00:45 +0900
Subject: [PATCH] t#30143:au and ar change
---
app/controllers/artists_controller.rb | 4 ++--
app/controllers/authors_controller.rb | 4 ++--
app/models/artist.rb | 9 +++++++--
app/views/artists/edit.html.erb | 3 ---
app/views/artists/show.html.erb | 4 +++-
app/views/authors/edit.html.erb | 2 --
app/views/authors/show.html.erb | 4 +++-
app/views/home/configure.html.erb | 1 +
spec/controllers/artists_controller_spec.rb | 22 +++++++++++-----------
spec/controllers/authors_controller_spec.rb | 8 ++++----
10 files changed, 33 insertions(+), 28 deletions(-)
diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb
index 036131b5..acd5fa24 100644
--- a/app/controllers/artists_controller.rb
+++ b/app/controllers/artists_controller.rb
@@ -84,7 +84,7 @@ class ArtistsController < ApplicationController
@ar.overwrite @author
respond_to do |format|
if @ar.save
- format.html { redirect_to @ar, notice: 'Artist was successfully created.' }
+ format.html { redirect_to root_path, notice: 'Artist was successfully created.' }
format.json { render json: @ar.to_json(Artist.show_json_opt), status: :created, location: @artist }
else
format.html { render action: "new" }
@@ -102,7 +102,7 @@ class ArtistsController < ApplicationController
respond_to do |format|
if @ar.save
- format.html { redirect_to @ar, notice: 'Artist was successfully updated.' }
+ format.html { redirect_to '/home/configure', notice: 'Artist was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb
index f454c91b..50adf081 100644
--- a/app/controllers/authors_controller.rb
+++ b/app/controllers/authors_controller.rb
@@ -69,7 +69,7 @@ class AuthorsController < ApplicationController
@au.overwrite @user.id
respond_to do |format|
if @au.save
- format.html { redirect_to @au, notice: 'Author was successfully created.' }
+ format.html { redirect_to root_path, notice: 'Author was successfully created.' }
format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
else
format.html { render action: "new" }
@@ -85,7 +85,7 @@ class AuthorsController < ApplicationController
respond_to do |format|
if @au.save
- format.html { redirect_to @au, notice: 'Author was successfully updated.' }
+ format.html { redirect_to '/home/configure', notice: 'Author was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
diff --git a/app/models/artist.rb b/app/models/artist.rb
index 419e9650..bfd9b767 100644
--- a/app/models/artist.rb
+++ b/app/models/artist.rb
@@ -17,8 +17,13 @@ class Artist < ActiveRecord::Base
end
def own? au
- return false unless au.is_a?(Author)
- self.author_id == au.id
+ if au.is_a?(Author)
+ self.author_id == au.id
+ elsif au.is_a?(Artist)
+ self.id == au.id
+ else
+ false
+ end
end
def visible? au
diff --git a/app/views/artists/edit.html.erb b/app/views/artists/edit.html.erb
index 6e8a5d2e..78e99436 100644
--- a/app/views/artists/edit.html.erb
+++ b/app/views/artists/edit.html.erb
@@ -2,6 +2,3 @@
<%= notice %>
<%= render 'form', :ar => @ar %>
-configure
-<%= link_to 'Show', @ar %> |
-<%= link_to 'Back', artists_path %>
diff --git a/app/views/artists/show.html.erb b/app/views/artists/show.html.erb
index 0a09a711..c7914769 100644
--- a/app/views/artists/show.html.erb
+++ b/app/views/artists/show.html.erb
@@ -16,4 +16,6 @@
<%= l @ar.updated_at %>
-<%= link_to t('link.back'), artists_path %>
+<% if @ar.own?(@artist) %>
+ <%= link_to t('link.edit'), edit_artist_path(@ar) %>
+<% end %>
diff --git a/app/views/authors/edit.html.erb b/app/views/authors/edit.html.erb
index dd7fb8f8..c6fbf291 100644
--- a/app/views/authors/edit.html.erb
+++ b/app/views/authors/edit.html.erb
@@ -2,5 +2,3 @@
<%= render 'form', :au => @au %>
-<%= link_to 'Show', @au %> |
-<%= link_to 'Back', authors_path %>
diff --git a/app/views/authors/show.html.erb b/app/views/authors/show.html.erb
index 3c114a2e..555278e8 100644
--- a/app/views/authors/show.html.erb
+++ b/app/views/authors/show.html.erb
@@ -16,4 +16,6 @@
<%= l @au.updated_at %>
-<%= link_to t('link.back'), authors_path %>
+<% if @au.own?(@author) %>
+ <%= link_to t('link.edit'), edit_author_path(@au) %>
+<% end %>
diff --git a/app/views/home/configure.html.erb b/app/views/home/configure.html.erb
index e6c6cfe3..70dea5c1 100644
--- a/app/views/home/configure.html.erb
+++ b/app/views/home/configure.html.erb
@@ -1,4 +1,5 @@
<%= t '.title' -%>
+<%= notice %>
<%= t('home.configure.caption', :email => @user.email) %>
diff --git a/spec/controllers/artists_controller_spec.rb b/spec/controllers/artists_controller_spec.rb
index c6ae2776..0c61680a 100644
--- a/spec/controllers/artists_controller_spec.rb
+++ b/spec/controllers/artists_controller_spec.rb
@@ -125,9 +125,9 @@ describe ArtistsController do
Artist.should_receive(:show).exactly(1)
get :show
end
- it '@artistã«ã¢ã¬ãåå¾ãã¦ãã' do
+ it '@arã«ã¢ã¬ãåå¾ãã¦ãã' do
get :show, :id => @artist.id
- assigns(:artist).should eq(@artist)
+ assigns(:ar).should eq(@artist)
end
context 'htmlå½¢å¼' do
it 'showãã³ãã¬ã¼ããæç»ãã' do
@@ -321,10 +321,10 @@ describe ArtistsController do
end
end
context 'ã¤ã¤ããªãçµããã¨ã' do
- it "@artistã«ä½æããã絵師ãä¿æãã¦ãã¦ããããDBã«ãã" do
+ it "@arã«ä½æããã絵師ãä¿æãã¦ãã¦ããããDBã«ãã" do
post :create, :artist => @attr
- assigns(:artist).should be_a(Artist)
- assigns(:artist).should be_persisted
+ assigns(:ar).should be_a(Artist)
+ assigns(:ar).should be_persisted
end
context 'htmlå½¢å¼' do
it 'ã¹ãã¼ã¿ã¹ã³ã¼ã302 Foundãè¿ã' do
@@ -332,10 +332,10 @@ describe ArtistsController do
post :create, :artist => @attr
response.status.should eq 302
end
- it 'ä½æããã絵師ã®è¡¨ç¤ºãã¼ã¸ã¸é·ç§»ãã' do
+ it 'ããããã¼ã¸ã¸é·ç§»ãã' do
# Artist.any_instance.stub(:save).and_return(true)
post :create, :artist => @attr
- response.should redirect_to(Artist.last)
+ response.should redirect_to(root_path)
end
end
context 'jsonå½¢å¼' do
@@ -497,9 +497,9 @@ describe ArtistsController do
Artist.any_instance.should_receive(:save).exactly(1)
put :update, :id => @artist.id, :artist => @attr
end
- it '@artistã«ã¢ã¬ãåå¾ãã¦ãã' do
+ it '@arã«ã¢ã¬ãåå¾ãã¦ãã' do
put :update, :id => @artist.id, :artist => @attr
- assigns(:artist).should eq @artist
+ assigns(:ar).should eq @artist
end
end
context 'ã¤ã¤ããªãçµããã¨ã' do
@@ -513,9 +513,9 @@ describe ArtistsController do
put :update, :id => @artist.id, :artist => @attr
response.status.should eq 302
end
- it 'æ´æ°ããã絵師ã®è¡¨ç¤ºãã¼ã¸ã¸é·ç§»ãã' do
+ it 'è¨å®ãã¼ã¸ã¸é·ç§»ãã' do
put :update, :id => @artist.id, :artist => @attr
- response.should redirect_to(@artist)
+ response.should redirect_to('/home/configure')
end
end
context 'jsonå½¢å¼' do
diff --git a/spec/controllers/authors_controller_spec.rb b/spec/controllers/authors_controller_spec.rb
index da6819d3..ff4a766b 100644
--- a/spec/controllers/authors_controller_spec.rb
+++ b/spec/controllers/authors_controller_spec.rb
@@ -337,10 +337,10 @@ describe AuthorsController do
post :create, :author => @attr
response.status.should eq 302
end
- it 'ä½æãããä½å®¶ã®è¡¨ç¤ºãã¼ã¸ã¸é·ç§»ãã' do
+ it 'ããããã¼ã¸ã¸é·ç§»ãã' do
# Author.any_instance.stub(:save).and_return(true)
post :create, :author => @attr
- response.should redirect_to(Author.last)
+ response.should redirect_to(root_path)
end
end
context 'jsonå½¢å¼' do
@@ -522,9 +522,9 @@ describe AuthorsController do
put :update, :id => @author.id, :author => @attr
response.status.should eq 302
end
- it 'æ´æ°ãããä½å®¶ã®è¡¨ç¤ºãã¼ã¸ã¸é·ç§»ãã' do
+ it 'è¨å®ãã¼ã¸ã¸é·ç§»ãã' do
put :update, :id => @author.id, :author => @attr
- response.should redirect_to(@author)
+ response.should redirect_to('/home/configure')
end
end
context 'jsonå½¢å¼' do
--
2.11.0