From cff561f0f6edceed0daac9f0ba062f75e3d6a814 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Fri, 7 Dec 2012 14:43:18 +0900 Subject: [PATCH] create demander --- app/controllers/application_controller.rb | 5 ++ app/models/provider.rb | 6 +-- app/views/layouts/test.html.erb | 9 ++++ app/views/provider_statuses/show.html.erb | 2 +- app/views/system/import.html.erb | 13 +++++ config/magic_number.yml | 1 + config/routes.rb | 32 +++++++++++++ spec/controllers/comics_controller_spec.rb | 56 +++++++++++++--------- .../provider_sources_controller_spec.rb | 2 +- .../provider_statuses_controller_spec.rb | 16 ------- spec/factories.rb | 29 ++++++++++- 11 files changed, 123 insertions(+), 48 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e9fa1f2e..60d5f824 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/models/provider.rb b/app/models/provider.rb index 42925c81..b7936b6b 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -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 diff --git a/app/views/layouts/test.html.erb b/app/views/layouts/test.html.erb index 110c475c..9bb76ac8 100644 --- a/app/views/layouts/test.html.erb +++ b/app/views/layouts/test.html.erb @@ -52,6 +52,15 @@ <%= link_to 'system_pictures', main_app.system_pictures_path %> <%= yield %> +
+demanders +<% if demand_user_signed_in? %> + <%= link_to "demanders", main_app.demanders_path %> + <%= link_to "sign out", main_app.destroy_demand_user_session_path, :method => :delete %> +<% else %> + <%= link_to "sign in", main_app.new_demand_user_session_path %> +<% end %> +
<%= javascript_tag 'var server_result=' + @server_result.to_json + ';' %> diff --git a/app/views/provider_statuses/show.html.erb b/app/views/provider_statuses/show.html.erb index 8195faa4..8775a6ea 100644 --- a/app/views/provider_statuses/show.html.erb +++ b/app/views/provider_statuses/show.html.erb @@ -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 %>

<%= link_to 'Back', provider_statuses_path %> diff --git a/app/views/system/import.html.erb b/app/views/system/import.html.erb index 45f72e30..d6b29e61 100644 --- a/app/views/system/import.html.erb +++ b/app/views/system/import.html.erb @@ -13,5 +13,18 @@ <%= link_to '貸手', providers_path %> + + + <%= link_to '借受状況', provider_statuses_path %> + + + +

貸手

+ + + +
+ <%= link_to '貸与状況', demander_statuses_path %> +
diff --git a/config/magic_number.yml b/config/magic_number.yml index fe424780..430388d8 100644 --- a/config/magic_number.yml +++ b/config/magic_number.yml @@ -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'] diff --git a/config/routes.rb b/config/routes.rb index 3647ec20..badc1ef4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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. diff --git a/spec/controllers/comics_controller_spec.rb b/spec/controllers/comics_controller_spec.rb index 37b885e0..8b76a567 100644 --- a/spec/controllers/comics_controller_spec.rb +++ b/spec/controllers/comics_controller_spec.rb @@ -68,10 +68,10 @@ describe ComicsController do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end - it 'コミックモデルにjson一覧出力オプションを問い合わせている' do - Comic.should_receive(:list_json_opt).exactly(1) - get :index, :format => :json - end + it 'コミックモデルにjson一覧出力オプションを問い合わせている' do + Comic.should_receive(:list_json_opt).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body @@ -142,10 +142,10 @@ describe ComicsController do get :show, :id => @comic.id, :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 :show, :id => @comic.id, :format => :json - end + it 'コミックモデルにjson単体出力オプションを問い合わせている' do + Comic.should_receive(:show_json_opt).exactly(1) + get :show, :id => @comic.id, :format => :json + end it 'データがアレになっている' do get :show, :id => @comic.id, :format => :json json = JSON.parse response.body @@ -271,16 +271,16 @@ describe ComicsController do response.should render_template("new") end end - 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 + 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 end context '作家権限がないとき' do before do @@ -306,6 +306,16 @@ describe ComicsController do response.message.should match(/Unauthorized/) end end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :new, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :new, :format => :json + response.message.should match(/Unauthorized/) + end + end end end @@ -317,19 +327,19 @@ describe ComicsController do context '事前チェックしておく' do it 'コミックモデルにデフォルト値補充を依頼している' do Comic.any_instance.should_receive(:supply_default).exactly(1) - post :create, :artist => @attr - end + post :create, :comic => @attr + end it 'コミックモデルにカラム値復元を依頼している' do Comic.any_instance.should_receive(:attributes=).exactly(1) - post :create, :artist => @attr + post :create, :comic => @attr end it 'コミックモデルに上書き補充を依頼している' do Comic.any_instance.should_receive(:overwrite).exactly(1) - post :create, :artist => @attr + post :create, :comic => @attr end it 'モデルに保存依頼する' do Comic.any_instance.should_receive(:save).exactly(1) - post :create, :artist => @attr + post :create, :comic => @attr end end context 'つつがなく終わるとき' do diff --git a/spec/controllers/provider_sources_controller_spec.rb b/spec/controllers/provider_sources_controller_spec.rb index 6f0301c7..2e97ed70 100644 --- a/spec/controllers/provider_sources_controller_spec.rb +++ b/spec/controllers/provider_sources_controller_spec.rb @@ -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 diff --git a/spec/controllers/provider_statuses_controller_spec.rb b/spec/controllers/provider_statuses_controller_spec.rb index e13ec8e7..e70216a8 100644 --- a/spec/controllers/provider_statuses_controller_spec.rb +++ b/spec/controllers/provider_statuses_controller_spec.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index 5f09ea33..00c9ee8a 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 -- 2.11.0