OSDN Git Service

fix panel test
authoryasushiito <yasushiito@git.sourceforge.jp>
Sun, 3 Jun 2012 04:10:31 +0000 (13:10 +0900)
committeryasushiito <yasushiito@git.sourceforge.jp>
Sun, 3 Jun 2012 04:10:31 +0000 (13:10 +0900)
15 files changed:
app/controllers/panels_controller.rb
app/controllers/speech_balloon_templates_controller.rb
app/models/comic.rb
app/models/panel.rb
app/models/speech_balloon_template.rb
app/views/panels/edit.html.erb [new file with mode: 0644]
app/views/panels/edit.js.erb [new file with mode: 0644]
app/views/panels/new.html.erb [new file with mode: 0644]
db/migrate/20111206111202_create_panels.rb
db/schema.rb
spec/controllers/balloons_controller_spec.rb
spec/controllers/panels_controller_spec.rb
spec/controllers/speech_balloon_templates_controller_spec.rb
spec/controllers/speeches_controller_spec.rb
spec/models/panel_spec.rb

index 24359c3..2236299 100644 (file)
@@ -1,6 +1,6 @@
 class PanelsController < ApplicationController
   layout 'test' if Pettanr::TestLayout
-  before_filter :authenticate_user!, :only => [:index, :show, :create, :update, :destroy]
+  before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
   private
@@ -14,39 +14,37 @@ class PanelsController < ApplicationController
   # GET /panels
   # GET /panels.json
   def index
-    @panels = Panel.find(:all, :include => [:comic, :author], :order => 'updated_at', :limit => 20)
+    @page = Panel.page params[:page]
+    @page_size = Panel.page_size params[:page_size]
+    @panels = Panel.list({}, @page, @page_size)
 
     respond_to do |format|
       format.html # index.html.erb
-      format.json { render :json => @panels.to_json(
-        :include => [:comic, :author]
-      ) }
+      format.json { render json: @panels.to_json(Panel.list_json_opt) }
     end
   end
 
   # GET /panels/1
   # GET /panels/1.json
   def show
-    @panel = Panel.find(params[:id], include: [:comic, :panel_pictures => :resource_picture, :balloons => :speeches])# only: [:width, :height])
+    @panel = Panel.show(params[:id], @author)
 
     respond_to do |format|
       format.html # show.html.erb
-       format.json {
-        render :json => @panel.to_json(include: {
-          :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
-        })
-      }
+      format.json { render json: @panel.to_json(Panel.show_json_include_opt) }
       format.jsonp {
-        render :json => "callback(" + @panel.to_json(include: {
-          :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
-        }) + ");"
+        render :json => "callback(" + @panel.to_json(Panel.show_json_include_opt) + ");"
       }
-#      format.json { render :json => @frame.to_json(include: {
-#        :comic => {:only => :title}, :panel_pictures => {:include => {:image => {:only => [:width]}},:only => [:width, :height, :z, :image_id]}
-#      }, only: [:border]) }
     end
   end
 
+  def count
+    @panel = {:count => Panel.visible_count}
+    respond_to do |format|
+      format.json { render json: @panel.to_json }
+    end
+  end
+  
   def list
     @panels = Panel.all :order => 'updated_at'
 
@@ -64,6 +62,25 @@ class PanelsController < ApplicationController
     end
   end
 
+  def new
+    @panel = Panel.new
+    @panel.supply_default @author
+
+    respond_to do |format|
+      format.html # new.html.erb
+      format.js
+      format.json { render json: @panel }
+    end
+  end
+
+  def edit
+    @panel = Panel.show(params[:id], @author)
+    respond_to do |format|
+      format.html
+      format.js
+    end
+  end
+
   # POST /panels
   # POST /panels.json
   def create
@@ -77,7 +94,7 @@ class PanelsController < ApplicationController
 
     respond_to do |format|
       Panel.transaction do
-        if @panel.vdt_save
+        if @panel.store
           format.html { redirect_to @panel, notice: 'Panel was successfully created.' }
           format.json { render json: @panel, status: :created, location: @panel }
         else
index 13dba70..c95f03b 100644 (file)
@@ -5,7 +5,7 @@ class SpeechBalloonTemplatesController < ApplicationController
   # GET /speech_balloon_templates
   # GET /speech_balloon_templates.json
   def index
-    @speech_balloon_templates = SpeechBalloonTemplate.all
+    @speech_balloon_templates = SpeechBalloonTemplate.list
 
     respond_to do |format|
       format.html # index.html.erb
@@ -16,7 +16,7 @@ class SpeechBalloonTemplatesController < ApplicationController
   # GET /speech_balloon_templates/1
   # GET /speech_balloon_templates/1.json
   def show
-    @speech_balloon_template = SpeechBalloonTemplate.find(params[:id])
+    @speech_balloon_template = SpeechBalloonTemplate.show(params[:id])
 
     respond_to do |format|
       format.html # show.html.erb
index 6db937d..b280dd3 100644 (file)
@@ -113,9 +113,9 @@ class Comic < ActiveRecord::Base
       :author, 
       :panels => [
         :panel_pictures => :resource_picture, 
-        :balloons => :speeches
+        :speech_balloons =>{:balloons => {}, :speeches => {}}
       ]
-    ], order: 'panels.t, speeches.t')
+    ], order: 'panels.t')
   end
   
   def to_json_play
index 7f47768..0254dd4 100644 (file)
@@ -4,9 +4,9 @@ class Panel < ActiveRecord::Base
   belongs_to :resource_picture
 #  belongs_to :background_picture, :class_name => 'ResourcePicture'
   has_many :panel_pictures, :dependent => :destroy
-  has_many :balloons, :dependent => :destroy
+  has_many :speech_balloons, :dependent => :destroy
   accepts_nested_attributes_for :panel_pictures, :allow_destroy => true
-  accepts_nested_attributes_for :balloons, :allow_destroy => true
+  accepts_nested_attributes_for :speech_balloons, :allow_destroy => true
 
 #  validates :comic_id, :presence => true, :numericality => true, :existence => true, :uniqueness => {:scope => :t} 
   validates :resource_picture_id, :numericality => {:allow_blank => true}
@@ -20,6 +20,7 @@ class Panel < ActiveRecord::Base
   validates :author_id, :presence => true, :numericality => true, :existence => true
   
   def supply_default au
+    return false unless au
     c = self.comic_id ? Comic.show(self.comic_id, au) : nil
     if c
       self.width = c.width if self.width.blank?
@@ -45,7 +46,7 @@ class Panel < ActiveRecord::Base
 
   #更新する時にPanelIDをチェックしとかないと勝手に所属先を変えられるゾ!?
 
-  def vdt_save
+  def store
     f = nil
     f = Panel.find_t(self.comic_id, self.t) if self.t
     if f
@@ -116,18 +117,18 @@ class Panel < ActiveRecord::Base
       :panel_pictures => {
         :resource_picture => {:artist => {}, :license => {}}
       }, 
-      :balloons => {:speeches => {}},
+      :speech_balloons => {:balloons => {}, :speeches => {}},
       :author => {}
     }}
   end
   
   def self.list_json_opt
     {:include => {
-      :comic => :author
+      :comic => {:author => {}}
       :panel_pictures => {
         :resource_picture => {:artist => {}, :license => {}}
       }, 
-      :balloons => {:speeches => {}},
+      :speech_balloons => {:balloons => {}, :speeches => {}},
       :author => {}
     }}
   end
@@ -144,7 +145,7 @@ class Panel < ActiveRecord::Base
       :panel_pictures => {
         :resource_picture => {:artist => {}, :license => {}}
       }, 
-      :balloons => {:speeches => {}},
+      :speech_balloons => {:balloons => {}, :speeches => {}},
       :author => {}
     }
     res.merge!(opt[:include]) if opt[:include]
@@ -153,11 +154,11 @@ class Panel < ActiveRecord::Base
   
   def self.show_json_include_opt
     {:include => {
-      :comic => :author
+      :comic => {:author => {}}
       :panel_pictures => {
         :resource_picture => {:artist => {}, :license => {}}
       }, 
-      :balloons => {:speeches => {}},
+      :speech_balloons => {:balloons => {}, :speeches => {}},
       :author => {}
     }}
   end
@@ -206,4 +207,9 @@ class Panel < ActiveRecord::Base
   def to_json_play
     self.to_json :methods => :panel_elements
   end
+  
+  def self.visible_count
+    Panel.count
+  end
+  
 end
index b5f12e0..a9a20ec 100644 (file)
@@ -52,6 +52,15 @@ class SpeechBalloonTemplate < ActiveRecord::Base
     st
   end
   
+  def self.list
+    SpeechBalloonTemplate.find(:all)
+  end
+  
+  def self.show rid
+    r = SpeechBalloonTemplate.find(rid)
+    r
+  end
+  
   def self.parse(data)
     res = data
     begin
diff --git a/app/views/panels/edit.html.erb b/app/views/panels/edit.html.erb
new file mode 100644 (file)
index 0000000..2d34363
--- /dev/null
@@ -0,0 +1 @@
+<%= render 'form' %>
diff --git a/app/views/panels/edit.js.erb b/app/views/panels/edit.js.erb
new file mode 100644 (file)
index 0000000..1b751ea
--- /dev/null
@@ -0,0 +1 @@
+$("#newpanel").html("<%= escape_javascript(render('form')) -%>");
diff --git a/app/views/panels/new.html.erb b/app/views/panels/new.html.erb
new file mode 100644 (file)
index 0000000..2d34363
--- /dev/null
@@ -0,0 +1 @@
+<%= render 'form' %>
index bcf7b3e..9cb1b92 100644 (file)
@@ -1,7 +1,7 @@
 class CreatePanels < ActiveRecord::Migration
   def change
     create_table :panels do |t|
-      t.integer :comic_id, :null => false
+      t.integer :comic_id
       t.integer :resource_picture_id
       t.integer :width, :null => false, :default => 200
       t.integer :height, :null => false, :default => 80
@@ -14,7 +14,6 @@ class CreatePanels < ActiveRecord::Migration
 
       t.timestamps
     end
-    add_index :panels, [:comic_id, :t], :unique => true, :name => 'panels_idt'
     add_index :panels, [:author_id]
   end
 end
index 8682613..2c94bfb 100644 (file)
@@ -166,7 +166,7 @@ ActiveRecord::Schema.define(:version => 20120424100555) do
   add_index "panel_pictures", ["panel_id", "t"], :name => "panel_pictures_idt", :unique => true\r
 \r
   create_table "panels", :force => true do |t|\r
-    t.integer  "comic_id",                             :null => false\r
+    t.integer  "comic_id"\r
     t.integer  "resource_picture_id"\r
     t.integer  "width",               :default => 200, :null => false\r
     t.integer  "height",              :default => 80,  :null => false\r
@@ -181,7 +181,6 @@ ActiveRecord::Schema.define(:version => 20120424100555) do
   end\r
 \r
   add_index "panels", ["author_id"], :name => "index_panels_on_author_id"\r
-  add_index "panels", ["comic_id", "t"], :name => "panels_idt", :unique => true\r
 \r
   create_table "resource_pictures", :force => true do |t|\r
     t.string   "ext",                                :null => false\r
index 97ff672..a3899d1 100644 (file)
@@ -3,11 +3,4 @@
 require 'spec_helper'
 
 describe BalloonsController do
-  describe "GET index" do
-    it "assigns all baloons as @baloons" do
-      baloon = Baloon.create! valid_attributes
-      get :index
-      assigns(:baloons).should eq([baloon])
-    end
-  end
 end
index fbc8e26..e7c058e 100644 (file)
@@ -138,7 +138,7 @@ describe PanelsController do
         it 'データがアレになっている' do\r
           get :show, :id => @panel.id, :format => :json\r
           json = JSON.parse response.body\r
-          json["width"].should match(/438/)\r
+          json["width"].should eq 100\r
         end\r
       end\r
     end\r
@@ -290,7 +290,7 @@ describe PanelsController do
   \r
   describe '新規作成に於いて' do\r
     before do\r
-      @panel = Factory :normal_panel, :author_id => @user.author.id, :comic_id => @comic.id\r
+      @panel = Factory :panel, :author_id => @user.author.id, :comic_id => @comic.id\r
       sign_in @user\r
     end\r
     context '事前チェックする' do\r
@@ -299,57 +299,57 @@ describe PanelsController do
         Panel.stub(:count).and_return(10)\r
       end\r
       it 'panelがパラメータにあれば、展開する' do\r
-        post :create, :panel => Factory.attributes_for(:panel, :panel_id => @panel.id)\r
-        assigns(:prm)['border'].to_i.should eq 1\r
+        post :create, :panel => Factory.attributes_for(:panel, :comic_id => @comic.id)\r
+        assigns(:prm)['border'].to_i.should eq @panel.border\r
       end\r
       it 'jsonがパラメータにあれば、展開する' do\r
-        post :create, :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s\r
+        post :create, :json => Factory.attributes_for(:panel, :comic_id => @comic.id, :border => 4).to_json\r
         assigns(:prm)['border'].to_i.should eq 4\r
       end\r
       it 'panel・json両パラメータがあれば、panelを優先して展開する' do\r
         post :create, {\r
-          :panel => Factory.attributes_for(:panel, :panel_id => @panel.id), \r
-          :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s\r
+          :panel => Factory.attributes_for(:panel, :comic_id => @comic.id), \r
+          :json => Factory.attributes_for(:panel, :comic_id => @comic.id, :border => 4).to_json\r
         }\r
-        assigns(:prm)['border'].to_i.should eq 1\r
+        assigns(:prm)['border'].to_i.should eq @panel.border\r
       end\r
     end\r
     context 'つつがなく終わるとき' do\r
       it 'モデルに保存依頼する' do\r
-        Panel.any_instance.should_receive(:save).exactly(1)\r
-        post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+        Panel.any_instance.should_receive(:store).exactly(1)\r
+        post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
       end\r
       it "@panelに作成されたコマを保持していて、それがDBにある" do\r
-        post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+        post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
         assigns(:panel).should be_a(Panel)\r
         assigns(:panel).should be_persisted\r
       end\r
       context 'html形式' do\r
         it 'ステータスコード302 Foundを返す' do\r
-          Panel.any_instance.stub(:save).and_return(true)\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          Panel.any_instance.stub(:store).and_return(true)\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
           response.status.should eq 302\r
         end\r
         it '作成されたコマの表示ページへ遷移する' do\r
-#          Panel.any_instance.stub(:save).and_return(true)\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+#          Panel.any_instance.stub(:store).and_return(true)\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
           response.should redirect_to(Panel.last)\r
         end\r
       end\r
       context 'json形式' do\r
         it 'ステータスコード200 OKを返す' do\r
-#          Panel.any_instance.stub(:save).and_return(true)\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+#          Panel.any_instance.stub(:store).and_return(true)\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
           response.should be_success \r
         end\r
         it '作成されたコマをjsonデータで返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
         end\r
         it 'データがアレになっている' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
           json = JSON.parse response.body\r
-          json["title"].should match(/normal/)\r
+          json["width"].should eq @panel.width\r
         end\r
       end\r
     end\r
@@ -359,21 +359,21 @@ describe PanelsController do
       end\r
       context 'html形式' do\r
         it 'ステータスコード302 Foundを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
           response.status.should eq 302\r
         end\r
         it 'サインインページへ遷移する' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
           response.body.should redirect_to '/users/sign_in'\r
         end\r
       end\r
       context 'json形式' do\r
         it 'ステータスコード401 Unauthorizedを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
           response.status.should eq 401\r
         end\r
         it '応答メッセージにUnauthorizedを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
           response.message.should match(/Unauthorized/)\r
         end\r
       end\r
@@ -383,26 +383,26 @@ describe PanelsController do
         Panel.any_instance.stub(:save).and_return(false)\r
       end\r
       it "未保存のコマを保持している" do\r
-        post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+        post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
         assigns(:panel).should be_a_new(Panel)\r
       end\r
       context 'html形式' do\r
         it 'ステータスコード200 OKを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
           response.status.should eq 200\r
         end\r
         it '新規ページを描画する' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
           response.should render_template("new")\r
         end\r
       end\r
       context 'json形式' do\r
         it 'ステータスコード422 unprocessable_entity を返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
           response.status.should eq 422\r
         end\r
         it '応答メッセージUnprocessable Entityを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
           response.message.should match(/Unprocessable/)\r
         end\r
       end\r
@@ -468,102 +468,4 @@ describe PanelsController do
     end\r
   end\r
 \r
-  describe '更新に於いて' do\r
-    before do\r
-      @panel = Factory :panel, :author => @author.id, :comic_id => @comic.id\r
-      sign_in @user\r
-    end\r
-    context '事前チェックしておく' do\r
-      it 'コマモデルに単体取得を問い合わせている' do\r
-        Panel.stub(:show).with(any_args()).and_return @panel\r
-        Panel.should_receive(:show).exactly(1)\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-      end\r
-      it 'モデルに更新を依頼する' do\r
-        Panel.any_instance.should_receive(:update_attributes).with(any_args)\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-      end\r
-      it '@panelにアレを取得している' do\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-        assigns(:panel).id.should eq(@panel.id)\r
-      end\r
-    end\r
-    context 'つつがなく終わるとき' do\r
-      it '更新される' do\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-        Panel.find(@panel.id).visible.should eq 0\r
-      end\r
-      context 'html形式' do\r
-        it 'ステータスコード302 Foundを返す' do\r
-          Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-          response.status.should eq 302\r
-        end\r
-        it '更新されたコマの表示ページへ遷移する' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-          response.should redirect_to(@panel)\r
-        end\r
-      end\r
-      context 'json形式' do\r
-        it 'ステータスコード200 OKを返す' do\r
-          Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
-          response.should be_success \r
-        end\r
-        it 'ページ本体は特に返さない' do\r
-          Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
-          response.body.should match /./\r
-        end\r
-      end\r
-    end\r
-    context '作家権限がないとき' do\r
-      before do\r
-        sign_out @user\r
-      end\r
-      it 'ステータスコード302 Foundを返す' do\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-        response.status.should eq 302\r
-      end\r
-      context 'html形式' do\r
-        it 'サインインページへ遷移する' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-          response.body.should redirect_to '/users/sign_in'\r
-        end\r
-      end\r
-      context 'json形式' do\r
-        it '応答メッセージにUnauthorizedを返す' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
-          response.message.should match(/Unauthorized/)\r
-        end\r
-      end\r
-    end\r
-    context '検証、保存に失敗したとき' do\r
-      before do\r
-        Panel.any_instance.stub(:update_attributes).and_return(false)\r
-      end\r
-      context 'html形式' do\r
-        it 'ステータスコード200 Okを返す' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-          response.status.should eq 200\r
-        end\r
-        it '編集ページを描画する' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-          response.should render_template("edit")\r
-        end\r
-      end\r
-      context 'json形式' do\r
-        it 'ステータスコード422 unprocessable_entity を返す' do\r
-          Panel.any_instance.stub(:update_attributes).and_return(false)\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
-          response.status.should eq 422\r
-        end\r
-        it '応答メッセージUnprocessable Entityを返す' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
-          response.message.should match(/Unprocessable/)\r
-        end\r
-      end\r
-    end\r
-  end\r
-  \r
 end\r
index 153f490..aac1bd3 100644 (file)
+# -*- encoding: utf-8 -*-
 require 'spec_helper'
-
-# This spec was generated by rspec-rails when you ran the scaffold generator.
-# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by Rails when you ran the scaffold generator.
-#
-# It assumes that the implementation code is generated by the rails scaffold
-# generator.  If you are using any extension libraries to generate different
-# controller code, this generated spec may or may not pass.
-#
-# It only uses APIs available in rails and/or rspec-rails.  There are a number
-# of tools you can use to make these specs even more expressive, but we're
-# sticking to rails and rspec-rails APIs to keep things simple and stable.
-#
-# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec.  Stubs are only used when there
-# is no simpler way to get a handle on the object needed for the example.
-# Message expectations are only used when there is no simpler way to specify
-# that an instance is receiving a specific message.
-
+#フキダシテンプレート
 describe SpeechBalloonTemplatesController do
 
-  # This should return the minimal set of attributes required to create a valid
-  # SpeechBalloonTemplate. As you add validations to SpeechBalloonTemplate, be sure to
-  # update the return value of this method accordingly.
-  def valid_attributes
-    {}
-  end
-
-  describe "GET index" do
-    it "assigns all speech_balloon_templates as @speech_balloon_templates" do
-      speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-      get :index
-      assigns(:speech_balloon_templates).should eq([speech_balloon_template])
-    end
+  before do
+    @admin = Factory :admin
+    @sbt = Factory :license
+    @user = Factory( :user_yas)
+    @author = @user.author
+    @sbt = Factory :speech_balloon_template
   end
 
-  describe "GET show" do
-    it "assigns the requested speech_balloon_template as @speech_balloon_template" do
-      speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-      get :show, :id => speech_balloon_template.id
-      assigns(:speech_balloon_template).should eq(speech_balloon_template)
+  describe '一覧表示に於いて' do
+    before do
+      sign_in @user
+      SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
     end
-  end
-
-  describe "GET new" do
-    it "assigns a new speech_balloon_template as @speech_balloon_template" do
-      get :new
-      assigns(:speech_balloon_template).should be_a_new(SpeechBalloonTemplate)
-    end
-  end
-
-  describe "GET edit" do
-    it "assigns the requested speech_balloon_template as @speech_balloon_template" do
-      speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-      get :edit, :id => speech_balloon_template.id
-      assigns(:speech_balloon_template).should eq(speech_balloon_template)
-    end
-  end
-
-  describe "POST create" do
-    describe "with valid params" do
-      it "creates a new SpeechBalloonTemplate" do
-        expect {
-          post :create, :speech_balloon_template => valid_attributes
-        }.to change(SpeechBalloonTemplate, :count).by(1)
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
       end
-
-      it "assigns a newly created speech_balloon_template as @speech_balloon_template" do
-        post :create, :speech_balloon_template => valid_attributes
-        assigns(:speech_balloon_template).should be_a(SpeechBalloonTemplate)
-        assigns(:speech_balloon_template).should be_persisted
+      it 'フキダシテンプレートモデルに一覧を問い合わせている' do
+        SpeechBalloonTemplate.should_receive(:list).exactly(1)
+        get :index
       end
-
-      it "redirects to the created speech_balloon_template" do
-        post :create, :speech_balloon_template => valid_attributes
-        response.should redirect_to(SpeechBalloonTemplate.last)
+      it '@speech_balloon_templatesにリストを取得している' do
+        get :index
+        assigns(:speech_balloon_templates).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'データがリスト構造になっている' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("classname").should be_true
+        end
       end
     end
-
-    describe "with invalid params" do
-      it "assigns a newly created but unsaved speech_balloon_template as @speech_balloon_template" do
-        # Trigger the behavior that occurs when invalid params are submitted
-        SpeechBalloonTemplate.any_instance.stub(:save).and_return(false)
-        post :create, :speech_balloon_template => {}
-        assigns(:speech_balloon_template).should be_a_new(SpeechBalloonTemplate)
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
       end
-
-      it "re-renders the 'new' template" do
-        # Trigger the behavior that occurs when invalid params are submitted
-        SpeechBalloonTemplate.any_instance.stub(:save).and_return(false)
-        post :create, :speech_balloon_template => {}
-        response.should render_template("new")
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :index
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :index, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :index, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
       end
     end
   end
-
-  describe "PUT update" do
-    describe "with valid params" do
-      it "updates the requested speech_balloon_template" do
-        speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-        # Assuming there are no other speech_balloon_templates in the database, this
-        # specifies that the SpeechBalloonTemplate created on the previous line
-        # receives the :update_attributes message with whatever params are
-        # submitted in the request.
-        SpeechBalloonTemplate.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
-        put :update, :id => speech_balloon_template.id, :speech_balloon_template => {'these' => 'params'}
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      SpeechBalloonTemplate.stub(:show).and_return(@sbt)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @sbt.id
+        response.should be_success
       end
-
-      it "assigns the requested speech_balloon_template as @speech_balloon_template" do
-        speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-        put :update, :id => speech_balloon_template.id, :speech_balloon_template => valid_attributes
-        assigns(:speech_balloon_template).should eq(speech_balloon_template)
+      it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
+        SpeechBalloonTemplate.should_receive(:show).exactly(1)
+        get :show
       end
-
-      it "redirects to the speech_balloon_template" do
-        speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-        put :update, :id => speech_balloon_template.id, :speech_balloon_template => valid_attributes
-        response.should redirect_to(speech_balloon_template)
+      it '@speech_balloon_templateにアレを取得している' do
+        get :show, :id => @sbt.id
+        assigns(:speech_balloon_template).id.should eq(@sbt.id)
       end
-    end
-
-    describe "with invalid params" do
-      it "assigns the speech_balloon_template as @speech_balloon_template" do
-        speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-        # Trigger the behavior that occurs when invalid params are submitted
-        SpeechBalloonTemplate.any_instance.stub(:save).and_return(false)
-        put :update, :id => speech_balloon_template.id, :speech_balloon_template => {}
-        assigns(:speech_balloon_template).should eq(speech_balloon_template)
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @sbt.id
+          response.should render_template("show")
+        end
       end
-
-      it "re-renders the 'edit' template" do
-        speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-        # Trigger the behavior that occurs when invalid params are submitted
-        SpeechBalloonTemplate.any_instance.stub(:save).and_return(false)
-        put :update, :id => speech_balloon_template.id, :speech_balloon_template => {}
-        response.should render_template("edit")
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @sbt.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @sbt.id, :format => :json
+          json = JSON.parse response.body
+          json["classname"].should match(/Plain/)
+        end
       end
     end
-  end
-
-  describe "DELETE destroy" do
-    it "destroys the requested speech_balloon_template" do
-      speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-      expect {
-        delete :destroy, :id => speech_balloon_template.id
-      }.to change(SpeechBalloonTemplate, :count).by(-1)
-    end
-
-    it "redirects to the speech_balloon_templates list" do
-      speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
-      delete :destroy, :id => speech_balloon_template.id
-      response.should redirect_to(speech_balloon_templates_url)
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :index
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :index, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :index, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
     end
   end
+  
 
 end
index 8b6000c..509b5fb 100644 (file)
@@ -4,11 +4,4 @@ require 'spec_helper'
 
 describe SpeechesController do
 
-  describe "GET index" do
-    it "assigns all speeches as @speeches" do
-      speech = Speech.create! valid_attributes
-      get :index
-      assigns(:speeches).should eq([speech])
-    end
-  end
 end
index 2b07d60..fd63b14 100644 (file)
@@ -11,7 +11,8 @@ describe Panel do
     @other_user = Factory( :user_yas)
     @other_author = @other_user.author
     @other_artist = Factory :artist_yas, :author_id => @other_author.id
-    
+    @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id\r
+    @rp = Factory :resource_picture, :original_picture_id => @op.id, :license_id => @license.id
   end\r
   
   describe '検証に於いて' do
@@ -55,7 +56,7 @@ describe Panel do
         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
       end
       it 'テストデータの確認' do
-        @panel.resource_picture_id = 1
+        @panel.resource_picture_id = @rp.id
         @panel.should be_valid
       end
       it 'nullなら通る' do
@@ -66,10 +67,6 @@ describe Panel do
         @panel.resource_picture_id = 'a'
         @panel.should_not be_valid
       end
-      it '存在する素材でなければ失敗する' do
-        @panel.resource_picture_id = 0
-        @panel.should_not be_valid
-      end
     end
     context 'widthを検証するとき' do
       before do
@@ -446,11 +443,15 @@ describe Panel do
           end
       it 'フキダシを含んでいる' do
         r = Panel.show_include_opt
-        r.has_key?(:balloons).should be_true\r
+        r.has_key?(:speech_balloons).should be_true\r
       end
+        it 'フキダシはフキダシ枠を含んでいる' do
+          r = Panel.show_include_opt
+          r[:speech_balloons].has_key?(:balloons).should be_true\r
+        end
         it 'フキダシはセリフを含んでいる' do
           r = Panel.show_include_opt
-          r[:balloons].has_key?(:speeches).should be_true\r
+          r[:speech_balloons].has_key?(:speeches).should be_true\r
         end
       it '作家を含んでいる' do
         r = Panel.show_include_opt
@@ -498,12 +499,16 @@ describe Panel do
           r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
         end
     it 'フキダシを含んでいる' do
-      r = Panel.show_json_include_opt[:include]
-      r.has_key?(:balloons).should be_true\r
+      r = Panel.show_include_opt
+      r.has_key?(:speech_balloons).should be_true\r
     end
+      it 'フキダシはフキダシ枠を含んでいる' do
+        r = Panel.show_include_opt
+        r[:speech_balloons].has_key?(:balloons).should be_true\r
+      end
       it 'フキダシはセリフを含んでいる' do
-        r = Panel.show_json_include_opt[:include]
-        r[:balloons].has_key?(:speeches).should be_true\r
+        r = Panel.show_include_opt
+        r[:speech_balloons].has_key?(:speeches).should be_true\r
       end
     it '作家を含んでいる' do
       r = Panel.show_json_include_opt[:include]
@@ -606,12 +611,16 @@ describe Panel do
           r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
         end
     it 'フキダシを含んでいる' do
-      r = Panel.list_opt[:include]
-      r.has_key?(:balloons).should be_true\r
+      r = Panel.show_include_opt
+      r.has_key?(:speech_balloons).should be_true\r
     end
+      it 'フキダシはフキダシ枠を含んでいる' do
+        r = Panel.show_include_opt
+        r[:speech_balloons].has_key?(:balloons).should be_true\r
+      end
       it 'フキダシはセリフを含んでいる' do
-        r = Panel.list_opt[:include]
-        r[:balloons].has_key?(:speeches).should be_true\r
+        r = Panel.show_include_opt
+        r[:speech_balloons].has_key?(:speeches).should be_true\r
       end
     it '作家を含んでいる' do
       r = Panel.list_opt[:include]
@@ -648,12 +657,16 @@ describe Panel do
           r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
         end
     it 'フキダシを含んでいる' do
-      r = Panel.list_json_opt[:include]
-      r.has_key?(:balloons).should be_true\r
+      r = Panel.show_include_opt
+      r.has_key?(:speech_balloons).should be_true\r
     end
+      it 'フキダシはフキダシ枠を含んでいる' do
+        r = Panel.show_include_opt
+        r[:speech_balloons].has_key?(:balloons).should be_true\r
+      end
       it 'フキダシはセリフを含んでいる' do
-        r = Panel.list_json_opt[:include]
-        r[:balloons].has_key?(:speeches).should be_true\r
+        r = Panel.show_include_opt
+        r[:speech_balloons].has_key?(:speeches).should be_true\r
       end
     it '作家を含んでいる' do
       r = Panel.list_json_opt[:include]