OSDN Git Service

t#30143:au and ar change
authoryasushiito <yas@pen-chan.jp>
Sat, 1 Dec 2012 07:00:45 +0000 (16:00 +0900)
committeryasushiito <yas@pen-chan.jp>
Sat, 1 Dec 2012 07:00:45 +0000 (16:00 +0900)
app/controllers/artists_controller.rb
app/controllers/authors_controller.rb
app/models/artist.rb
app/views/artists/edit.html.erb
app/views/artists/show.html.erb
app/views/authors/edit.html.erb
app/views/authors/show.html.erb
app/views/home/configure.html.erb
spec/controllers/artists_controller_spec.rb
spec/controllers/authors_controller_spec.rb

index 036131b..acd5fa2 100644 (file)
@@ -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" }
index f454c91..50adf08 100644 (file)
@@ -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" }
index 419e965..bfd9b76 100644 (file)
@@ -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
index 6e8a5d2..78e9943 100644 (file)
@@ -2,6 +2,3 @@
 <p id="notice"><%= notice %></p>
 
 <%= render 'form', :ar => @ar %>
-configure
-<%= link_to 'Show', @ar %> |
-<%= link_to 'Back', artists_path %>
index 0a09a71..c791476 100644 (file)
@@ -16,4 +16,6 @@
   <%= l @ar.updated_at %>
 </p>
 
-<%= link_to t('link.back'), artists_path %>
+<% if @ar.own?(@artist) %>
+  <%= link_to t('link.edit'), edit_artist_path(@ar) %>
+<% end %>
index dd7fb8f..c6fbf29 100644 (file)
@@ -2,5 +2,3 @@
 
 <%= render 'form', :au => @au %>
 
-<%= link_to 'Show', @au %> |
-<%= link_to 'Back', authors_path %>
index 3c114a2..555278e 100644 (file)
@@ -16,4 +16,6 @@
   <%= l @au.updated_at %>
 </p>
 
-<%= link_to t('link.back'), authors_path %>
+<% if @au.own?(@author) %>
+  <%= link_to t('link.edit'), edit_author_path(@au) %>
+<% end %>
index e6c6cfe..70dea5c 100644 (file)
@@ -1,4 +1,5 @@
 <h1><%= t '.title' -%></h1>
+<p id="notice"><%= notice %></p>
 
 <%= t('home.configure.caption', :email => @user.email) %>
 <table class="no-border" width="100%">
index c6ae277..0c61680 100644 (file)
@@ -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
index da6819d..ff4a766 100644 (file)
@@ -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