OSDN Git Service

fix test
authoryasushiito <yas@pen-chan.jp>
Wed, 25 Jun 2014 09:29:14 +0000 (18:29 +0900)
committeryasushiito <yas@pen-chan.jp>
Wed, 25 Jun 2014 09:29:14 +0000 (18:29 +0900)
app/models/artist.rb
spec/controller_helper.rb [new file with mode: 0644]
spec/controllers/scrolls_controller_spec.rb
spec/factories/user.rb
spec/spec_helper.rb

index 83ecf69..3604e57 100644 (file)
@@ -7,7 +7,7 @@ class Artist < Peta::Owner
   
   validates :name, :presence => true, :length => {:maximum => 30}
   validates :user_id, :numericality => true, :existence => {:both => false}
-  validates :provider_id, :numericality => {:allow_nil => true}
+  validates :provider, :numericality => {:allow_nil => true}
   
   def supply_default
     self.name = 'no name' if self.name.blank?
@@ -19,7 +19,7 @@ class Artist < Peta::Owner
   end
   
   def self.list_where
-    'artists.provider_id is null'
+    'artists.provider is null'
   end
   
   def self.show_opt
diff --git a/spec/controller_helper.rb b/spec/controller_helper.rb
new file mode 100644 (file)
index 0000000..086b5d8
--- /dev/null
@@ -0,0 +1,38 @@
+module ControllerMacros
+  def list_should_return_filer_or_json action, params = {}
+    # html\8c`\8e®: 
+    # \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
+    # filer\83e\83\93\83v\83\8c\81[\83g\82ð\95`\89æ\82·\82é
+    get action, params
+    response.should be_success 
+    response.should render_template("templates/r/filer/filer")
+    # json\8c`\8e®
+    # \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
+    # json\83f\81[\83^\82ð\95Ô\82·
+    get action, params.merge(:format => :json)
+    response.should be_success 
+    lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+  end
+  
+  def announce_sign_in_at_get action, params = {}
+    # html\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h302 Found\82ð\95Ô\82·
+    get action, params
+    response.status.should eq 302
+    response.should redirect_to '/users/sign_in'
+    # json\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h401 Unauthorized\82ð\95Ô\82·
+    get action, params.merge(:format => :json)
+    response.status.should eq 401
+    response.message.should match(/Unauthorized/)
+  end
+  
+  def return_ok_at_get action, params = {}
+    # html\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
+    get action, params
+    response.should be_success 
+    # json\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
+    get action, params.merge(:format => :json)
+    response.should be_success 
+  end
+  
+end
+
index 267879a..9a93a82 100644 (file)
@@ -9,100 +9,86 @@ describe ScrollsController do
 if Manifest.manifest.magic_numbers['run_mode'] == 1
   describe '一覧表示に於いて' do
     before do
-      #@scroll = FactoryGirl.create :scroll_hello
-      #@author_yas = @scroll.author
       @author_yas =  FactoryGirl.create :yas_with_scrolls
       @user_yas = @author_yas.user
-      sign_in @user_yas
     end
+    
     context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :index
-        response.should be_success 
+      before do
+        sign_in @user_yas
       end
-      it '@scrollsにリストを取得している' do
+      it '@itemsにリストを取得している' do
         get :index
-        assigns(:scrolls).should have_at_least(3).items
-      end
-      context 'html形式' do
-        it 'indexテンプレートを描画する' do
-          get :index
-          response.should render_template("index")
-        end
+        except(assigns(:items).size).to be >= 3
       end
-      context 'json形式' do
-        it 'jsonデータを返す' do
-          get :index, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
+      it 'ステータスコード200 OKを返す' do
+        list_should_return_filer_or_json :index
       end
     end
-    context 'ユーザ権限がないとき' do
-      before do
-        sign_out @user_yas
+    context '権限' do
+      it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
+        sign_in @admin
+        return_ok_at_get :index
       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
+      it 'ユーザだが作家登録していないとき 200 OKを返す' do
+        @user_rom = FactoryGirl.create :user_rom
+        sign_in @user_rom
+        return_ok_at_get :index
       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
+      it 'sign_inを返す' do
+        announce_sign_in_at_get :index
       end
     end
-    context 'ユーザ権限はないが管理者権限があるとき' do
+  end
+  describe '作家フィルタ一覧及びカウント' do
+    before do
+      @author_yas =  FactoryGirl.create :yas_with_scrolls
+      @user_yas = @author_yas.user
+      @scroll = @author_yas.scrolls.first
+    end
+    context 'つつがなく終わるとき' do
       before do
-        sign_out @user_yas
-        sign_in @admin
+        sign_in @user_yas
+      end
+      it '@itemsにリストを取得している' do
+        get :by_author
+        except(assigns(:items).size).to be >= 3
       end
       it 'ステータスコード200 OKを返す' do
-        get :index
-        response.should be_success 
+        list_should_return_filer_or_json :by_author, id: @author_yas.id
       end
     end
-    context 'ユーザだが作家登録していないとき' do
-      before do
-        sign_out @user_yas
-        @user_ghost = FactoryGirl.create :user_ghost
-        sign_in @user_ghost
+    context '権限' do
+      it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
+        sign_in @admin
+        return_ok_at_get :by_author
       end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :index
-          response.should be_success 
-        end
+      it 'ユーザだが作家登録していないとき 200 OKを返す' do
+        @user_rom = FactoryGirl.create :user_rom, id: @author_yas.id
+        sign_in @user_rom
+        return_ok_at_get :by_author
+      end
+      it 'sign_inを返す' do
+        announce_sign_in_at_get :by_author, id: @author_yas.id
       end
     end
   end
   
   describe '単体表示に於いて' do
     before do
-      @scroll = FactoryGirl.create :scroll_hello
-      @author_yas = @scroll.author
+      @author_yas =  FactoryGirl.create :yas_with_scrolls
       @user_yas = @author_yas.user
-      Scroll.stub(:show).and_return(@scroll)
-      sign_in @user
+      sign_in @user_yas
+      @scroll = @author_yas.scrolls.first
     end
     context 'つつがなく終わるとき' do
       it 'ステータスコード200 OKを返す' do
         get :show, :id => @scroll.id
         response.should be_success
       end
-      it '@scrollにアレを取得している' do
+      it '@itemにアレを取得している' do
         get :show, :id => @scroll.id
-        assigns(:scroll).id.should eq(@scroll.id)
+        assigns(:item).id.should eq(@scroll.id)
       end
       context 'html形式' do
         it 'showテンプレートを描画する' do
@@ -116,6 +102,12 @@ if Manifest.manifest.magic_numbers['run_mode'] == 1
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
       end
+      context 'prof形式' do
+        it 'profilerを描画する' do
+          get :show, :id => @scroll.id, :format => :prof
+          response.should render_template("templates/r/profiler/profiler")
+        end
+      end
     end
     context 'ユーザ権限がないとき' do
       before do
@@ -216,42 +208,6 @@ if Manifest.manifest.magic_numbers['run_mode'] == 1
       ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
       sign_in @user
     end
-    context 'パラメータチェックする' do
-      it '与えられたoffsetがセットされている' do
-        get :play, :id => @scroll.id, :offset => 5
-        assigns(:offset).should eq 5
-      end
-      it '省略されると@offsetに0値が入る' do
-        get :play, :id => @scroll.id
-        assigns(:offset).should eq 0
-      end
-      it '与えられたcountがセットされている' do
-        get :play, :id => @scroll.id, :count => 4
-        assigns(:panel_count).should eq 4
-      end
-      it '省略されると@panel_countにデフォルト値が入る' do
-        get :play, :id => @scroll.id
-        assigns(:panel_count).should eq ScrollPanel.default_panel_size
-      end
-      it '最大を超えると@panel_countにデフォルト最大値が入る' do
-        get :play, :id => @scroll.id, :count => 1500
-        assigns(:panel_count).should eq ScrollPanel.max_panel_size
-      end
-      it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
-        get :play, :id => @scroll.id, :count => -1
-        assigns(:panel_count).should eq ScrollPanel.default_panel_size
-      end
-    end
-    context '事前チェックする' do
-      it 'スクロールモデルに単体取得を問い合わせている' do
-        Scroll.should_receive(:show).with(@scroll.id.to_s, [@user, nil]).exactly(1)
-        get :play, :id => @scroll.id
-      end
-      it 'スクコマモデルにプレイリスト取得を問い合わせている' do
-        ScrollPanel.should_receive(:play_list).with(@scroll, @author, 0, 30).exactly(1)
-        get :play, :id => @scroll.id
-      end
-    end
     context 'つつがなく終わるとき' do
       it '@scroll_panelsにリストを取得している' do
         get :play, :id => @scroll.id
@@ -276,22 +232,6 @@ if Manifest.manifest.magic_numbers['run_mode'] == 1
           get :play, :id => @scroll.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'スクコマモデルにスクコマリストのjson出力を問い合わせている' do
-          ScrollPanel.should_receive(:list_as_json_text).exactly(1)
-          get :play, :id => @scroll.id, :format => :json
-        end
-        it 'データがリスト構造になっている' do
-          get :play, :id => @scroll.id, :format => :json
-          json = JSON.parse response.body
-          json.should have_at_least(3).items
-        end
-        it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
-          get :play, :id => @scroll.id, :format => :json
-          json = JSON.parse response.body
-          json.first.has_key?("panel_id").should be_true
-          json.first.has_key?("scroll_id").should be_true
-          json.first.has_key?("author_id").should be_true
-        end
       end
     end
     context 'ユーザ権限がないとき' do
index 27ee1b8..440468f 100644 (file)
@@ -9,6 +9,18 @@ FactoryGirl.define do
     i.email "itojun@jmail.com"\r
     i.password "user0100"\r
     i.password_confirmation "user0100"\r
+    trait :with_owner do\r
+      after(:create) do |user|\r
+        create(:author_itojun, user: user)\r
+        create(:artist_itojun, user: user)\r
+      end\r
+    end\r
+    factory :user_itojun_with_owner, traits: [:with_owner]\r
+  end\r
+  factory :user_rom, :class => User do |i|\r
+    i.email "rom@jmail.com"\r
+    i.password "user0100"\r
+    i.password_confirmation "user0100"\r
   end\r
   factory :user_ghost, :class => User do |i|\r
     i.email "ghost@jmail.com"\r
index 19d27e0..c0569b6 100644 (file)
@@ -3,6 +3,7 @@ ENV["RAILS_ENV"] ||= 'test'
 require File.expand_path("../../config/environment", __FILE__)
 require 'rspec/rails'
 require 'rspec/autorun'
+require File.dirname(__FILE__) + '/controller_helper'
 
 # Requires supporting ruby files with custom matchers and macros, etc,
 # in spec/support/ and its subdirectories.
@@ -35,4 +36,6 @@ RSpec.configure do |config|
 #  config.extend ControllerMacros, :type => :controller
   config.infer_spec_type_from_file_location!
   config.raise_errors_for_deprecations!
+  
+  config.include ControllerMacros
 end