OSDN Git Service

make license group controller
authoryasushiito <yas@pen-chan.jp>
Tue, 26 Jun 2012 10:50:56 +0000 (19:50 +0900)
committeryasushiito <yas@pen-chan.jp>
Tue, 26 Jun 2012 10:50:56 +0000 (19:50 +0900)
app/controllers/license_groups_controller.rb
app/views/license_groups/index.html.erb [new file with mode: 0644]
app/views/license_groups/show.html.erb [new file with mode: 0644]
spec/controllers/license_groups_controller_spec.rb
spec/models/license_group_spec.rb

index 19a1b77..7d3aa4b 100644 (file)
@@ -1,4 +1,5 @@
 class LicenseGroupsController < ApplicationController
+  layout 'test' if Pettanr::TestLayout
   before_filter :authenticate_admin!, :only => [:list, :browse]
   
   # GET /license_groups
diff --git a/app/views/license_groups/index.html.erb b/app/views/license_groups/index.html.erb
new file mode 100644 (file)
index 0000000..331ce18
--- /dev/null
@@ -0,0 +1,17 @@
+<h1>Listing license Groups</h1>
+
+<table>
+  <tr>
+    <th>id</th>
+    <th>name</th>
+    <th>caption</th>
+  </tr>
+
+<% @license_groups.each do |lg| %>
+  <tr>
+    <td><%= link_to lg.id, license_group_path(lg) %></td>
+    <td><%= h lg.name %></td>
+    <td><%= content_tag(:a, h(lg.caption), :href => lg.url) %></td>
+  </tr>
+<% end -%>
+</table>
diff --git a/app/views/license_groups/show.html.erb b/app/views/license_groups/show.html.erb
new file mode 100644 (file)
index 0000000..ce494af
--- /dev/null
@@ -0,0 +1,22 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+<%= h @license_group.name %>
+</p>
+<p>
+<%= h @license_group.classname %>
+</p>
+<p>
+<%= h @license_group.caption %>
+</p>
+<p>
+<%= h @license_group.url %>
+</p>
+<p>
+<%= @license_group.created_at %>
+</p>
+<p>
+<%= @license_group.updated_at %>
+</p>
+
+<%= link_to 'Back', license_groups_path %>
index a269321..9064b78 100644 (file)
@@ -1,5 +1,115 @@
+# -*- encoding: utf-8 -*-
+#ライセンスグループ
 require 'spec_helper'
 
 describe LicenseGroupsController do
+  before do
+    @admin = Factory :admin
+    @user = Factory( :user_yas)
+    @lg = Factory :license_group, :name => 'peta'
+  end
+
+  describe '一覧表示に於いて' do
+    before do
+      sign_in @user
+      LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      it 'ライセンスモデルに一覧を問い合わせている' do
+        LicenseGroup.should_receive(:list).exactly(1)
+        get :index
+      end
+      it '@license_groupsにリストを取得している' do
+        get :index
+        assigns(:license_groups).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?("name").should be_true
+          json.first.has_key?("classname").should be_true
+          json.first.has_key?("caption").should be_true
+          json.first.has_key?("url").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 okを返す' do
+        get :index
+        response.status.should eq 200
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      LicenseGroup.stub(:show).and_return(@lg)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @lg.id
+        response.should be_success
+      end
+      it 'ライセンスモデルに単体取得を問い合わせている' do
+        LicenseGroup.should_receive(:show).exactly(1)
+        get :show
+      end
+      it '@license_groupにアレを取得している' do
+        get :show, :id => @lg.id
+        assigns(:license_group).id.should eq(@lg.id)
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @lg.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @lg.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @lg.id, :format => :json
+          json = JSON.parse response.body
+          json["name"].should match(/peta/)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 okを返す' do
+        get :show, :id => @lg.id
+        response.status.should eq 200
+      end
+    end
+  end
+  
 
 end
index f24f524..00a4df0 100644 (file)
@@ -251,14 +251,14 @@ describe LicenseGroup do
   end
   describe '一覧取得に於いて' do
     before do
-      @lg = Factory :license_group
+      @lg = Factory :license_group, :name => "1"
     end
     it 'リストを返す' do
       l = LicenseGroup.list
       l.should eq [@lg]
     end
     it '名前順で並んでいる' do
-      @lg2 = Factory :license_group, :name => "Z" + @lg.name, :url => 'http://test.ptn/10'
+      @lg2 = Factory :license_group, :name => "5", :url => 'http://test.ptn/10'
       l = LicenseGroup.list
       l.should eq [@lg, @lg2]
     end