OSDN Git Service

t#30137:fix authenticate
authoryasushiito <yas@pen-chan.jp>
Mon, 21 Jan 2013 10:29:30 +0000 (19:29 +0900)
committeryasushiito <yas@pen-chan.jp>
Mon, 21 Jan 2013 10:29:30 +0000 (19:29 +0900)
55 files changed:
app/controllers/artists_controller.rb
app/controllers/authors_controller.rb
app/controllers/balloons_controller.rb
app/controllers/comics_controller.rb
app/controllers/ground_colors_controller.rb
app/controllers/ground_pictures_controller.rb
app/controllers/original_pictures_controller.rb
app/controllers/panel_colors_controller.rb
app/controllers/panel_pictures_controller.rb
app/controllers/panels_controller.rb
app/controllers/pictures_controller.rb
app/controllers/resource_pictures_controller.rb
app/controllers/speech_balloon_templates_controller.rb
app/controllers/speech_balloons_controller.rb
app/controllers/speeches_controller.rb
app/controllers/stories_controller.rb
app/models/artist.rb
app/models/author.rb
app/models/balloon.rb
app/models/comic.rb
app/models/ground_color.rb
app/models/ground_picture.rb
app/models/original_picture.rb
app/models/panel.rb
app/models/panel_color.rb
app/models/panel_picture.rb
app/models/picture.rb
app/models/resource_picture.rb
app/models/speech.rb
app/models/speech_balloon.rb
app/models/story.rb
app/models/system_picture.rb
config/environment.rb
lib/ar_helper.rb [new file with mode: 0644]
spec/controllers/artists_controller_spec.rb
spec/controllers/panels_controller_spec.rb
spec/controllers/pictures_controller_spec.rb
spec/controllers/resource_pictures_controller_spec.rb
spec/controllers/speech_balloon_templates_controller_spec.rb
spec/controllers/stories_controller_spec.rb
spec/models/artist_spec.rb
spec/models/author_spec.rb
spec/models/balloon_spec.rb
spec/models/comic_spec.rb
spec/models/ground_color_spec.rb
spec/models/ground_picture_spec.rb
spec/models/original_picture_spec.rb
spec/models/panel_color_spec.rb
spec/models/panel_picture_spec.rb
spec/models/panel_spec.rb
spec/models/picture_spec.rb
spec/models/resource_picture_spec.rb
spec/models/speech_balloon_spec.rb
spec/models/speech_spec.rb
spec/models/story_spec.rb

index c1f2384..b5b2956 100644 (file)
@@ -3,7 +3,7 @@ class ArtistsController < ApplicationController
   if MagicNumber['run_mode'] == 0
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
   else
-    before_filter :authenticate_reader, :only => [:index, :show]
+    before_filter :authenticate_resource_reader, :only => [:index, :show]
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
   end
   before_filter :authenticate_admin!, :only => [:list, :browse]
index 6f787a3..d5d0b5c 100644 (file)
@@ -20,7 +20,7 @@ class AuthorsController < ApplicationController
   end
 
   def show
-    @au = Author.show(params[:id], @author)
+    @au = Author.show(params[:id], [@author, @admin])
 
     respond_to do |format|
       format.html
index fda6a8b..cb01d58 100644 (file)
@@ -20,7 +20,7 @@ class BalloonsController < ApplicationController
   end
   
   def show
-    @balloon = Balloon.show(params[:id], @author)
+    @balloon = Balloon.show(params[:id], [@author, @admin])
     respond_to do |format|
       format.html # show.html.erb
       format.json { render json: @balloon.to_json(Balloon.show_json_opt) }
index 75eade6..ec79f36 100644 (file)
@@ -25,7 +25,7 @@ class ComicsController < ApplicationController
   end
 
   def show
-    @comic = Comic.show(params[:id], @author)
+    @comic = Comic.show(params[:id], [@author, @admin])
 
     respond_to do |format|
       format.html # show.html.erb
index 5346ff1..39ecdda 100644 (file)
@@ -21,7 +21,7 @@ class GroundColorsController < ApplicationController
   end
   
   def show
-    @ground_color = GroundColor.show(params[:id], @author)
+    @ground_color = GroundColor.show(params[:id], [@author, @admin])
     respond_to do |format|
       format.html # show.html.erb
       format.json { render json: @ground_color.to_json(GroundColor.show_json_opt) }
index 666eb58..8836779 100644 (file)
@@ -21,7 +21,7 @@ class GroundPicturesController < ApplicationController
   end
 
   def show
-    @ground_picture = GroundPicture.show(params[:id], @author)
+    @ground_picture = GroundPicture.show(params[:id], [@author, @admin])
     respond_to do |format|
       format.html # show.html.erb
       format.json { render json: @ground_picture.to_json(GroundPicture.show_json_opt) }
index e8e451c..fb6a7a3 100644 (file)
@@ -22,7 +22,7 @@ class OriginalPicturesController < ApplicationController
   # GET /original_pictures/1
   # GET /original_pictures/1.json
   def show
-    @original_picture = OriginalPicture.show(params[:id], @admin || @artist)
+    @original_picture = OriginalPicture.show(params[:id], [@artist, @admin])
     
     respond_to do |format|
       opt = {:type => @original_picture.mime_type, :disposition=>"inline"}
@@ -39,7 +39,7 @@ class OriginalPicturesController < ApplicationController
   end
 
   def history
-    @original_picture = OriginalPicture.show(params[:id], @artist)
+    @original_picture = OriginalPicture.show(params[:id], [@artist, @admin])
     @history = @original_picture.history
     
     respond_to do |format|
index 3c822bb..2fe7885 100644 (file)
@@ -21,7 +21,7 @@ class PanelColorsController < ApplicationController
   end
   
   def show
-    @panel_color = PanelColor.show(params[:id], @author)
+    @panel_color = PanelColor.show(params[:id], [@author, @admin])
     respond_to do |format|
       format.html # show.html.erb
       format.json { render json: @panel_color.to_json(PanelColor.show_json_opt) }
index 07c60e2..22f98d4 100644 (file)
@@ -21,7 +21,7 @@ class PanelPicturesController < ApplicationController
   end
 
   def show
-    @panel_picture = PanelPicture.show(params[:id], @author)
+    @panel_picture = PanelPicture.show(params[:id], [@author, @admin])
 
     respond_to do |format|
       format.html
index 70b9209..3a880ea 100644 (file)
@@ -22,7 +22,7 @@ class PanelsController < ApplicationController
   end
 
   def show
-    @panel = Panel.show(params[:id], @author)
+    @panel = Panel.show(params[:id], [@author, @admin])
 
     respond_to do |format|
       format.html # show.html.erb
index 2e37317..12fc5f6 100644 (file)
@@ -9,7 +9,7 @@ class PicturesController < ApplicationController
   before_filter :authenticate_admin!, :only => [:list, :browse]
   
   def show
-    @picture = Picture.show(params[:id], @author)
+    @picture = Picture.show(params[:id], [@author, @admin, @demand_user])
 
     respond_to do |format|
       opt = {:type => @picture.mime_type, :disposition=>"inline"}
@@ -22,7 +22,7 @@ class PicturesController < ApplicationController
   end
   
   def credit
-    @picture = Picture.show(params[:id], @author)
+    @picture = Picture.show(params[:id], [@author, @admin, @demand_user])
 
     respond_to do |format|
       format.html { render :layout => false } # show.html.erb
index ab9e01d..4f9479b 100644 (file)
@@ -1,7 +1,7 @@
 class ResourcePicturesController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
   if MagicNumber['run_mode'] == 0
-    before_filter :authenticate_resource_user, :only => [:new, :create, :update, :destroy]
+    before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
     before_filter :authenticate_artist, :only => [:new, :create, :destroy]
   else
     before_filter :authenticate_resource_reader, :only => [:index, :show, :credit]
@@ -26,7 +26,7 @@ class ResourcePicturesController < ApplicationController
   # GET /resource_pictures/1
   # GET /resource_pictures/1.json
   def show
-    @resource_picture = ResourcePicture.show(params[:id], @author)
+    @resource_picture = ResourcePicture.show(params[:id], [@author, @admin, @demand_user])
 
     respond_to do |format|
       opt = {:type => @resource_picture.mime_type, :disposition=>"inline"}
index 7199852..607554b 100644 (file)
@@ -22,7 +22,7 @@ class SpeechBalloonTemplatesController < ApplicationController
   # GET /speech_balloon_templates/1
   # GET /speech_balloon_templates/1.json
   def show
-    @speech_balloon_template = SpeechBalloonTemplate.show(params[:id], @author)
+    @speech_balloon_template = SpeechBalloonTemplate.show(params[:id], [@author, @admin])
 
     respond_to do |format|
       format.html # show.html.erb
index 543c4c3..5d2d711 100644 (file)
@@ -20,7 +20,7 @@ class SpeechBalloonsController < ApplicationController
   end
   
   def show
-    @speech_balloon = SpeechBalloon.show(params[:id], @author)
+    @speech_balloon = SpeechBalloon.show(params[:id], [@author, @admin])
     respond_to do |format|
       format.html # show.html.erb
       format.json { render json: @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
index d911107..48141d3 100644 (file)
@@ -20,7 +20,7 @@ class SpeechesController < ApplicationController
   end
   
   def show
-    @speech = Speech.show(params[:id], @author)
+    @speech = Speech.show(params[:id], [@author, @admin])
     respond_to do |format|
       format.html # show.html.erb
       format.json { render json: @speech.to_json(Speech.show_json_opt) }
index 1ad4001..ec4aefb 100644 (file)
@@ -20,7 +20,7 @@ class StoriesController < ApplicationController
   end
 
   def show
-    @story = Story.show(params[:id], @author)
+    @story = Story.show(params[:id], [@author, @admin])
 
     respond_to do |format|
       format.html # show.html.erb
@@ -29,7 +29,7 @@ class StoriesController < ApplicationController
   end
   
   def comic
-    @comic = Comic.show(params[:id], @author)
+    @comic = Comic.show(params[:id], [@author, @admin])
     cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i
     @offset = Story.offset cnt, params[:offset]
     @panel_count = Story.panel_count cnt, params[:count]
index bfd9b76..6ac95a6 100644 (file)
@@ -16,23 +16,18 @@ class Artist < ActiveRecord::Base
     self.author_id = au.id
   end
   
-  def own? au
-    if au.is_a?(Author)
-      self.author_id == au.id
-    elsif au.is_a?(Artist)
-      self.id == au.id
-    else
-      false
-    end
+  def own? roles
+    roles = [roles] unless roles.respond_to?(:each)
+    au = Artist.get_author_from_roles roles
+    return false unless au
+    self.author_id == au.id
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless resource_reader_role_check(roles)
     end
     true
   end
index 4149e76..3fd96ec 100644 (file)
@@ -15,20 +15,20 @@ class Author < ActiveRecord::Base
     self.user_id = uid
   end
   
-  def own? au
-    return false unless au.is_a?(Author)
+  def own? roles
+    roles = [roles] unless roles.respond_to?(:each)
+    au = Author.get_author_from_roles roles
+    return false unless au
     self.id == au.id
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
-    true
+    return true
   end
   
   def artist?
@@ -77,11 +77,11 @@ class Author < ActiveRecord::Base
     {:include => {:artist => {}} }
   end
   
-  def self.show aid, au
+  def self.show aid, roles
     opt = {}
     opt.merge!(Author.show_opt)
     res = Author.find(aid, opt)
-    raise ActiveRecord::Forbidden unless res.visible?(au)
+    raise ActiveRecord::Forbidden unless res.visible?(roles)
     res
   end
   
index 14143a6..84604bf 100644 (file)
@@ -15,16 +15,14 @@ class Balloon < ActiveRecord::Base
     '/system_pictures/' + self.system_picture.filename
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-    elsif au.is_a?(Admin)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
-    self.speech_balloon.visible? au
+    return true if self.speech_balloon.panel.own?(roles)
+    self.speech_balloon.panel.visible? roles
   end
   
   def self.default_page_size
index e9b1298..c60e519 100644 (file)
@@ -15,19 +15,20 @@ class Comic < ActiveRecord::Base
     self.author_id = au.id
   end
   
-  def own? au
-    return false unless au.is_a?(Author)
+  def own? roles
+    roles = [roles] unless roles.respond_to?(:each)
+    au = Comic.get_author_from_roles roles
+    return false unless au
     self.author_id == au.id
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-      return true if self.own?(au)
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
+    return true if self.own?(roles)
     self.visible > 0
   end
   
@@ -84,11 +85,11 @@ class Comic < ActiveRecord::Base
     Comic.find(:all, opt)
   end
   
-  def self.show cid, au
+  def self.show cid, roles
     opt = {}
     opt.merge!(Comic.show_opt)
     res = Comic.find(cid, opt)
-    raise ActiveRecord::Forbidden unless res.visible?(au)
+    raise ActiveRecord::Forbidden unless res.visible?(roles)
     res
   end
   
index 58fa057..b89e698 100644 (file)
@@ -12,16 +12,14 @@ class GroundColor < ActiveRecord::Base
   def overwrite
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-    elsif au.is_a?(Admin)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
-    self.panel.publish?
+    return true if self.panel.own?(roles)
+    self.panel.visible? roles
   end
   
   def self.default_page_size
@@ -69,11 +67,11 @@ class GroundColor < ActiveRecord::Base
     GroundColor.find(:all, opt)
   end
   
-  def self.show cid, au
+  def self.show cid, roles
     opt = {}
     opt.merge!(GroundColor.show_opt)
     res = GroundColor.find(cid, opt)
-    raise ActiveRecord::Forbidden unless res.visible?(au)
+    raise ActiveRecord::Forbidden unless res.visible?(roles)
     res
   end
   
index f9aa110..bda16d3 100644 (file)
@@ -18,16 +18,14 @@ class GroundPicture < ActiveRecord::Base
   def overwrite
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-    elsif au.is_a?(Admin)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
-    self.panel.publish?
+    return true if self.panel.own?(roles)
+    self.panel.visible? roles
   end
   
   def self.default_page_size
index f55c06b..db2d272 100644 (file)
@@ -18,19 +18,16 @@ class OriginalPicture < ActiveRecord::Base
     self.artist_id = ar.id
   end
   
-  def own? ar
-    if ar.is_a?(Author)
-      self.artist_id == ar.artist.id
-    elsif ar.is_a?(Artist)
-      self.artist_id == ar.id
-    else
-      false
-    end
+  def own? roles
+    roles = [roles] unless roles.respond_to?(:each)
+    ar = OriginalPicture.get_artist_from_roles roles
+    return false unless ar
+    self.artist_id == ar.id
   end
   
-  def visible? ar
-    return true if ar.is_a?(Admin)
-    self.own?(ar)
+  def visible? roles
+    return true if self.admin_role_check roles
+    self.own?(roles)
   end
   
   def filename
@@ -111,11 +108,11 @@ class OriginalPicture < ActiveRecord::Base
     {:include => {:resource_picture => {}, :pictures => {}}}
   end
   
-  def self.show cid, ar
+  def self.show cid, roles
     opt = {}
     opt.merge!(self.show_opt)
     res = OriginalPicture.find(cid, opt)
-    raise ActiveRecord::Forbidden unless res.visible?(ar)
+    raise ActiveRecord::Forbidden unless res.visible?(roles)
     res
   end
   
index 1d87d74..3ff90f6 100644 (file)
@@ -32,19 +32,20 @@ class Panel < ActiveRecord::Base
     self.author_id = au.id
   end
   
-  def own? au
-    return false unless au.is_a?(Author)
+  def own? roles
+    roles = [roles] unless roles.respond_to?(:each)
+    au = Panel.get_author_from_roles roles
+    return false unless au
     self.author_id == au.id
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-      return true if self.own?(au)
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
+    return true if self.own?(roles)
     self.publish?
   end
   
@@ -111,11 +112,11 @@ class Panel < ActiveRecord::Base
     Panel.find(:all, opt)
   end
   
-  def self.show rid, au
+  def self.show rid, roles
     opt = {}
     opt.merge!(Panel.show_opt)
     res = Panel.find(rid, opt)
-    raise ActiveRecord::Forbidden unless res.visible?(au)
+    raise ActiveRecord::Forbidden unless res.visible?(roles)
     res
   end
   
index d9d1713..6683029 100644 (file)
@@ -11,16 +11,14 @@ class PanelColor < ActiveRecord::Base
   def overwrite
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-    elsif au.is_a?(Admin)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
-    self.panel.publish?
+    return true if self.panel.own?(roles)
+    self.panel.visible? roles
   end
   
   def self.default_page_size
@@ -68,11 +66,11 @@ class PanelColor < ActiveRecord::Base
     PanelColor.find(:all, opt)
   end
   
-  def self.show cid, au
+  def self.show cid, roles
     opt = {}
     opt.merge!(PanelColor.show_opt)
     res = PanelColor.find(cid, opt)
-    raise ActiveRecord::Forbidden unless res.visible?(au)
+    raise ActiveRecord::Forbidden unless res.visible?(roles)
     res
   end
   
index 6c1342a..5714e22 100644 (file)
@@ -12,16 +12,14 @@ class PanelPicture < ActiveRecord::Base
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-    elsif au.is_a?(Admin)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
-    self.panel.publish?
+    return true if self.panel.own?(roles)
+    self.panel.visible? roles
   end
   
   def flip
index 3b1fc56..771a4a4 100644 (file)
@@ -29,14 +29,11 @@ class Picture < ActiveRecord::Base
     self.revision = self.new_revision   #Do not move to attr. new_revision reffernces self.original_picture_id
   end
   
-  def own? ar
-    if ar.is_a?(Author)
-      self.artist_id == ar.artist.id
-    elsif ar.is_a?(Artist)
-      self.artist_id == ar.id
-    else
-      false
-    end
+  def own? roles
+    roles = [roles] unless roles.respond_to?(:each)
+    ar = Picture.get_artist_from_roles roles
+    return false unless ar
+    self.artist_id == ar.id
   end
   
   def visible? ar
@@ -125,10 +122,10 @@ class Picture < ActiveRecord::Base
     Picture.list_by_md5(md5, opid).empty? ? false : true
   end
   
-  def self.show rid, au
+  def self.show rid, roles
     opt = {}
     r = Picture.find(rid, opt)
-    raise ActiveRecord::Forbidden unless r.visible?(au)
+    raise ActiveRecord::Forbidden unless r.visible?(roles)
     r
   end
   
index 15999d6..9d113a5 100644 (file)
@@ -28,18 +28,18 @@ class ResourcePicture < ActiveRecord::Base
     self.attributes = attr
   end
   
-  def own? ar
-    return false unless ar.is_a?(Artist)
-    ar.id == self.artist_id
+  def own? roles
+    roles = [roles] unless roles.respond_to?(:each)
+    ar = ResourcePicture.get_artist_from_roles roles
+    return false unless ar
+    self.artist_id == ar.id
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless resource_reader_role_check(roles)
     end
     true
   end
@@ -123,11 +123,11 @@ class ResourcePicture < ActiveRecord::Base
     ResourcePicture.find(:all, opt)
   end
   
-  def self.show rid, au
+  def self.show rid, roles
     opt = {}
     opt.merge!(self.show_opt)
     r = ResourcePicture.find(rid, opt)
-    raise ActiveRecord::Forbidden unless r.visible?(au)
+    raise ActiveRecord::Forbidden unless r.visible?(roles)
     r
   end
   
index 508e816..1cb8403 100644 (file)
@@ -8,16 +8,14 @@ class Speech < ActiveRecord::Base
   validates :height, :presence => true, :numericality => true, :natural_number => true
 #  validates :settings, :presence => true
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-    elsif au.is_a?(Admin)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
-    self.speech_balloon.visible? au
+    return true if self.speech_balloon.panel.own?(roles)
+    self.speech_balloon.panel.visible? roles
   end
   
   def self.default_page_size
index 8e349e1..825eeb3 100644 (file)
@@ -14,16 +14,14 @@ class SpeechBalloon < ActiveRecord::Base
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
 #  validates :settings, :presence => true
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-    elsif au.is_a?(Admin)
-      return true
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
-    self.panel.publish?
+    return true if self.panel.own?(roles)
+    self.panel.visible? roles
   end
   
   def self.default_page_size
index b4c609c..10b1a9e 100644 (file)
@@ -20,20 +20,21 @@ class Story < ActiveRecord::Base
     self.author_id = au.id
   end
   
-  def own? au
-    return false unless au.is_a?(Author)
+  def own? roles
+    roles = [roles] unless roles.respond_to?(:each)
+    au = Story.get_author_from_roles roles
+    return false unless au
     self.author_id == au.id
   end
   
-  def visible? au
-    if au == nil
-      return false if MagicNumber['run_mode'] == 1
-    elsif au.is_a?(Author)
-      return true if self.comic.own?(au)
+  def visible? roles
+    if MagicNumber['run_mode'] == 0
+      return false unless guest_role_check(roles)
     else
-      return false
+      return false unless reader_role_check(roles)
     end
-    self.comic.visible? au
+    return true if self.comic.own?(roles)
+    self.comic.visible? roles
   end
   
   def self.default_panel_size
@@ -132,11 +133,11 @@ class Story < ActiveRecord::Base
     Story.find(:all, opt)
   end
   
-  def self.show sid, au
+  def self.show sid, roles
     opt = {}
     opt.merge!(Story.show_opt)
     res = Story.find sid, opt
-    raise ActiveRecord::Forbidden unless res.visible?(au)
+    raise ActiveRecord::Forbidden unless res.visible?(roles)
     res
   end
   
index 631b3c5..50e6ec3 100644 (file)
@@ -21,7 +21,10 @@ class SystemPicture < ActiveRecord::Base
   def overwrite
   end
   
-  def own? ad
+  def own? roles
+    roles = [roles] unless roles.respond_to?(:each)
+    ad = SystemPicture.get_admin_from_roles roles
+    return false unless ad
     true
   end
   
index 89544d5..374d7f3 100644 (file)
@@ -6,4 +6,5 @@ require 'RMagick'
 Pettanr::Application.initialize!
 require 'picture_io'
 require 'pettan_imager'
+require 'ar_helper'
 
diff --git a/lib/ar_helper.rb b/lib/ar_helper.rb
new file mode 100644 (file)
index 0000000..8a8be92
--- /dev/null
@@ -0,0 +1,77 @@
+
+module ActiveRecord
+  class Base
+    module ActiveRecordHelper
+      def self.included(base)
+        base.extend(ClassMethods)
+        base.__send__ :include, InstanceMethods
+      end
+      
+      module ClassMethods
+        def get_author_from_roles roles
+          roles.each do |role|
+            return role if role.is_a?(Author)
+            return role.author if role.is_a?(User)
+            return role.author if role.is_a?(Artist) and role.author
+          end
+          nil
+        end
+        
+        def get_artist_from_roles roles
+          roles.each do |role|
+            return role.artist if role.is_a?(Author) and role.artist
+            return role.author.artist if role.is_a?(User) and role.author and role.author.artist
+            return role if role.is_a?(Artist)
+          end
+          nil
+        end
+        
+        def get_admin_from_roles roles
+          roles.each do |role|
+            return role if role.is_a?(Admin)
+          end
+          nil
+        end
+        
+      end
+      
+      module InstanceMethods
+        private
+        
+        public
+        
+        def guest_role_check roles
+          true
+        end
+        
+        def reader_role_check roles
+          roles = [roles] unless roles.respond_to?(:each)
+          roles.each do |role|
+            return true if role.is_a?(Author) or role.is_a?(Artist) or role.is_a?(Admin) or role.is_a?(User)
+          end
+          false
+        end
+        
+        def resource_reader_role_check roles
+          roles = [roles] unless roles.respond_to?(:each)
+          roles.each do |role|
+            return true if role.is_a?(Author) or role.is_a?(Artist) or role.is_a?(Admin) or role.is_a?(User) or role.is_a?(DemandUser)
+          end
+          false
+        end
+        
+        def admin_role_check roles
+          roles = [roles] unless roles.respond_to?(:each)
+          roles.each do |role|
+            return true if role.is_a?(Admin)
+          end
+          false
+        end
+        
+      end
+      
+    end
+    include ActiveRecordHelper
+  end
+end
+
index 6399b6e..2a6c289 100644 (file)
@@ -5,6 +5,7 @@ require 'spec_helper'
 describe ArtistsController do
   before do
     @admin = FactoryGirl.create :admin
+    @demand_user = FactoryGirl.create :demand_user
     @sp = FactoryGirl.create :system_picture
     @lg = FactoryGirl.create :license_group
     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@@ -120,6 +121,16 @@ if MagicNumber['run_mode'] == 1
         response.should be_success 
       end
     end
+    context '作家権限はないが借手権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @demand_user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+    end
   end
   
   describe '閲覧に於いて' do
@@ -197,6 +208,16 @@ if MagicNumber['run_mode'] == 1
         response.should be_success 
       end
     end
+    context '作家権限はないが借手権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @demand_user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @artist.id
+        response.should be_success 
+      end
+    end
 =begin
     context '対象作家がないとき' do
       context 'html形式' do
index dafd395..1463f15 100644 (file)
@@ -128,8 +128,8 @@ if MagicNumber['run_mode'] == 1
   describe '単体表示に於いて' do\r
     before do\r
       @panel = FactoryGirl.create :panel, :author_id => @user.author.id\r
-      Panel.stub(:show).with(@panel.id.to_s, @author).and_return(@panel)\r
-      Panel.stub(:show).with(@panel.id.to_s, nil).and_return(@panel)\r
+      Panel.stub(:show).with(@panel.id.to_s, [@author, nil]).and_return(@panel)\r
+      Panel.stub(:show).with(@panel.id.to_s, [nil, @admin]).and_return(@panel)\r
       sign_in @user\r
     end\r
     context 'つつがなく終わるとき' do\r
index 637a4cb..23dbd0f 100644 (file)
@@ -20,8 +20,9 @@ if MagicNumber['run_mode'] == 1
     before do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       sign_in @user
-      Picture.stub(:show).with(@p.id.to_s, @author).and_return(@p)
-      Picture.stub(:show).with(@p.id.to_s, nil).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [@author, nil, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
     end
     context 'つつがなく終わるとき as json' do
       it 'ステータスコード200 OKを返す' do
@@ -183,8 +184,9 @@ if MagicNumber['run_mode'] == 1
     before do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       sign_in @user
-      Picture.stub(:show).with(@p.id.to_s, @author).and_return(@p)
-      Picture.stub(:show).with(@p.id.to_s, nil).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [@author, nil, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
     end
     context 'つつがなく終わるとき' do
       it 'ステータスコード200 OKを返す' do
index be82c0f..1835a8d 100644 (file)
@@ -147,8 +147,9 @@ if MagicNumber['run_mode'] == 1
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       sign_in @user
-      ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
-      ResourcePicture.stub(:show).with(@rp.id.to_s, nil).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [@author, nil, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp)
     end
     context 'つつがなく終わるとき' do
       it '素材モデルに単体取得を問い合わせている' do
index 37677b0..afad3fa 100644 (file)
@@ -105,8 +105,8 @@ if MagicNumber['run_mode'] == 1
   describe '単体表示に於いて' do
     before do
       sign_in @user
-      SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, @author).and_return(@sbt)
-      SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, nil).and_return(@sbt)
+      SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [@author, nil]).and_return(@sbt)
+      SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [nil, @admin]).and_return(@sbt)
     end
     context 'つつがなく終わるとき' do
       it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
index b01f7d5..3b8345f 100644 (file)
@@ -129,14 +129,14 @@ if MagicNumber['run_mode'] == 1
     before do
       sign_in @user
       @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
-      Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
-      Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
-      Story.stub(:show).with(@story.id.to_s, @author).and_return(@story)
-      Story.stub(:show).with(@story.id.to_s, nil).and_return(@story)
+      Comic.stub(:show).with(@comic.id.to_s, [@author, nil]).and_return(@comic)
+      Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
+      Story.stub(:show).with(@story.id.to_s, [@author, nil]).and_return(@story)
+      Story.stub(:show).with(@story.id.to_s, [nil, @admin]).and_return(@story)
     end
     context 'つつがなく終わるとき' do
       it 'ストーリーモデルに単体取得を問い合わせている' do
-        Story.should_receive(:show).with(@story.id.to_s, @author).exactly(1)
+        Story.should_receive(:show).with(@story.id.to_s, [@author, nil]).exactly(1)
         get :show, :id => @story.id
       end
       it '@storyにアレを取得している' do
@@ -215,8 +215,8 @@ if MagicNumber['run_mode'] == 1
   describe '閲覧に於いて' do
     before do
       @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
-      Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
-      Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
+      Comic.stub(:show).with(@comic.id.to_s, [@author, nil]).and_return(@comic)
+      Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
       Story.stub(:count).and_return(10)
       Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
       sign_in @user
@@ -249,7 +249,7 @@ if MagicNumber['run_mode'] == 1
     end
     context '事前チェックする' do
       it 'コミックモデルに単体取得を問い合わせている' do
-        Comic.should_receive(:show).with(@comic.id.to_s, @author).exactly(1)
+        Comic.should_receive(:show).with(@comic.id.to_s, [@author, nil]).exactly(1)
         get :comic, :id => @comic.id
       end
       it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
index 7893a0c..31a5a74 100644 (file)
@@ -70,14 +70,33 @@ describe Artist do
       @artist = FactoryGirl.create :artist, :author_id => @author.id
       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
     end
-    it '自分の絵師ならyes' do
-      @artist.own?(@author).should == true
+    context '事前チェックする' do
+      it '自身にロールリストからの作家取得を依頼している' do
+        Artist.should_receive(:get_author_from_roles).with(any_args).exactly(1)
+        r = @artist.own?([@author])
+      end
     end
-    it '他人の絵師ならno' do
-      @artist.own?(@other_author).should == false
+    context 'ロール内作家が取得できるとき' do
+      before do
+      end
+      it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+        Artist.stub(:get_author_from_roles).with(any_args).and_return(@author)
+        r = @artist.own?([@author])
+        r.should be_true
+      end
+      it 'ロール内作家のidが自身の作家idと一致しないならno' do
+        Artist.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
+        @artist.own?(@other_author).should be_false
+      end
     end
-    it 'パラメータが作家でないならならno' do
-      @artist.own?(nil).should == false
+    context 'ロール内作家が取得できないとき' do
+      before do
+        Artist.stub(:get_author_from_roles).with(any_args).and_return(nil)
+      end
+      it 'Falseを返す' do
+        r = @artist.own?([@author])
+        r.should be_false
+      end
     end
   end
   
@@ -85,38 +104,46 @@ describe Artist do
     before do
       @artist = FactoryGirl.create :artist, :author_id => @author.id
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @artist.visible?(nil)
-          r.should be_false
-        end
-      end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '許可する' do
-          r = @artist.visible?(nil)
-          r.should be_true
-        end
-      end
-    end
-    context '検査対象が作家のとき' do
-      it '許可する' do
-        r = @artist.visible?(@author)
-        r.should == true
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
+      end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        Artist.any_instance.stub(:guest_role_check).and_return(true)
+        Artist.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @artist.visible?([@author])
+      end
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+        Artist.any_instance.stub(:guest_role_check).and_return(false)
+        r = @artist.visible?([@author])
+        r.should be_false
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @artist.visible?(@admin)
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に素材読者用ロールチェックを問い合わせしている' do
+        Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
+        Artist.any_instance.should_receive(:resource_reader_role_check).with(any_args).exactly(1)
+        r = @artist.visible?([@author])
+      end
+      it '素材読者用ロールチェックが失敗したとき、falseを返す' do
+        Artist.any_instance.stub(:resource_reader_role_check).and_return(false)
+        r = @artist.visible?([@author])
         r.should be_false
       end
     end
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
+      end
+      it '許可する' do
+        r = @artist.visible?([@author])
+        r.should be_true
+      end
+    end
   end
   
   describe '一覧取得に於いて' do
index f839919..7550611 100644 (file)
@@ -64,54 +64,87 @@ describe Author do
   describe '所持判定に於いて' do
     before do
       @other_user = FactoryGirl.create :user_yas
-#アカウントを作ると連動して作家ができる      @other_author = FactoryGirl.create :author_yas, :user_id => @other_user.id
+      @other_author = @other_user.author
     end
-    it '作家自身ならyes' do
-      @author.own?(@author).should == true
+    context '事前チェックする' do
+      it '自身にロールリストからの作家取得を依頼している' do
+        Author.should_receive(:get_author_from_roles).with(any_args).exactly(1)
+        r = @author.own?([@author])
+      end
     end
-    it '作家自身でなければno' do
-      @author.own?(@other_author).should == false
+    context 'ロール内作家が取得できるとき' do
+      before do
+      end
+      it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+        Author.stub(:get_author_from_roles).with(any_args).and_return(@author)
+        r = @author.own?([@author])
+        r.should be_true
+      end
+      it 'ロール内作家のidが自身の作家idと一致しないならno' do
+        Author.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
+        @author.own?(@other_author).should be_false
+      end
     end
-    it 'パラメータが作家でないならno' do
-      @author.own?(nil).should == false
+    context 'ロール内作家が取得できないとき' do
+      before do
+        Author.stub(:get_author_from_roles).with(any_args).and_return(nil)
+      end
+      it 'Falseを返す' do
+        r = @author.own?([@author])
+        r.should be_false
+      end
     end
   end
   
   describe '閲覧許可に於いて' do
     before do
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @author.visible?(nil)
-          r.should be_false
-        end
-      end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '許可する' do
-          r = @author.visible?(nil)
-          r.should be_true
-        end
-      end
-    end
-    context '検査対象が作家のとき' do
-      it '許可する' do
-        r = @author.visible?(@author)
-        r.should == true
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
+      end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        Author.any_instance.stub(:guest_role_check).and_return(true)
+        Author.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @author.visible?([@author])
+      end
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+        Author.any_instance.stub(:guest_role_check).and_return(false)
+        r = @author.visible?([@author])
+        r.should be_false
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @author.visible?(@admin)
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        Author.any_instance.stub(:reader_role_check).and_return(true)
+        Author.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @author.visible?([@author])
+      end
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        Author.any_instance.stub(:reader_role_check).and_return(false)
+        r = @author.visible?([@author])
         r.should be_false
       end
     end
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Author.any_instance.stub(:reader_role_check).and_return(true)
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Author.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '許可する' do
+        r = @author.visible?([@author])
+        r.should be_true
+      end
+    end
   end
   
   describe '絵師作家判定に於いて' do
index 9749500..78f0da0 100644 (file)
@@ -148,58 +148,79 @@ describe Balloon do
       @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
       @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
     end\r
-    context '検査対象がnil(ゲスト)のとき' do\r
-      context 'クローズドモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 1\r
-        end\r
-        it '不許可を返す。' do\r
-          r = @balloon.visible?(nil)\r
-          r.should be_false\r
-        end\r
+    context 'オープンモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 0\r
       end\r
-      context 'オープンモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 0\r
-        end\r
-        it '公開されたコマのフキダシ枠なら許可する' do\r
-          SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)\r
-          r = @balloon.visible?(nil)\r
-          r.should be_true\r
-        end\r
-        it 'れ以外なら不許可を返す' do\r
-          SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
-          r = @balloon.visible?(nil)\r
-          r.should be_false\r
-        end\r
+      it '自身にゲスト用ロールチェックを問い合わせしている' do\r
+        Balloon.any_instance.stub(:guest_role_check).and_return(true)\r
+        Balloon.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)\r
+        r = @balloon.visible?([@author])\r
+      end\r
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do\r
+        Balloon.any_instance.stub(:guest_role_check).and_return(false)\r
+        r = @balloon.visible?([@author])\r
+        r.should be_false\r
       end\r
     end\r
-    context '検査対象が作家のとき' do\r
-      it '公開されたコマのフキダシ枠なら許可する' do\r
-        SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)\r
-        r = @balloon.visible?(@author)\r
-        r.should be_true\r
+    context 'クローズドモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+      end\r
+      it '自身に読者用ロールチェックを問い合わせしている' do\r
+        Balloon.any_instance.stub(:reader_role_check).and_return(true)\r
+        Balloon.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)\r
+        r = @balloon.visible?([@author])\r
       end\r
-      it 'れ以外なら不許可を返す' do\r
-        SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
-        r = @balloon.visible?(@author)\r
+      it '読者用ロールチェックが失敗したとき、falseを返す' do\r
+        Balloon.any_instance.stub(:reader_role_check).and_return(false)\r
+        r = @balloon.visible?([@author])\r
         r.should be_false\r
       end\r
     end\r
-    context '検査対象が管理者のとき' do\r
-      it '許可を返す。' do\r
-        SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
-        r = @balloon.visible?(@admin)\r
-        r.should be_true\r
+    context '事前チェックする' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+        Balloon.any_instance.stub(:reader_role_check).and_return(true)\r
+      end\r
+      it '自身のコマに所持判定を問い合わせしている' do\r
+        Panel.any_instance.stub(:own?).and_return(true)\r
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
+        r = @balloon.visible?([@author])\r
+      end\r
+      it '自身のコマに閲覧許可を問い合わせしている' do\r
+        Panel.any_instance.stub(:own?).and_return(false)\r
+        Panel.any_instance.stub(:visible?).and_return(true)\r
+        Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
+        r = @balloon.visible?([@author])\r
       end\r
     end\r
-    context '検査対象がそれ以外のとき' do\r
-      it '不許可を返す。' do\r
-        r = @balloon.visible?(1)\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+        Panel.any_instance.stub(:reader_role_check).and_return(true)\r
+      end\r
+      it '自分のコマのコマ絵なら許可する' do\r
+        Panel.any_instance.stub(:own?).and_return(true)\r
+        Panel.any_instance.stub(:visible?).and_return(false)\r
+        r = @balloon.visible?([@author])\r
+        r.should be_true\r
+      end\r
+      it '他人の非公開コマのコマ絵なら許可しない' do\r
+        Panel.any_instance.stub(:own?).and_return(false)\r
+        Panel.any_instance.stub(:visible?).and_return(false)\r
+        r = @balloon.visible?([@author])\r
         r.should be_false\r
       end\r
+      it '他人のコマのコマ絵でも公開なら許可する' do\r
+        Panel.any_instance.stub(:own?).and_return(false)\r
+        Panel.any_instance.stub(:visible?).and_return(true)\r
+        r = @balloon.visible?([@author])\r
+        r.should be_true\r
+      end\r
     end\r
   end\r
+  \r
   describe '一覧取得に於いて' do\r
     before do\r
       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
index 78a6f7a..35792c1 100644 (file)
@@ -5,6 +5,7 @@ require 'spec_helper'
 describe Comic do
   before do
     @admin = FactoryGirl.create :admin
+    @demand_user = FactoryGirl.create :demand_user
     @sp = FactoryGirl.create :system_picture
     @lg = FactoryGirl.create :license_group
     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@@ -76,18 +77,195 @@ describe Comic do
     end
   end
   
+  describe 'ロールリストからの作家取得に於いて' do
+    context 'ロールがユーザのとき' do
+      it 'ユーザから作家を取得して、それを返す' do
+        r = Comic.get_author_from_roles([@user])
+        r.should eq @author
+      end
+    end
+    context 'ロールが作家のとき' do
+      it '作家を返す' do
+        r = Comic.get_author_from_roles([@author])
+        r.should eq @author
+      end
+    end
+    context 'ロールが絵師のとき' do
+      it '絵師から作家を取得できれば、それをを返す' do
+        r = Comic.get_author_from_roles([@artist])
+        r.should eq @author
+      end
+      it '絵師から作家を取得できないときnilを返す' do
+        @artist.author_id = nil
+        @artist.save!
+        r = Comic.get_author_from_roles([@artist])
+        r.should be_nil
+      end
+    end
+    context 'ロールが管理者のとき' do
+      it 'nilを返す' do
+        r = Comic.get_author_from_roles([@admin])
+        r.should be_nil
+      end
+    end
+  end
+  
+  describe 'ロールリストからの絵師取得に於いて' do
+    context 'ロールがユーザのとき' do
+      it 'ユーザから作家を取得して、そこから絵師を取得できれば、それを返す' do
+        r = Comic.get_artist_from_roles([@user])
+        r.should eq @artist
+      end
+      it '作家から絵師を取得できないときnilを返す' do
+        @artist.author_id = nil
+        @artist.save!
+        r = Comic.get_artist_from_roles([@user])
+        r.should be_nil
+      end
+    end
+    context 'ロールが作家のとき' do
+      it 'そこから絵師を取得できれば、それを返す' do
+        r = Comic.get_artist_from_roles([@author])
+        r.should eq @artist
+      end
+      it '作家から絵師を取得できないときnilを返す' do
+        @artist.author_id = nil
+        @artist.save!
+        r = Comic.get_artist_from_roles([@author])
+        r.should be_nil
+      end
+    end
+    context 'ロールが絵師のとき' do
+      it 'それを返す' do
+        r = Comic.get_artist_from_roles([@artist])
+        r.should eq @artist
+      end
+    end
+    context 'ロールが管理者のとき' do
+      it 'nilを返す' do
+        r = Comic.get_artist_from_roles([@admin])
+        r.should be_nil
+      end
+    end
+  end
+  
   describe '所持判定に於いて' do
     before do
       @comic = FactoryGirl.build :comic, :author_id => @author.id
     end
-    it '自分のコミックならyes' do
-      @comic.own?(@author).should == true
+    context '事前チェックする' do
+      it '自身にロールリストからの作家取得を依頼している' do
+        Comic.should_receive(:get_author_from_roles).with(any_args).exactly(1)
+        r = @comic.own?([@author])
+      end
+    end
+    context 'ロール内作家が取得できるとき' do
+      before do
+      end
+      it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+        Comic.stub(:get_author_from_roles).with(any_args).and_return(@author)
+        r = @comic.own?([@author])
+        r.should be_true
+      end
+      it 'ロール内作家のidが自身の作家idと一致しないならno' do
+        Comic.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
+        @comic.own?(@other_author).should be_false
+      end
+    end
+    context 'ロール内作家が取得できないとき' do
+      before do
+        Comic.stub(:get_author_from_roles).with(any_args).and_return(nil)
+      end
+      it 'Falseを返す' do
+        r = @comic.own?([@author])
+        r.should be_false
+      end
+    end
+  end
+  
+  describe '読者用ロールチェックに於いて' do
+    before do
+      @comic = FactoryGirl.build :comic, :author_id => @author.id
+    end
+    context 'ロールリストに作家が含まれるとき' do
+      it 'ロールリストがリストではないとき、リストにする trueを返す' do
+        r = @comic.reader_role_check(@author)
+        r.should be_true
+      end
+      it 'trueを返す' do
+        r = @comic.reader_role_check([@author])
+        r.should be_true
+      end
+    end
+    context 'ロールリストに絵師が含まれるとき' do
+      it 'trueを返す' do
+        r = @comic.reader_role_check([@artist])
+        r.should be_true
+      end
+    end
+    context 'ロールリストにユーザが含まれるとき' do
+      it 'trueを返す' do
+        r = @comic.reader_role_check([@user])
+        r.should be_true
+      end
+    end
+    context 'ロールリストに管理者が含まれるとき' do
+      it 'trueを返す' do
+        r = @comic.reader_role_check([@admin])
+        r.should be_true
+      end
+    end
+    context 'ロールリストにユーザ、管理者、作家、絵師が含まれないとき' do
+      it 'falseを返す' do
+        r = @comic.reader_role_check([nil])
+        r.should be_false
+      end
+    end
+  end
+  
+  describe '素材読者用ロールチェックに於いて' do
+    before do
+      @comic = FactoryGirl.build :comic, :author_id => @author.id
+    end
+    context 'ロールリストに作家が含まれるとき' do
+      it 'ロールリストがリストではないとき、リストにする trueを返す' do
+        r = @comic.resource_reader_role_check(@author)
+        r.should be_true
+      end
+      it 'trueを返す' do
+        r = @comic.resource_reader_role_check([@author])
+        r.should be_true
+      end
     end
-    it '他人のコミックならno' do
-      @comic.own?(@other_author).should == false
+    context 'ロールリストに絵師が含まれるとき' do
+      it 'trueを返す' do
+        r = @comic.resource_reader_role_check([@artist])
+        r.should be_true
+      end
     end
-    it 'パラメータが作家でないならno' do
-      @comic.own?(nil).should == false
+    context 'ロールリストにユーザが含まれるとき' do
+      it 'trueを返す' do
+        r = @comic.resource_reader_role_check([@user])
+        r.should be_true
+      end
+    end
+    context 'ロールリストに管理者が含まれるとき' do
+      it 'trueを返す' do
+        r = @comic.resource_reader_role_check([@admin])
+        r.should be_true
+      end
+    end
+    context 'ロールリストに借手が含まれるとき' do
+      it 'trueを返す' do
+        r = @comic.resource_reader_role_check([@demand_user])
+        r.should be_true
+      end
+    end
+    context 'ロールリストにユーザ、管理者、作家、絵師、借手が含まれないとき' do
+      it 'falseを返す' do
+        r = @comic.resource_reader_role_check([nil])
+        r.should be_false
+      end
     end
   end
   
@@ -95,56 +273,69 @@ describe Comic do
     before do
       @comic = FactoryGirl.build :comic, :author_id => @author.id
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @comic.visible?(nil)
-          r.should be_false
-        end
-      end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '公開コミックなら許可する' do
-          Comic.any_instance.stub(:visible).and_return(1)
-          r = @comic.visible?(nil)
-          r.should be_true
-        end
-        it '非公開コミックなら許可しない' do
-          Comic.any_instance.stub(:visible).and_return(0)
-          r = @comic.visible?(nil)
-          r.should be_false
-        end
-      end
-    end
-    context '検査対象が作家のとき' do
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
+      end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        Comic.any_instance.stub(:guest_role_check).and_return(true)
+        Comic.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @comic.visible?([@author])
+      end
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+        Comic.any_instance.stub(:guest_role_check).and_return(false)
+        r = @comic.visible?([@author])
+        r.should be_false
+      end
+    end
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        Comic.any_instance.stub(:reader_role_check).and_return(true)
+        Comic.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @comic.visible?([@author])
+      end
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        Comic.any_instance.stub(:reader_role_check).and_return(false)
+        r = @comic.visible?([@author])
+        r.should be_false
+      end
+    end
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Comic.any_instance.stub(:reader_role_check).and_return(true)
+        Comic.any_instance.stub(:own?).and_return(true)
+      end
+      it '自身に所持判定を問い合わせしている' do
+        Comic.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @comic.visible?([@author])
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Comic.any_instance.stub(:reader_role_check).and_return(true)
+      end
       it '自分のコミックなら許可する' do
         Comic.any_instance.stub(:own?).and_return(true)
         Comic.any_instance.stub(:visible).and_return(0)
-        r = @comic.visible?(@author)
-        r.should == true
+        r = @comic.visible?([@author])
+        r.should be_true
       end
       it '他人の非公開コミックなら許可しない' do
         Comic.any_instance.stub(:own?).and_return(false)
         Comic.any_instance.stub(:visible).and_return(0)
-        r = @comic.visible?(@author)
-        r.should == false
+        r = @comic.visible?([@author])
+        r.should be_false
       end
       it '他人のコミックでも公開なら許可する' do
         Comic.any_instance.stub(:own?).and_return(false)
         Comic.any_instance.stub(:visible).and_return(1)
-        r = @comic.visible?(@author)
-        r.should == true
-      end
-    end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @comic.visible?(@admin)
-        r.should be_false
+        r = @comic.visible?([@author])
+        r.should be_true
       end
     end
   end
index c197829..6479ef9 100644 (file)
@@ -96,56 +96,76 @@ describe GroundColor do
     before do
       @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @gc.visible?(nil)
-          r.should be_false
-        end
-      end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '公開されたコマの選択色地なら許可する' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-          r = @gc.visible?(nil)
-          r.should be_true
-        end
-        it 'れ以外なら不許可を返す' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-          r = @gc.visible?(nil)
-          r.should be_false
-        end
-      end
-    end
-    context '検査対象が作家のとき' do
-      it '公開されたコマの選択色地なら許可する' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-        r = @gc.visible?(@author)
-        r.should be_true
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
+      end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        GroundColor.any_instance.stub(:guest_role_check).and_return(true)
+        GroundColor.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @gc.visible?([@author])
       end
-      it 'ã\82\8c以å¤\96ã\81ªã\82\89ä¸\8d許å\8f¯を返す' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @gc.visible?(@author)
+      it 'ã\82²ã\82¹ã\83\88ç\94¨ã\83­ã\83¼ã\83«ã\83\81ã\82§ã\83\83ã\82¯ã\81\8c失æ\95\97ã\81\97ã\81\9fã\81¨ã\81\8dã\80\81falseを返す' do
+        GroundColor.any_instance.stub(:guest_role_check).and_return(false)
+        r = @gc.visible?([@author])
         r.should be_false
       end
     end
-    context '検査対象が管理者のとき' do
-      it '許可を返す。' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @gc.visible?(@admin)
-        r.should be_true
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        GroundColor.any_instance.stub(:reader_role_check).and_return(true)
+        GroundColor.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @gc.visible?([@author])
+      end
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        GroundColor.any_instance.stub(:reader_role_check).and_return(false)
+        r = @gc.visible?([@author])
+        r.should be_false
+      end
+    end
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        GroundColor.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自身のコマに所持判定を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @gc.visible?([@author])
+      end
+      it '自身のコマに閲覧許可を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = @gc.visible?([@author])
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @gc.visible?(1)
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Panel.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自分のコマの選択色地なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @gc.visible?([@author])
+        r.should be_true
+      end
+      it '他人の非公開コマの選択色地なら許可しない' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @gc.visible?([@author])
         r.should be_false
       end
+      it '他人のコマの選択色地でも公開なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        r = @gc.visible?([@author])
+        r.should be_true
+      end
     end
   end
   
index ab72eb2..02e6054 100644 (file)
@@ -150,58 +150,79 @@ describe GroundPicture do
     before do
       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @gp.visible?(nil)
-          r.should be_false
-        end
-      end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '公開されたコマの絵地なら許可する' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-          r = @gp.visible?(nil)
-          r.should be_true
-        end
-        it 'れ以外なら不許可を返す' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-          r = @gp.visible?(nil)
-          r.should be_false
-        end
-      end
-    end
-    context '検査対象が作家のとき' do
-      it '公開されたコマの絵地なら許可する' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-        r = @gp.visible?(@author)
-        r.should be_true
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
+      end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        GroundPicture.any_instance.stub(:guest_role_check).and_return(true)
+        GroundPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @gp.visible?([@author])
       end
-      it 'ã\82\8c以å¤\96ã\81ªã\82\89ä¸\8d許å\8f¯を返す' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @gp.visible?(@author)
+      it 'ã\82²ã\82¹ã\83\88ç\94¨ã\83­ã\83¼ã\83«ã\83\81ã\82§ã\83\83ã\82¯ã\81\8c失æ\95\97ã\81\97ã\81\9fã\81¨ã\81\8dã\80\81falseを返す' do
+        GroundPicture.any_instance.stub(:guest_role_check).and_return(false)
+        r = @gp.visible?([@author])
         r.should be_false
       end
     end
-    context '検査対象が管理者のとき' do
-      it '許可を返す。' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @gp.visible?(@admin)
-        r.should be_true
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
+        GroundPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @gp.visible?([@author])
+      end
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        GroundPicture.any_instance.stub(:reader_role_check).and_return(false)
+        r = @gp.visible?([@author])
+        r.should be_false
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @gp.visible?(1)
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自身のコマに所持判定を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @gp.visible?([@author])
+      end
+      it '自身のコマに閲覧許可を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = @gp.visible?([@author])
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Panel.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自分のコマの絵地なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @gp.visible?([@author])
+        r.should be_true
+      end
+      it '他人の非公開コマの絵地なら許可しない' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @gp.visible?([@author])
         r.should be_false
       end
+      it '他人のコマの絵地でも公開なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        r = @gp.visible?([@author])
+        r.should be_true
+      end
     end
   end
+  
   describe '一覧取得に於いて' do
     before do
       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
index d154b85..92ea8aa 100644 (file)
@@ -153,29 +153,36 @@ describe OriginalPicture do
     end
   end
   
-  describe '作者判定に於いて' do
+  describe '所持判定に於いて' do
     before do
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
     end
-    context 'パラメータが作家のとき' do
-      it '自作の原画ならyes' do
-        @op.own?(@author).should == true
-      end
-      it '他人のならno' do
-        @op.own?(@other_author).should == false
+    context '事前チェックする' do
+      it '自身にロールリストからの絵師取得を依頼している' do
+        OriginalPicture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)
+        r = @op.own?([@artist])
       end
     end
-    context 'パラメータが絵師のとき' do
-      it '自作の原画ならyes' do
-        @op.own?(@artist).should == true
+    context 'ロール内絵師が取得できるとき' do
+      before do
+      end
+      it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do
+        OriginalPicture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)
+        r = @op.own?([@artist])
+        r.should be_true
       end
-      it '他人のならno' do
-        @op.own?(@other_artist).should == false
+      it 'ロール内絵師のidが自身の絵師idと一致しないならno' do
+        OriginalPicture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)
+        @op.own?(@other_artist).should be_false
       end
     end
-    context 'それ以外のとき' do
-      it 'no' do
-        @op.own?(nil).should == false
+    context 'ロール内絵師が取得できないとき' do
+      before do
+        OriginalPicture.stub(:get_artist_from_roles).with(any_args).and_return(nil)
+      end
+      it 'Falseを返す' do
+        r = @op.own?([@artist])
+        r.should be_false
       end
     end
   end
@@ -184,20 +191,30 @@ describe OriginalPicture do
     before do
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
     end
-    it '検査対象が管理者のとき、許可を返す' do
-      OriginalPicture.any_instance.stub(:own?).and_return(false)
-      r = @op.visible?(@admin)
-      r.should == true
-    end
-    it '所持判定を問い合わせ、自分の原画なら許可する' do
-      OriginalPicture.any_instance.stub(:own?).and_return(true)
-      r = @op.visible?(@artist)
-      r.should == true
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身の原画に所持判定を問い合わせしている' do
+        OriginalPicture.any_instance.stub(:own?).and_return(true)
+        OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @op.visible?([@artist])
+      end
     end
-    it '他人の原画なら許可しない' do
-      OriginalPicture.any_instance.stub(:own?).and_return(false)
-      r = @op.visible?(@artist)
-      r.should == false
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自分の原画なら許可する' do
+        OriginalPicture.any_instance.stub(:own?).and_return(true)
+        r = @op.visible?([@artist])
+        r.should be_true
+      end
+      it '他人の原画なら許可しない' do
+        OriginalPicture.any_instance.stub(:own?).and_return(false)
+        r = @op.visible?([@artist])
+        r.should be_false
+      end
     end
   end
   
index a35d20f..e1f5613 100644 (file)
@@ -114,56 +114,76 @@ describe PanelColor do
     before do
       @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @pc.visible?(nil)
-          r.should be_false
-        end
-      end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '公開されたコマの指定色地なら許可する' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-          r = @pc.visible?(nil)
-          r.should be_true
-        end
-        it 'れ以外なら不許可を返す' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-          r = @pc.visible?(nil)
-          r.should be_false
-        end
-      end
-    end
-    context '検査対象が作家のとき' do
-      it '公開されたコマの指定色地なら許可する' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-        r = @pc.visible?(@author)
-        r.should be_true
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
+      end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        PanelColor.any_instance.stub(:guest_role_check).and_return(true)
+        PanelColor.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @pc.visible?([@author])
       end
-      it 'ã\82\8c以å¤\96ã\81ªã\82\89ä¸\8d許å\8f¯を返す' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @pc.visible?(@author)
+      it 'ã\82²ã\82¹ã\83\88ç\94¨ã\83­ã\83¼ã\83«ã\83\81ã\82§ã\83\83ã\82¯ã\81\8c失æ\95\97ã\81\97ã\81\9fã\81¨ã\81\8dã\80\81falseを返す' do
+        PanelColor.any_instance.stub(:guest_role_check).and_return(false)
+        r = @pc.visible?([@author])
         r.should be_false
       end
     end
-    context '検査対象が管理者のとき' do
-      it '許可を返す。' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @pc.visible?(@admin)
-        r.should be_true
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        PanelColor.any_instance.stub(:reader_role_check).and_return(true)
+        PanelColor.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @pc.visible?([@author])
+      end
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        PanelColor.any_instance.stub(:reader_role_check).and_return(false)
+        r = @pc.visible?([@author])
+        r.should be_false
+      end
+    end
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        PanelColor.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自身のコマに所持判定を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @pc.visible?([@author])
+      end
+      it '自身のコマに閲覧許可を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = @pc.visible?([@author])
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @pc.visible?(1)
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Panel.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自分のコマの指定色地なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @pc.visible?([@author])
+        r.should be_true
+      end
+      it '他人の非公開コマの指定色地なら許可しない' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @pc.visible?([@author])
         r.should be_false
       end
+      it '他人のコマの指定色地でも公開なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        r = @pc.visible?([@author])
+        r.should be_true
+      end
     end
   end
   
index 29a214c..5b415ed 100644 (file)
@@ -289,63 +289,86 @@ describe PanelPicture do
       end
     end
   end
+  
   describe '閲覧許可に於いて' do
     before do
       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
         :width => @p.width, :height => @p.height
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @pp.visible?(nil)
-          r.should be_false
-        end
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
       end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '公開されたコマのコマ絵なら許可する' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-          r = @pp.visible?(nil)
-          r.should be_true
-        end
-        it 'れ以外なら不許可を返す' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-          r = @pp.visible?(nil)
-          r.should be_false
-        end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        PanelPicture.any_instance.stub(:guest_role_check).and_return(true)
+        PanelPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @pp.visible?([@author])
+      end
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+        PanelPicture.any_instance.stub(:guest_role_check).and_return(false)
+        r = @pp.visible?([@author])
+        r.should be_false
       end
     end
-    context '検査対象が作家のとき' do
-      it '公開されたコマのコマ絵なら許可する' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-        r = @pp.visible?(@author)
-        r.should be_true
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        PanelPicture.any_instance.stub(:reader_role_check).and_return(true)
+        PanelPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @pp.visible?([@author])
       end
-      it 'れ以外なら不許可を返す' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @pp.visible?(@author)
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        PanelPicture.any_instance.stub(:reader_role_check).and_return(false)
+        r = @pp.visible?([@author])
         r.should be_false
       end
     end
-    context '検査対象が管理者のとき' do
-      it '許可を返す。' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @pp.visible?(@admin)
-        r.should be_true
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        PanelPicture.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自身のコマに所持判定を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @pp.visible?([@author])
+      end
+      it '自身のコマに閲覧許可を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = @pp.visible?([@author])
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @pp.visible?(1)
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Panel.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自分のコマのコマ絵なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @pp.visible?([@author])
+        r.should be_true
+      end
+      it '他人の非公開コマのコマ絵なら許可しない' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @pp.visible?([@author])
         r.should be_false
       end
+      it '他人のコマのコマ絵でも公開なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        r = @pp.visible?([@author])
+        r.should be_true
+      end
     end
   end
+  
+  
   describe '一覧取得に於いて' do
     before do
       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
index b319970..9fa263d 100644 (file)
@@ -201,75 +201,115 @@ describe Panel do
     \r
   end\r
   \r
-  describe '作者判定に於いて' do\r
+  describe '所持判定に於いて' do\r
     before do\r
       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
     end\r
-    it '自作のコマならyes' do\r
-      @panel.own?(@author).should == true\r
+    context '事前チェックする' do\r
+      it '自身にロールリストからの作家取得を依頼している' do\r
+        Panel.should_receive(:get_author_from_roles).with(any_args).exactly(1)\r
+        r = @panel.own?([@author])\r
+      end\r
     end\r
-    it '他人のコマならno' do\r
-      @panel.own?(@other_author).should == false\r
+    context 'ロール内作家が取得できるとき' do\r
+      before do\r
+      end\r
+      it 'ロール内作家のidが自身の作家idと一致するなら許可する' do\r
+        Panel.stub(:get_author_from_roles).with(any_args).and_return(@author)\r
+        r = @panel.own?([@author])\r
+        r.should be_true\r
+      end\r
+      it 'ロール内作家のidが自身の作家idと一致しないならno' do\r
+        Panel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)\r
+        @panel.own?(@other_author).should be_false\r
+      end\r
     end\r
-    it 'パラメータが作家でないならno' do\r
-      @panel.own?(nil).should == false\r
+    context 'ロール内作家が取得できないとき' do\r
+      before do\r
+        Panel.stub(:get_author_from_roles).with(any_args).and_return(nil)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @panel.own?([@author])\r
+        r.should be_false\r
+      end\r
     end\r
   end\r
   \r
   describe '閲覧許可に於いて' do\r
     before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @author.id\r
       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
     end\r
-    context '検査対象がnil(ゲスト)のとき' do\r
-      context 'クローズドモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 1\r
-        end\r
-        it '不許可を返す。' do\r
-          r = @panel.visible?(nil)\r
-          r.should be_false\r
-        end\r
+    context 'オープンモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 0\r
       end\r
-      context 'オープンモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 0\r
-        end\r
-        it '公開コマなら許可する' do\r
-          Panel.any_instance.stub(:publish?).and_return(true)\r
-          r = @panel.visible?(nil)\r
-          r.should be_true\r
-        end\r
-        it '非公開コマなら許可しない' do\r
-          Panel.any_instance.stub(:publish?).and_return(false)\r
-          r = @panel.visible?(nil)\r
-          r.should be_false\r
-        end\r
+      it '自身にゲスト用ロールチェックを問い合わせしている' do\r
+        Panel.any_instance.stub(:guest_role_check).and_return(true)\r
+        Panel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)\r
+        r = @panel.visible?([@author])\r
+      end\r
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do\r
+        Panel.any_instance.stub(:guest_role_check).and_return(false)\r
+        r = @panel.visible?([@author])\r
+        r.should be_false\r
       end\r
     end\r
-    context '検査対象が作家のとき' do\r
-      it '自分のコマなら許可する' do\r
+    context 'クローズドモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+      end\r
+      it '自身に読者用ロールチェックを問い合わせしている' do\r
+        Panel.any_instance.stub(:reader_role_check).and_return(true)\r
+        Panel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)\r
+        r = @panel.visible?([@author])\r
+      end\r
+      it '読者用ロールチェックが失敗したとき、falseを返す' do\r
+        Panel.any_instance.stub(:reader_role_check).and_return(false)\r
+        r = @panel.visible?([@author])\r
+        r.should be_false\r
+      end\r
+    end\r
+    context '事前チェックする' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+        Panel.any_instance.stub(:reader_role_check).and_return(true)\r
+      end\r
+      it '自身に所持判定を問い合わせしている' do\r
         Panel.any_instance.stub(:own?).and_return(true)\r
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
+        r = @panel.visible?([@author])\r
+      end\r
+      it '自身に閲覧許可を問い合わせしている' do\r
+        Panel.any_instance.stub(:own?).and_return(false)\r
         Panel.any_instance.stub(:publish?).and_return(true)\r
-        r = @panel.visible?(@author)\r
-        r.should == true\r
+        Panel.any_instance.should_receive(:publish?).with(any_args).exactly(1)\r
+        r = @panel.visible?([@author])\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+        Panel.any_instance.stub(:reader_role_check).and_return(true)\r
+      end\r
+      it '自分のコマなら許可する' do\r
+        Panel.any_instance.stub(:own?).and_return(true)\r
+        Panel.any_instance.stub(:publish?).and_return(false)\r
+        r = @panel.visible?([@author])\r
+        r.should be_true\r
       end\r
       it '他人の非公開コマなら許可しない' do\r
         Panel.any_instance.stub(:own?).and_return(false)\r
         Panel.any_instance.stub(:publish?).and_return(false)\r
-        r = @panel.visible?(@author)\r
-        r.should == false\r
+        r = @panel.visible?([@author])\r
+        r.should be_false\r
       end\r
       it '他人のコマでも公開なら許可する' do\r
         Panel.any_instance.stub(:own?).and_return(false)\r
         Panel.any_instance.stub(:publish?).and_return(true)\r
-        r = @panel.visible?(@author)\r
-        r.should == true\r
-      end\r
-    end\r
-    context '検査対象がそれ以外のとき' do\r
-      it '不許可を返す。' do\r
-        r = @panel.visible?(@admin)\r
-        r.should be_false\r
+        r = @panel.visible?([@author])\r
+        r.should be_true\r
       end\r
     end\r
   end\r
index 8684f43..d9aaf9d 100644 (file)
@@ -250,28 +250,36 @@ describe Picture do
     before do
       @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
     end
-    context 'パラメータが作家のとき' do
-      it '自作の実素材ならyes' do
-        @p.own?(@author).should == true
-      end
-      it '他人のならno' do
-        @p.own?(@other_author).should == false
+    context '事前チェックする' do
+      it '自身にロールリストからの絵師取得を依頼している' do
+        Picture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)
+        r = @p.own?([@artist])
       end
     end
-    context 'パラメータが絵師のとき' do
-      it '自作の実素材ならyes' do
-        @p.own?(@artist).should == true
+    context 'ロール内絵師が取得できるとき' do
+      before do
       end
-      it '他人のならno' do
-        @p.own?(@other_artist).should == false
+      it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do
+        Picture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)
+        r = @p.own?([@artist])
+        r.should be_true
+      end
+      it 'ロール内絵師のidが自身の絵師idと一致しないならno' do
+        Picture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)
+        @p.own?(@other_artist).should be_false
       end
     end
-    context 'それ以外のとき' do
-      it 'no' do
-        @p.own?(nil).should == false
+    context 'ロール内絵師が取得できないとき' do
+      before do
+        Picture.stub(:get_artist_from_roles).with(any_args).and_return(nil)
+      end
+      it 'Falseを返す' do
+        r = @p.own?([@artist])
+        r.should be_false
       end
     end
   end
+  
   describe '閲覧許可に於いて' do
     before do
       @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
index a2736a5..8c91623 100644 (file)
@@ -242,8 +242,33 @@ describe ResourcePicture do
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
     end\r
-    it '素材を更新することはないので、Falseを返す' do\r
-      @rp.own?(@author).should == false\r
+    context '事前チェックする' do\r
+      it '自身にロールリストからの絵師取得を依頼している' do\r
+        ResourcePicture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)\r
+        r = @rp.own?([@author])\r
+      end\r
+    end\r
+    context 'ロール内絵師が取得できるとき' do\r
+      before do\r
+      end\r
+      it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do\r
+        ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)\r
+        r = @rp.own?([@author])\r
+        r.should be_true\r
+      end\r
+      it 'ロール内絵師のidが自身の絵師idと一致しないならno' do\r
+        ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)\r
+        @rp.own?(@other_artist).should be_false\r
+      end\r
+    end\r
+    context 'ロール内絵師が取得できないとき' do\r
+      before do\r
+        ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(nil)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.own?([@author])\r
+        r.should be_false\r
+      end\r
     end\r
   end\r
   \r
@@ -252,38 +277,46 @@ describe ResourcePicture do
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
     end\r
-    context '検査対象がnil(ゲスト)のとき' do\r
-      context 'クローズドモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 1\r
-        end\r
-        it '不許可を返す。' do\r
-          r = @rp.visible?(nil)\r
-          r.should be_false\r
-        end\r
-      end\r
-      context 'オープンモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 0\r
-        end\r
-        it '許可する' do\r
-          r = @rp.visible?(nil)\r
-          r.should be_true\r
-        end\r
-      end\r
-    end\r
-    context '検査対象が作家のとき' do\r
-      it '許可する' do\r
-        r = @rp.visible?(@author)\r
-        r.should == true\r
+    context 'オープンモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 0\r
+      end\r
+      it '自身にゲスト用ロールチェックを問い合わせしている' do\r
+        ResourcePicture.any_instance.stub(:guest_role_check).and_return(true)\r
+        ResourcePicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)\r
+        r = @rp.visible?([@author])\r
+      end\r
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do\r
+        ResourcePicture.any_instance.stub(:guest_role_check).and_return(false)\r
+        r = @rp.visible?([@author])\r
+        r.should be_false\r
       end\r
     end\r
-    context '検査対象がそれ以外のとき' do\r
-      it '不許可を返す。' do\r
-        r = @rp.visible?(@admin)\r
+    context 'クローズドモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+      end\r
+      it '自身に素材読者用ロールチェックを問い合わせしている' do\r
+        ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(true)\r
+        ResourcePicture.any_instance.should_receive(:resource_reader_role_check).with(any_args).exactly(1)\r
+        r = @rp.visible?([@author])\r
+      end\r
+      it '素材読者用ロールチェックが失敗したとき、falseを返す' do\r
+        ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(false)\r
+        r = @rp.visible?([@author])\r
         r.should be_false\r
       end\r
     end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+        ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(true)\r
+      end\r
+      it '許可する' do\r
+        r = @rp.visible?([@author])\r
+        r.should be_true\r
+      end\r
+    end\r
   end\r
   \r
   describe 'ファイル名に於いて' do\r
index 48955bf..fe29f09 100644 (file)
@@ -91,61 +91,80 @@ describe SpeechBalloon do
   describe '閲覧許可に於いて' do
     before do
       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
-      @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
-      @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @sb.visible?(nil)
-          r.should be_false
-        end
-      end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '公開されたコマのフキダシなら許可する' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-          r = @sb.visible?(nil)
-          r.should be_true
-        end
-        it 'れ以外なら不許可を返す' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-          r = @sb.visible?(nil)
-          r.should be_false
-        end
-      end
-    end
-    context '検査対象が作家のとき' do
-      it '公開されたコマのフキダシなら許可する' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-        r = @sb.visible?(@author)
-        r.should be_true
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
+      end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        SpeechBalloon.any_instance.stub(:guest_role_check).and_return(true)
+        SpeechBalloon.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @sb.visible?([@author])
       end
-      it 'ã\82\8c以å¤\96ã\81ªã\82\89ä¸\8d許å\8f¯を返す' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @sb.visible?(@author)
+      it 'ã\82²ã\82¹ã\83\88ç\94¨ã\83­ã\83¼ã\83«ã\83\81ã\82§ã\83\83ã\82¯ã\81\8c失æ\95\97ã\81\97ã\81\9fã\81¨ã\81\8dã\80\81falseを返す' do
+        SpeechBalloon.any_instance.stub(:guest_role_check).and_return(false)
+        r = @sb.visible?([@author])
         r.should be_false
       end
     end
-    context '検査対象が管理者のとき' do
-      it '許可を返す。' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @sb.visible?(@admin)
-        r.should be_true
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
+        SpeechBalloon.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @sb.visible?([@author])
+      end
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        SpeechBalloon.any_instance.stub(:reader_role_check).and_return(false)
+        r = @sb.visible?([@author])
+        r.should be_false
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @sb.visible?(1)
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自身のコマに所持判定を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @sb.visible?([@author])
+      end
+      it '自身のコマに閲覧許可を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = @sb.visible?([@author])
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Panel.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自分のコマのフキダシなら許可する' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @sb.visible?([@author])
+        r.should be_true
+      end
+      it '他人の非公開コマのフキダシなら許可しない' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @sb.visible?([@author])
         r.should be_false
       end
+      it '他人のコマのフキダシでも公開なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        r = @sb.visible?([@author])
+        r.should be_true
+      end
     end
   end
+  
   describe '一覧取得に於いて' do
     before do
       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
index fd2e8d1..e57215f 100644 (file)
@@ -137,58 +137,79 @@ describe Speech do
       @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
       @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
     end\r
-    context '検査対象がnil(ゲスト)のとき' do\r
-      context 'クローズドモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 1\r
-        end\r
-        it '不許可を返す。' do\r
-          r = @speech.visible?(nil)\r
-          r.should be_false\r
-        end\r
+    context 'オープンモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 0\r
       end\r
-      context 'オープンモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 0\r
-        end\r
-        it '公開されたコマのセリフなら許可する' do\r
-          SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)\r
-          r = @speech.visible?(nil)\r
-          r.should be_true\r
-        end\r
-        it 'れ以外なら不許可を返す' do\r
-          SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
-          r = @speech.visible?(nil)\r
-          r.should be_false\r
-        end\r
+      it '自身にゲスト用ロールチェックを問い合わせしている' do\r
+        Speech.any_instance.stub(:guest_role_check).and_return(true)\r
+        Speech.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)\r
+        r = @speech.visible?([@author])\r
+      end\r
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do\r
+        Speech.any_instance.stub(:guest_role_check).and_return(false)\r
+        r = @speech.visible?([@author])\r
+        r.should be_false\r
       end\r
     end\r
-    context '検査対象が作家のとき' do\r
-      it '公開されたコマのセリフなら許可する' do\r
-        SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)\r
-        r = @speech.visible?(@author)\r
-        r.should be_true\r
+    context 'クローズドモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+      end\r
+      it '自身に読者用ロールチェックを問い合わせしている' do\r
+        Speech.any_instance.stub(:reader_role_check).and_return(true)\r
+        Speech.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)\r
+        r = @speech.visible?([@author])\r
       end\r
-      it 'れ以外なら不許可を返す' do\r
-        SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
-        r = @speech.visible?(@author)\r
+      it '読者用ロールチェックが失敗したとき、falseを返す' do\r
+        Speech.any_instance.stub(:reader_role_check).and_return(false)\r
+        r = @speech.visible?([@author])\r
         r.should be_false\r
       end\r
     end\r
-    context '検査対象が管理者のとき' do\r
-      it '許可を返す。' do\r
-        SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
-        r = @speech.visible?(@admin)\r
-        r.should be_true\r
+    context '事前チェックする' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+        Speech.any_instance.stub(:reader_role_check).and_return(true)\r
+      end\r
+      it '自身のコマに所持判定を問い合わせしている' do\r
+        Panel.any_instance.stub(:own?).and_return(true)\r
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
+        r = @speech.visible?([@author])\r
+      end\r
+      it '自身のコマに閲覧許可を問い合わせしている' do\r
+        Panel.any_instance.stub(:own?).and_return(false)\r
+        Panel.any_instance.stub(:visible?).and_return(true)\r
+        Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
+        r = @speech.visible?([@author])\r
       end\r
     end\r
-    context '検査対象がそれ以外のとき' do\r
-      it '不許可を返す。' do\r
-        r = @speech.visible?(1)\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+        Panel.any_instance.stub(:reader_role_check).and_return(true)\r
+      end\r
+      it '自分のコマのセリフなら許可する' do\r
+        Panel.any_instance.stub(:own?).and_return(true)\r
+        Panel.any_instance.stub(:visible?).and_return(false)\r
+        r = @speech.visible?([@author])\r
+        r.should be_true\r
+      end\r
+      it '他人の非公開コマのセリフなら許可しない' do\r
+        Panel.any_instance.stub(:own?).and_return(false)\r
+        Panel.any_instance.stub(:visible?).and_return(false)\r
+        r = @speech.visible?([@author])\r
         r.should be_false\r
       end\r
+      it '他人のコマのセリフでも公開なら許可する' do\r
+        Panel.any_instance.stub(:own?).and_return(false)\r
+        Panel.any_instance.stub(:visible?).and_return(true)\r
+        r = @speech.visible?([@author])\r
+        r.should be_true\r
+      end\r
     end\r
   end\r
+  \r
   describe '一覧取得に於いて' do\r
     before do\r
       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
index 06a8f84..4c6baf6 100644 (file)
@@ -141,14 +141,33 @@ describe Story do
       @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
       @storyo = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @comico.id, :panel_id => @panelo.id
     end
-    it '自分のストーリーならyes' do
-      @story.own?(@author).should == true
+    context '事前チェックする' do
+      it '自身にロールリストからの作家取得を依頼している' do
+        Story.should_receive(:get_author_from_roles).with(any_args).exactly(1)
+        r = @story.own?([@author])
+      end
     end
-    it '他人のストーリーならno' do
-      @storyo.own?(@author).should == false
+    context 'ロール内作家が取得できるとき' do
+      before do
+      end
+      it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+        Story.stub(:get_author_from_roles).with(any_args).and_return(@author)
+        r = @story.own?([@author])
+        r.should be_true
+      end
+      it 'ロール内作家のidが自身の作家idと一致しないならno' do
+        Story.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
+        @story.own?(@other_author).should be_false
+      end
     end
-    it 'パラメータが作家でないならno' do
-      @story.own?(nil).should == false
+    context 'ロール内作家が取得できないとき' do
+      before do
+        Story.stub(:get_author_from_roles).with(any_args).and_return(nil)
+      end
+      it 'Falseを返す' do
+        r = @story.own?([@author])
+        r.should be_false
+      end
     end
   end
   
@@ -158,57 +177,76 @@ describe Story do
       @panel = FactoryGirl.create :panel, :author_id => @author.id
       @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @story.visible?(nil)
-          r.should be_false
-        end
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
       end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '公開コミックのストーリーなら許可する' do
-          Comic.any_instance.stub(:visible?).with(nil).and_return(true)
-          r = @story.visible?(nil)
-          r.should be_true
-        end
-        it '非公開コミックのストーリーなら許可しない' do
-          Comic.any_instance.stub(:visible?).with(nil).and_return(false)
-          r = @story.visible?(nil)
-          r.should be_false
-        end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        Story.any_instance.stub(:guest_role_check).and_return(true)
+        Story.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @story.visible?([@author])
+      end
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+        Story.any_instance.stub(:guest_role_check).and_return(false)
+        r = @story.visible?([@author])
+        r.should be_false
       end
     end
-    context '検査対象が作家のとき' do
-      it '自分のコミックのストーリーなら許可する' do
-        Comic.any_instance.stub(:own?).with(@author).and_return(true)
-        Comic.any_instance.stub(:visible?).with(@author).and_return(true)
-        r = @story.visible?(@author)
-        r.should == true
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
       end
-      it '他人の非公開コミックのストーリーなら許可しない' do
-        Comic.any_instance.stub(:own?).with(@other_author).and_return(false)
-        Comic.any_instance.stub(:visible?).with(@other_author).and_return(false)
-        r = @story.visible?(@other_author)
-        r.should == false
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        Story.any_instance.stub(:reader_role_check).and_return(true)
+        Story.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @story.visible?([@author])
       end
-      it '他人のコミックのストーリーでも公開なら許可する' do
-        Comic.any_instance.stub(:own?).with(@other_author).and_return(false)
-        Comic.any_instance.stub(:visible?).with(@other_author).and_return(true)
-        r = @story.visible?(@other_author)
-        r.should == true
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        Story.any_instance.stub(:reader_role_check).and_return(false)
+        r = @story.visible?([@author])
+        r.should be_false
+      end
+    end
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Story.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自身のコミックに所持判定を問い合わせしている' do
+        Comic.any_instance.stub(:own?).and_return(true)
+        Comic.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @story.visible?([@author])
+      end
+      it '自身のコミックに閲覧許可を問い合わせしている' do
+        Comic.any_instance.stub(:own?).and_return(false)
+        Comic.any_instance.stub(:visible?).and_return(true)
+        Comic.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = @story.visible?([@author])
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @story.visible?(@admin)
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Story.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自分のコミックのストーリーなら許可する' do
+        Comic.any_instance.stub(:own?).and_return(true)
+        Comic.any_instance.stub(:visible).and_return(0)
+        r = @story.visible?([@author])
+        r.should be_true
+      end
+      it '他人の非公開コミックのストーリーなら許可しない' do
+        Comic.any_instance.stub(:own?).and_return(false)
+        Comic.any_instance.stub(:visible).and_return(0)
+        r = @story.visible?([@author])
         r.should be_false
       end
+      it '他人のコミックのストーリーでも公開なら許可する' do
+        Comic.any_instance.stub(:own?).and_return(false)
+        Comic.any_instance.stub(:visible).and_return(1)
+        r = @story.visible?([@author])
+        r.should be_true
+      end
     end
   end