OSDN Git Service

create demander
authoryasushiito <yas@pen-chan.jp>
Fri, 7 Dec 2012 05:43:18 +0000 (14:43 +0900)
committeryasushiito <yas@pen-chan.jp>
Fri, 7 Dec 2012 05:43:18 +0000 (14:43 +0900)
app/controllers/application_controller.rb
app/models/provider.rb
app/views/layouts/test.html.erb
app/views/provider_statuses/show.html.erb
app/views/system/import.html.erb
config/magic_number.yml
config/routes.rb
spec/controllers/comics_controller_spec.rb
spec/controllers/provider_sources_controller_spec.rb
spec/controllers/provider_statuses_controller_spec.rb
spec/factories.rb

index e9fa1f2..60d5f82 100644 (file)
@@ -27,6 +27,11 @@ class ApplicationController < ActionController::Base
       else
         nil
       end
+      @demand_user = if demand_user_signed_in?
+        current_demand_user
+      else
+        nil
+      end
     end
   end
   
index 42925c8..b7936b6 100644 (file)
@@ -41,10 +41,6 @@ class Provider < ActiveRecord::Base
     30
   end
   
-  def self.max_panel_size
-    200
-  end
-  
   def self.page prm = nil
     page = prm.to_i
     page = 1 if page < 1
@@ -118,7 +114,7 @@ class Provider < ActiveRecord::Base
           r.provider_status_id = nil
        end
       end
-      r.save
+      raise ActiveRecord::Rollback unless r.save
     end
     r
   end
index 110c475..9bb76ac 100644 (file)
 <%= link_to 'system_pictures', main_app.system_pictures_path %>\r
 </div>\r
 <%= yield %>\r
+<div>\r
+demanders\r
+<% if demand_user_signed_in? %>\r
+  <%= link_to "demanders", main_app.demanders_path %>\r
+  <%= link_to "sign out", main_app.destroy_demand_user_session_path, :method => :delete %>\r
+<% else %>\r
+  <%= link_to "sign in", main_app.new_demand_user_session_path %>\r
+<% end %>\r
+</div>\r
 <%= javascript_tag 'var server_result=' + @server_result.to_json + ';' %>\r
 \r
 </body>\r
index 8195faa..8775a6e 100644 (file)
@@ -31,7 +31,7 @@ receive_hour2
   <% if @provider_status.status == 0 %>
     <%= link_to 'この貸手からの借受を開始する', edit_provider_status_path(@provider_status) %>
   <% else %>
-    <%= link_to '借受を停止する', destroy_provider_status_path(@provider_status) %>
+    <%= link_to '借受を停止する', provider_status_path(@provider_status), :method => :delete %>
   <% end %>
 </p>
 <%= link_to 'Back', provider_statuses_path %>
index 45f72e3..d6b29e6 100644 (file)
       <%= link_to '貸手', providers_path %>
     </td>
   </tr>
+  <tr>
+    <td>
+      <%= link_to '借受状況', provider_statuses_path %>
+    </td>
+  </tr>
+</table>
+<h1>貸手</h1>
+<table>
+  <tr>
+    <td>
+      <%= link_to '貸与状況', demander_statuses_path %>
+    </td>
+  </tr>
 </table>
 </div>
index fe42478..430388d 100644 (file)
@@ -4,6 +4,7 @@
   thumbnail_height: 64
 
   provider_status_items: [['waiting', 0], ['receiving', 1]]
+  demander_status_items: [['waiting', 0], ['rejected', 1], ['requesting', 2], ['approved', 3]]
   
   comic_visible_items: [['private', 0], ['public', 1]]
   ground_picture_repeat_items: ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
index 3647ec2..badc1ef 100644 (file)
@@ -2,6 +2,7 @@ Pettanr::Application.routes.draw do
 
   devise_for :users , :controllers => { :registrations => "user_registrations" }
   devise_for :admins
+  devise_for :demand_users
   
   Pettanr::Application.licenses.each do |name, klass|
     mount Module.const_get(klass)::Engine => "/#{name}"
@@ -268,6 +269,37 @@ Pettanr::Application.routes.draw do
       delete :destroy
     end
   end
+  resources :demanders do
+    new do
+      get :new
+    end
+    collection do
+      get :index
+      get :show
+      post :create
+      get :list
+      get :browse
+      post :req
+    end
+    member do
+      get :edit
+      put :update
+      delete :destroy
+    end
+  end
+  resources :demander_statuses do
+    collection do
+      get :index
+      get :show
+      get :list
+      get :browse
+    end
+    member do
+      get :edit
+      put :update
+      delete :destroy
+    end
+  end
   # The priority is based upon order of creation:
   # first created -> highest priority.
 
index 37b885e..8b76a56 100644 (file)
@@ -68,10 +68,10 @@ describe ComicsController do
           get :index, :format => :json\r
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
         end\r
-        it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
-          Comic.should_receive(:list_json_opt).exactly(1)
-          get :index, :format => :json
-        end
+        it 'コミックモデルにjson一覧出力オプションを問い合わせている' do\r
+          Comic.should_receive(:list_json_opt).exactly(1)\r
+          get :index, :format => :json\r
+        end\r
         it 'データがリスト構造になっている' do\r
           get :index, :format => :json\r
           json = JSON.parse response.body\r
@@ -142,10 +142,10 @@ describe ComicsController do
           get :show, :id => @comic.id, :format => :json\r
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
         end\r
-        it 'コミックモデルにjson単体出力オプションを問い合わせている' do
-          Comic.should_receive(:show_json_opt).exactly(1)
-          get :show, :id => @comic.id, :format => :json
-        end
+        it 'コミックモデルにjson単体出力オプションを問い合わせている' do\r
+          Comic.should_receive(:show_json_opt).exactly(1)\r
+          get :show, :id => @comic.id, :format => :json\r
+        end\r
         it 'データがアレになっている' do\r
           get :show, :id => @comic.id, :format => :json\r
           json = JSON.parse response.body\r
@@ -271,16 +271,16 @@ describe ComicsController do
           response.should render_template("new")\r
         end\r
       end\r
-      context 'json形式' do
-        it 'jsonデータを返す' do
-          get :new, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'コミックモデルにjson単体出力オプションを問い合わせている' do
-          Comic.should_receive(:show_json_opt).exactly(1)
-          get :new, :format => :json
-        end
-      end
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :new, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'コミックモデルにjson単体出力オプションを問い合わせている' do\r
+          Comic.should_receive(:show_json_opt).exactly(1)\r
+          get :new, :format => :json\r
+        end\r
+      end\r
     end\r
     context '作家権限がないとき' do\r
       before do\r
@@ -306,6 +306,16 @@ describe ComicsController do
           response.message.should match(/Unauthorized/)\r
         end\r
       end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :new, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :new, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
     end\r
   end\r
 \r
@@ -317,19 +327,19 @@ describe ComicsController do
     context '事前チェックしておく' do\r
       it 'コミックモデルにデフォルト値補充を依頼している' do\r
         Comic.any_instance.should_receive(:supply_default).exactly(1)\r
-        post :create, :artist => @attr\r
-      end
+        post :create, :comic => @attr\r
+      end\r
       it 'コミックモデルにカラム値復元を依頼している' do\r
         Comic.any_instance.should_receive(:attributes=).exactly(1)\r
-        post :create, :artist => @attr\r
+        post :create, :comic => @attr\r
       end\r
       it 'コミックモデルに上書き補充を依頼している' do\r
         Comic.any_instance.should_receive(:overwrite).exactly(1)\r
-        post :create, :artist => @attr\r
+        post :create, :comic => @attr\r
       end\r
       it 'モデルに保存依頼する' do\r
         Comic.any_instance.should_receive(:save).exactly(1)\r
-        post :create, :artist => @attr\r
+        post :create, :comic => @attr\r
       end\r
     end\r
     context 'つつがなく終わるとき' do\r
index 6f0301c..2e97ed7 100644 (file)
@@ -59,7 +59,7 @@ describe ProviderSourcesController do
     before do
       sign_in @admin
       @ps = MagicNumber['provider_sources']
-      @results = @ps.map {|u| {u => {:validations => []}}}
+      @results = @ps.map {|u| {u => {'validations' => []}}}
       Provider.stub(:import).with(@ps).and_return @results
     end
     context '事前チェックする' do
index e13ec8e..e70216a 100644 (file)
@@ -232,12 +232,6 @@ describe ProviderStatusesController do
           response.should render_template("edit")
         end
       end
-      context 'js形式' do
-        it 'edit.jsテンプレートを描画する' do
-          get :edit, :id => @ps.id, :format => :js
-          response.should render_template("edit")
-        end
-      end
     end
     context '管理者権限がないとき' do
       before do
@@ -253,16 +247,6 @@ describe ProviderStatusesController do
           response.body.should redirect_to '/admins/sign_in'
         end
       end
-      context 'js形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :edit, :id => @ps.id, :format => :js
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :edit, :id => @ps.id, :format => :js
-          response.message.should match(/Unauthorized/)
-        end
-      end
     end
   end
 
index 5f09ea3..00c9ee8 100644 (file)
@@ -15,6 +15,13 @@ FactoryGirl.define do
   #  user.author FactoryGirl.create(:author_yas)
   end
 
+  factory :demand_user, :class => DemandUser do |demand_user|
+    demand_user.sequence(:email) { |n| "hoge#{n}@gmail.com"}
+    demand_user.password "user0100"
+    demand_user.password_confirmation "user0100"
+  #  user.author FactoryGirl.create(:author_yas)
+  end
+
   factory :author, :class => Author do |author|
     author.name nil
     author.sequence(:user_id) { |n| n}
@@ -202,12 +209,12 @@ FactoryGirl.define do
   end
 
   factory :provider, :class => Provider do |provider|
-    provider.provider_status_id 1
     provider.name 'admin@penguinkingdom.com'
-    provider.caption 'ペンギン王国"'
+    provider.caption 'ペンギン王国'
     provider.url 'http://localhost:3000/'
     provider.description 'ペンギン王国はペンギン素材を豊富に用意したペンギンマニアのサイトです。'
     provider.demander_url 'http://localhost:3000/demanders'
+    provider.provider_status_id 1
   end
 
   factory :provider_status, :class => ProviderStatus do |provider_status|
@@ -218,4 +225,22 @@ FactoryGirl.define do
     provider_status.stopped_at nil
   end
 
+  factory :demander, :class => Demander do |demander|
+    demander.demand_user_id 1
+    demander.name 'admin@penguinkingdom.com'
+    demander.caption 'ペンギン王国'
+    demander.url 'http://localhost:3000/'
+    demander.description 'ペンギン王国はペンギン素材を豊富に用意したペンギンマニアのサイトです。'
+    demander.demander_url 'http://localhost:3000/demanders'
+    demander.demander_status_id 1
+  end
+
+  factory :demander_status, :class => DemanderStatus do |demander_status|
+    demander_status.requested_at nil
+    demander_status.rejected_at nil
+    demander_status.approved_at nil
+    demander_status.token nil
+    demander_status.receive_hour1 nil
+    demander_status.receive_hour2 nil
+  end
 end