From c7216b685d62319f15e1cb982a0cfc50274ba043 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Mon, 3 Sep 2012 19:07:15 +0900 Subject: [PATCH] t#29400:update:itr2 --- app/controllers/artists_controller.rb | 8 +- app/controllers/balloons_controller.rb | 12 - app/controllers/colors_controller.rb | 2 +- app/controllers/comics_controller.rb | 9 +- app/controllers/ground_colors_controller.rb | 2 +- app/controllers/license_groups_controller.rb | 4 +- app/controllers/licenses_controller.rb | 4 +- .../original_picture_license_groups_controller.rb | 19 - app/controllers/original_pictures_controller.rb | 21 +- app/controllers/panel_colors_controller.rb | 2 +- app/controllers/panel_pictures_controller.rb | 2 +- app/controllers/speech_balloons_controller.rb | 110 +---- app/models/color.rb | 51 +- app/models/comic.rb | 50 +- app/models/ground_color.rb | 30 +- app/models/ground_picture.rb | 30 +- app/models/license.rb | 65 +-- app/models/license_group.rb | 57 ++- app/models/original_picture.rb | 98 ++-- app/models/panel_color.rb | 30 +- app/models/panel_picture.rb | 26 +- app/models/speech_balloon.rb | 6 - spec/controllers/artists_controller_spec.rb | 32 +- spec/controllers/colors_controller_spec.rb | 4 + spec/controllers/comics_controller_spec.rb | 58 ++- spec/controllers/ground_colors_controller_spec.rb | 6 +- spec/controllers/license_groups_controller_spec.rb | 13 +- spec/controllers/licenses_controller_spec.rb | 12 + .../original_pictures_controller_spec.rb | 42 +- spec/controllers/panel_colors_controller_spec.rb | 4 + spec/controllers/panel_pictures_controller_spec.rb | 6 + spec/factories.rb | 2 +- spec/models/author_spec.rb | 1 - spec/models/balloon_spec.rb | 73 +-- spec/models/color_spec.rb | 270 +++++++---- spec/models/comic_spec.rb | 381 +++++++++------ spec/models/ground_color_spec.rb | 134 ++++-- spec/models/ground_picture_spec.rb | 133 +++++- spec/models/license_group_spec.rb | 237 ++++++---- spec/models/license_spec.rb | 254 +++++----- spec/models/original_picture_license_group_spec.rb | 23 +- spec/models/original_picture_spec.rb | 518 +++++++++++++-------- spec/models/panel_color_spec.rb | 115 ++++- spec/models/panel_picture_spec.rb | 181 ++++--- spec/models/speech_balloon_spec.rb | 58 +-- spec/models/speech_spec.rb | 58 +-- 46 files changed, 1957 insertions(+), 1296 deletions(-) diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index 52c4f240..afacb4a3 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -61,13 +61,17 @@ layout 'test' respond_to do |format| format.html # new.html.erb format.js - format.json { render json: @artist } + format.json { render json: @artist.to_json(Artist.show_json_opt) } end end # GET /artists/1/edit def edit @artist = Artist.edit(params[:id], @author) + respond_to do |format| + format.html + format.js + end end # POST /artists @@ -80,7 +84,7 @@ layout 'test' respond_to do |format| if @artist.save format.html { redirect_to @artist, notice: 'Artist was successfully created.' } - format.json { render json: @artist, status: :created, location: @artist } + format.json { render json: @artist.to_json(Artist.show_json_opt), status: :created, location: @artist } else format.html { render action: "new" } format.json { render json: @artist.errors, status: :unprocessable_entity } diff --git a/app/controllers/balloons_controller.rb b/app/controllers/balloons_controller.rb index eb8025ce..4d2bd336 100644 --- a/app/controllers/balloons_controller.rb +++ b/app/controllers/balloons_controller.rb @@ -1,18 +1,6 @@ class BalloonsController < ApplicationController - before_filter :authenticate_user!, :only => [:index, :show] before_filter :authenticate_admin!, :only => [:list, :browse] - # GET /balloons - # GET /balloons.json - def index - @balloons = Balloon.all - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @balloons } - end - end - def list @balloons = Balloon.all diff --git a/app/controllers/colors_controller.rb b/app/controllers/colors_controller.rb index 9a936ffb..00ea365f 100644 --- a/app/controllers/colors_controller.rb +++ b/app/controllers/colors_controller.rb @@ -6,7 +6,7 @@ class ColorsController < ApplicationController def index @page = PanelColor.page params[:page] @page_size = PanelColor.page_size params[:page_size] - @colors = Color.list({}, @page, @page_size) + @colors = Color.list(@page, @page_size) respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/comics_controller.rb b/app/controllers/comics_controller.rb index 4444e834..1b6ccb35 100644 --- a/app/controllers/comics_controller.rb +++ b/app/controllers/comics_controller.rb @@ -23,7 +23,7 @@ class ComicsController < ApplicationController def index @page = Comic.page params[:page] @page_size = Comic.page_size params[:page_size] - @comics = Comic.list({}, @page, @page_size) + @comics = Comic.list(@page, @page_size) respond_to do |format| format.html # index.html.erb format.json { render json: @comics.to_json(Comic.list_json_opt) } @@ -37,7 +37,7 @@ class ComicsController < ApplicationController respond_to do |format| format.html # show.html.erb - format.json { render json: @comic.to_json(Comic.show_json_include_opt) } + format.json { render json: @comic.to_json(Comic.show_json_opt) } end end @@ -74,6 +74,7 @@ class ComicsController < ApplicationController respond_to do |format| format.html # new.html.erb format.js + format.json { render json: @comic.to_json(Comic.show_json_opt) } end end @@ -81,7 +82,6 @@ class ComicsController < ApplicationController # GET /comics/1.js/edit def edit @comic = Comic.edit(params[:id], @author) - @comic.supply_default respond_to do |format| format.html format.js @@ -91,7 +91,6 @@ class ComicsController < ApplicationController # POST /comics # POST /comics.json def create - params[:comic].merge! author_id: @author.id @comic = Comic.new @comic.supply_default @comic.attributes = params[:comic] @@ -100,7 +99,7 @@ class ComicsController < ApplicationController respond_to do |format| if @comic.save format.html { redirect_to @comic, notice: 'Comic was successfully created.' } - format.json { render json: Comic.show(@comic.id, @author).to_json(Comic.show_json_include_opt), status: :created, location: @comic } + format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic } else format.html { render action: "new" } format.json { render json: @comic.errors, status: :unprocessable_entity } diff --git a/app/controllers/ground_colors_controller.rb b/app/controllers/ground_colors_controller.rb index db1f252a..772f647c 100644 --- a/app/controllers/ground_colors_controller.rb +++ b/app/controllers/ground_colors_controller.rb @@ -7,7 +7,7 @@ class GroundColorsController < ApplicationController def index @page = GroundColor.page params[:page] @page_size = GroundColor.page_size params[:page_size] - @ground_colors = GroundColor.list({}, @page, @page_size) + @ground_colors = GroundColor.list(@page, @page_size) respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/license_groups_controller.rb b/app/controllers/license_groups_controller.rb index 7d3aa4b7..406de336 100644 --- a/app/controllers/license_groups_controller.rb +++ b/app/controllers/license_groups_controller.rb @@ -5,7 +5,7 @@ class LicenseGroupsController < ApplicationController # GET /license_groups # GET /license_groups.json def index - @license_groups = LicenseGroup.list({}) + @license_groups = LicenseGroup.list() respond_to do |format| format.html # index.html.erb @@ -19,7 +19,7 @@ class LicenseGroupsController < ApplicationController @license_group = LicenseGroup.show(params[:id]) respond_to do |format| format.html # show.html.erb - format.json { render json: @license_group.to_json(LicenseGroup.show_json_include_opt) } + format.json { render json: @license_group.to_json(LicenseGroup.show_json_opt) } end end diff --git a/app/controllers/licenses_controller.rb b/app/controllers/licenses_controller.rb index 4fa0b497..6e89e308 100644 --- a/app/controllers/licenses_controller.rb +++ b/app/controllers/licenses_controller.rb @@ -5,7 +5,7 @@ class LicensesController < ApplicationController # GET /licenses # GET /licenses.json def index - @licenses = License.list({}) + @licenses = License.list() respond_to do |format| format.html # index.html.erb @@ -19,7 +19,7 @@ class LicensesController < ApplicationController @license = License.show(params[:id]) respond_to do |format| format.html # show.html.erb - format.json { render json: @license.to_json(License.show_json_include_opt) } + format.json { render json: @license.to_json(License.show_json_opt) } end end diff --git a/app/controllers/original_picture_license_groups_controller.rb b/app/controllers/original_picture_license_groups_controller.rb index 05a2a248..21f4f337 100644 --- a/app/controllers/original_picture_license_groups_controller.rb +++ b/app/controllers/original_picture_license_groups_controller.rb @@ -3,25 +3,6 @@ class OriginalPictureLicenseGroupsController < ApplicationController before_filter :authenticate_user!, :only => [:new, :create] before_filter :authenticate_artist, :only => [:new, :create] - private - - def authenticate_artist - if @author.artist? - true - else - respond_to do |format| - format.html { redirect_to new_artist_path, :status => :found } - format.js { render "artists/new" } - format.json { - raise ActiveRecord::Forbidden - } - end - false - end - end - - public - # GET /original_picture_license_groups/new # GET /original_picture_license_groups/new.js def new diff --git a/app/controllers/original_pictures_controller.rb b/app/controllers/original_pictures_controller.rb index eaa3a847..ca3bc02b 100644 --- a/app/controllers/original_pictures_controller.rb +++ b/app/controllers/original_pictures_controller.rb @@ -22,7 +22,7 @@ class OriginalPicturesController < ApplicationController def index @page = OriginalPicture.page params[:page] @page_size = OriginalPicture.page_size params[:page_size] - @original_pictures = OriginalPicture.list(@artist.id, {}, @page, @page_size) + @original_pictures = OriginalPicture.mylist(@artist.id, @page, @page_size) respond_to do |format| format.html # index.html.erb @@ -45,7 +45,7 @@ class OriginalPicturesController < ApplicationController @original_picture_license_group = OriginalPictureLicenseGroup.new :original_picture_id => @original_picture.id render } - format.json { render json: @original_picture.to_json(OriginalPicture.show_json_include_opt)} + format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt)} end end @@ -77,25 +77,16 @@ class OriginalPicturesController < ApplicationController end end - def refresh - @original_picture = OriginalPicture.find(params[:id]) - img = Magick::Image.from_blob(@original_picture.restore).shift - @original_picture.store img - respond_to do |format| - format.html { redirect_to original_pictures_url } - end - end - # GET /original_pictures/new # GET /original_pictures/new.json def new @original_picture = OriginalPicture.new - @original_picture.supply_default @artist + @original_picture.supply_default respond_to do |format| format.html # new.html.erb format.js - format.json { render json: @original_picture } + format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt) } end end @@ -118,7 +109,7 @@ class OriginalPicturesController < ApplicationController respond_to do |format| if @original_picture.store(@picture_data, @artist) format.html { redirect_to @original_picture, notice: 'Original picture was successfully created.' } - format.json { render json: @original_picture, status: :created, location: @original_picture } + format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture } else format.html { render action: "new" } format.json { render json: @original_picture.errors, status: :unprocessable_entity } @@ -135,7 +126,7 @@ class OriginalPicturesController < ApplicationController respond_to do |format| if @original_picture.store(@picture_data, @artist) format.html { redirect_to @original_picture, notice: 'Original picture was successfully created.' } - format.json { render json: @original_picture, status: :created, location: @original_picture } + format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture } else format.html { render action: "edit" } format.json { render json: @original_picture.errors, status: :unprocessable_entity } diff --git a/app/controllers/panel_colors_controller.rb b/app/controllers/panel_colors_controller.rb index c701e771..8572c1f5 100644 --- a/app/controllers/panel_colors_controller.rb +++ b/app/controllers/panel_colors_controller.rb @@ -7,7 +7,7 @@ class PanelColorsController < ApplicationController def index @page = PanelColor.page params[:page] @page_size = PanelColor.page_size params[:page_size] - @panel_colors = PanelColor.list({}, @page, @page_size) + @panel_colors = PanelColor.list( @page, @page_size) respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/panel_pictures_controller.rb b/app/controllers/panel_pictures_controller.rb index d73715e4..4011887b 100644 --- a/app/controllers/panel_pictures_controller.rb +++ b/app/controllers/panel_pictures_controller.rb @@ -8,7 +8,7 @@ class PanelPicturesController < ApplicationController def index @page = PanelPicture.page params[:page] @page_size = PanelPicture.page_size params[:page_size] - @panel_pictures = PanelPicture.list({}, @page, @page_size) + @panel_pictures = PanelPicture.list(@page, @page_size) respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/speech_balloons_controller.rb b/app/controllers/speech_balloons_controller.rb index 36ab8392..85a39e28 100644 --- a/app/controllers/speech_balloons_controller.rb +++ b/app/controllers/speech_balloons_controller.rb @@ -1,65 +1,5 @@ class SpeechBalloonsController < ApplicationController - before_filter :authenticate_user!, :only => [:index, :show] - before_filter :authenticate_admin!, :only => [:list, :browse, :create, :update, :destroy] - - private - - def validate_param(ft) - res = nil - bl = ft[:size_count].to_i - tl = ft[:tail_count].to_i - if bl * tl == ft[:balloon_templates_attributes].size - flag = [] - bl.times do |i| - flag[i] = [] - tl.times do |j| - flag[i][j] = true - end - end - ft[:balloon_templates_attributes].each do |k, t| - flag[t[:size].to_i - 1][t[:tail].to_i - 1] = nil - end - if flag.flatten.compact.size == 0 - else - res = "invalid variation" - end - else - res = "invalid template size" - end - res - end - - public - # GET /speech_balloons - # GET /speech_balloons.json - def index - @speech_balloons = SpeechBalloon.all - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @speech_balloons } - end - end - - # GET /speech_balloons/1 - # GET /speech_balloons/1.json - def show - @speech_balloon = SpeechBalloon.find(params[:id], include: {:balloon_templates => :speech_templates}) - - respond_to do |format| - format.html # show.html.erb - format.json { - render :json => @speech_balloon.to_json(include: { - :balloon_templates => {:include => :speech_templates} - }) - } - format.jsonp { - render :json => "callback(" + @speech_balloon.to_json(include: { - :balloon_templates => {:include => :speech_templates} - }) + ")" - } - end - end + before_filter :authenticate_admin!, :only => [:list, :browse] def list @speech_balloons = SpeechBalloon.all @@ -79,52 +19,4 @@ class SpeechBalloonsController < ApplicationController end end - # POST /speech_balloons - # POST /speech_balloons.json - def create - @speech_balloon = SpeechBalloon.new(params[:speech_balloon]) - if em = validate_param(params[:speech_balloon]) - respond_to do |format| - format.json { render json: em, status: :unprocessable_entity } - end - else - respond_to do |format| - if @speech_balloon.save - format.html { redirect_to @speech_balloon, notice: 'Speech balloon was successfully created.' } - format.json { render json: @speech_balloon, status: :created, location: @speech_balloon } - else - format.html { render action: "new" } - format.json { render json: @speech_balloon.errors, status: :unprocessable_entity } - end - end - end - end - - # PUT /speech_balloons/1 - # PUT /speech_balloons/1.json - def update - @speech_balloon = SpeechBalloon.find(params[:id]) - - respond_to do |format| - if @speech_balloon.update_attributes(params[:speech_balloon]) - format.html { redirect_to @speech_balloon, notice: 'Speech balloon was successfully updated.' } - format.json { head :ok } - else - format.html { render action: "edit" } - format.json { render json: @speech_balloon.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /speech_balloons/1 - # DELETE /speech_balloons/1.json - def destroy - @speech_balloon = SpeechBalloon.find(params[:id]) - @speech_balloon.destroy - - respond_to do |format| - format.html { redirect_to speech_balloons_url } - format.json { head :ok } - end - end end diff --git a/app/models/color.rb b/app/models/color.rb index d09ae2c2..3144ad20 100644 --- a/app/models/color.rb +++ b/app/models/color.rb @@ -5,14 +5,15 @@ class Color < ActiveRecord::Base validates :code, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - def self.import filename - Color.import_file(filename) {|name, attr| Color.store(name, attr)} + def supply_default + self.name = 'no name' if self.name.blank? end - def self.store name, attr - r = Color.modify_object name, attr - r.save - r + def overwrite + end + + def visible? author + true end def self.default_page_size @@ -40,22 +41,46 @@ class Color < ActiveRecord::Base page_size end - def self.list opt = {}, page = 1, page_size = self.default_page_size - opt.merge!({:order => 'colors.t', :limit => page_size, :offset => (page -1) * page_size}) + def self.list page = 1, page_size = self.default_page_size + opt = {} + opt.merge!(Color.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:order => 'colors.t'}) Color.find(:all, opt) end def self.list_opt - {:include => {:ground_color => {:panel => {:author => {}}} }} + {} end def self.list_json_opt - {:include => {:ground_color => {:panel => {:author => {}}} }} + {} + end + + def self.show cid, au + opt = {} + opt.merge!(Color.show_opt) + res = Color.find(cid, opt) + raise ActiveRecord::Forbidden unless res.visible?(au) + res + end + + def self.show_opt + {} + end + + def self.show_json_opt + {} end - def self.show cid - c = Color.find(cid) - c + def self.import filename + Color.import_file(filename) {|name, attr| Color.store(name, attr)} + end + + def self.store name, attr + r = Color.modify_object name, attr + r.save + r end end diff --git a/app/models/comic.rb b/app/models/comic.rb index 6a1e92b8..107c0946 100644 --- a/app/models/comic.rb +++ b/app/models/comic.rb @@ -4,11 +4,7 @@ class Comic < ActiveRecord::Base belongs_to :author validates :title, :presence => true, :length => {:maximum => 100} - validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..3} - - before_save do |r| - r.supply_default - end + validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1} def supply_default self.visible = 0 if self.visible.blank? @@ -61,9 +57,11 @@ class Comic < ActiveRecord::Base page_size end - def self.list opt = {}, page = 1, page_size = self.default_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => ['visible > 0'], :order => 'updated_at desc', :limit => page_size, :offset => (page -1) * page_size}) + def self.list page = 1, page_size = self.default_page_size + opt = {} + opt.merge!(Comic.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => ['visible > 0'], :order => 'updated_at desc'}) Comic.find(:all, opt) end @@ -75,31 +73,35 @@ class Comic < ActiveRecord::Base {:include => {:stories => {:panel => {}}, :author => {}}} end - def self.mylist au, opt = {}, page = 1, comic_page_size = Author.default_comic_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => ['comics.author_id = ?', au.id], :order => 'comics.updated_at desc', :limit => page_size, :offset => (page -1) * comic_page_size}) + def self.mylist au, page = 1, page_size = Author.default_comic_page_size + opt = {} + opt.merge!(Comic.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => ['comics.author_id = ?', au.id], :order => 'comics.updated_at desc'}) Comic.find(:all, opt) end - def self.show cid, au, opt = {} - c = Comic.find(cid, :include => self.show_include_opt(opt)) - raise ActiveRecord::Forbidden unless c.visible?(au) - c + def self.show cid, au + opt = {} + opt.merge!(Comic.show_opt) + res = Comic.find(cid, opt) + raise ActiveRecord::Forbidden unless res.visible?(au) + res end - def self.edit cid, au, opt = {} - c = Comic.find(cid, :include => self.show_include_opt(opt)) - raise ActiveRecord::Forbidden unless c.own?(au) - c + def self.edit cid, au + opt = {} + opt.merge!(Comic.show_opt) + res = Comic.find(cid, opt) + raise ActiveRecord::Forbidden unless res.own?(au) + res end - def self.show_include_opt opt = {} - res = {:stories => {:panel => {}}, :author => {}} - res.push(opt[:include]) if opt[:include] - res + def self.show_opt + {:include => {:stories => {:panel => {}}, :author => {}}} end - def self.show_json_include_opt + def self.show_json_opt {:include => {:stories => {:panel => {}}, :author => {}}} end diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb index c8af47ed..95568a3e 100644 --- a/app/models/ground_color.rb +++ b/app/models/ground_color.rb @@ -6,6 +6,12 @@ class GroundColor < ActiveRecord::Base validates :color_id, :numericality => true, :existence => true validates :z, :presence => true, :numericality => {:greater_than => 0} + def supply_default + end + + def overwrite + end + def self.default_page_size 25 end @@ -27,17 +33,11 @@ class GroundColor < ActiveRecord::Base page_size end - def self.offset cnt, prm = nil - offset = prm.to_i - offset = cnt - 1 if offset >= cnt - offset = cnt - offset.abs if offset < 0 - offset = 0 if offset < 0 - offset - end - - def self.list opt = {}, page = 1, page_size = self.default_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => 'panels.publish > 0', :order => 'ground_colors.updated_at desc', :limit => page_size, :offset => (page -1) * page_size}) + def self.list page = 1, page_size = self.default_page_size + opt = {} + opt.merge!(GroundColor.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => 'panels.publish > 0', :order => 'ground_colors.updated_at desc'}) GroundColor.find(:all, opt) end @@ -49,9 +49,11 @@ class GroundColor < ActiveRecord::Base {:include => {:panel => {:author => {}}, :color => {} }} end - def self.mylist au, opt = {}, page = 1, ground_color_page_size = Author.default_ground_color_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'ground_colors.updated_at desc', :limit => page_size, :offset => (page -1) * ground_color_page_size}) + def self.mylist au, page = 1, page_size = Author.default_ground_color_page_size + opt = {} + opt.merge!(self.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'ground_colors.updated_at desc'}) GroundColor.find(:all, opt) end diff --git a/app/models/ground_picture.rb b/app/models/ground_picture.rb index 207b2083..c98e9dd3 100644 --- a/app/models/ground_picture.rb +++ b/app/models/ground_picture.rb @@ -6,6 +6,12 @@ class GroundPicture < ActiveRecord::Base validates :picture_id, :numericality => true, :existence => true validates :z, :presence => true, :numericality => {:greater_than => 0} + def supply_default + end + + def overwrite + end + def self.default_page_size 25 end @@ -27,17 +33,11 @@ class GroundPicture < ActiveRecord::Base page_size end - def self.offset cnt, prm = nil - offset = prm.to_i - offset = cnt - 1 if offset >= cnt - offset = cnt - offset.abs if offset < 0 - offset = 0 if offset < 0 - offset - end - - def self.list opt = {}, page = 1, page_size = self.default_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => 'panels.publish > 0', :order => 'ground_pictures.updated_at desc', :limit => page_size, :offset => (page -1) * page_size}) + def self.list page = 1, page_size = self.default_page_size + opt = {} + opt.merge!(GroundPicture.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => 'panels.publish > 0', :order => 'ground_pictures.updated_at desc'}) GroundPicture.find(:all, opt) end @@ -49,9 +49,11 @@ class GroundPicture < ActiveRecord::Base {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}} end - def self.mylist au, opt = {}, page = 1, ground_picture_page_size = Author.default_ground_picture_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'ground_pictures.updated_at desc', :limit => page_size, :offset => (page -1) * ground_picture_page_size}) + def self.mylist au, page = 1, page_size = Author.default_ground_picture_page_size + opt = {} + opt.merge!(self.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'ground_pictures.updated_at desc'}) GroundPicture.find(:all, opt) end diff --git a/app/models/license.rb b/app/models/license.rb index 704e3489..9a0fcb6d 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -9,30 +9,15 @@ class License < ActiveRecord::Base validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => true #{:allow_blank => true} validates :system_picture_id, :presence => true, :numericality => true, :existence => true - def self.store name, attr - r = License.replace_system_picture attr - l = License.modify_object name, attr - if r == false - l.errors.add :base, 'system picture can not create' - else - l.save - end - l + def supply_default end - def self.stores attrs, lg_id - res = 0 - return 0 unless attrs.is_a?(Hash) - attrs.each do |name, attr| - attr["license_group_id"] = lg_id - l = License.store name, attr - res += 1 unless l.valid? - end - res + def overwrite end - def self.list opt = {} - opt.merge!(self.list_opt) unless opt[:include] + def self.list + opt = {} + opt.merge!(License.list_opt) opt.merge!({:order => 'name'}) License.find(:all, opt) end @@ -45,20 +30,42 @@ class License < ActiveRecord::Base {:include => {:license_group => {}}} end - def self.show rid, opt = {} - r = License.find(rid, :include => self.show_include_opt(opt)) -# raise ActiveRecord::Forbidden unless c.visible?(au) - r + def self.show rid + opt = {} + opt.merge!(License.show_opt) + res = License.find(rid, opt) +# raise ActiveRecord::Forbidden unless res.visible?(au) + res end - def self.show_include_opt opt = {} - res = [:license_group] - res.push(opt[:include]) if opt[:include] - res + def self.show_opt + {:include => {:license_group => {}}} end - def self.show_json_include_opt + def self.show_json_opt {:include => {:license_group => {}}} end + def self.store name, attr + r = License.replace_system_picture attr + l = License.modify_object name, attr + if r == false + l.errors.add :base, 'system picture can not create' + else + l.save + end + l + end + + def self.stores attrs, lg_id + res = 0 + return 0 unless attrs.is_a?(Hash) + attrs.each do |name, attr| + attr["license_group_id"] = lg_id + l = License.store name, attr + res += 1 unless l.valid? + end + res + end + end diff --git a/app/models/license_group.rb b/app/models/license_group.rb index 7d7f13df..188b7a23 100644 --- a/app/models/license_group.rb +++ b/app/models/license_group.rb @@ -7,26 +7,15 @@ class LicenseGroup < ActiveRecord::Base validates :caption, :presence => true, :length => {:maximum => 30} validates :url, :presence => true, :length => {:maximum => 200}, :url => true - def self.store name, attr - #ライセンスデータがあるとライセンスグループのデータ生成で邪魔するので移しておく - lattr = attr["licenses_attributes"] - attr.delete "licenses_attributes" - #ライセンスグループを先に保存してidを決める - r = LicenseGroup.modify_object name, attr - r.save - #取っておいたライセンスデータとidでライセンス作成 - if (c = License.stores(lattr, r.id)) > 0 - r.errors.add :base, 'licenses can not create' - end - r + def supply_default end - def self.import filename - LicenseGroup.import_file(filename) {|name, attr| LicenseGroup.store(name, attr)} + def overwrite end - def self.list opt = {} - opt.merge!(self.list_opt) unless opt[:include] + def self.list + opt = {} + opt.merge!(self.list_opt) opt.merge!({:order => 'license_groups.name asc'}) LicenseGroup.find(:all, opt) end @@ -39,22 +28,40 @@ class LicenseGroup < ActiveRecord::Base {:include => {:licenses => {}}} end - def self.show rid, opt = {} - r = LicenseGroup.find(rid, :include => self.show_include_opt(opt)) -# raise ActiveRecord::Forbidden unless c.visible?(au) - r + def self.show rid + opt = {} + opt.merge!(self.show_opt) + res = LicenseGroup.find(rid, opt) +# raise ActiveRecord::Forbidden unless res.visible?(au) + res end - def self.show_include_opt opt = {} - res = {:licenses => {}} - res.push(opt[:include]) if opt[:include] - res + def self.show_opt + {:include => {:licenses => {}}} end - def self.show_json_include_opt + def self.show_json_opt {:include => {:licenses => {}}} end + def self.store name, attr + #ライセンスデータがあるとライセンスグループのデータ生成で邪魔するので移しておく + lattr = attr["licenses_attributes"] + attr.delete "licenses_attributes" + #ライセンスグループを先に保存してidを決める + r = LicenseGroup.modify_object name, attr + r.save + #取っておいたライセンスデータとidでライセンス作成 + if (c = License.stores(lattr, r.id)) > 0 + r.errors.add :base, 'licenses can not create' + end + r + end + + def self.import filename + LicenseGroup.import_file(filename) {|name, attr| LicenseGroup.store(name, attr)} + end + def self.disp_import_error r if r == false puts "json file error. file does not exist or broken" diff --git a/app/models/original_picture.rb b/app/models/original_picture.rb index 497fa646..307418c5 100644 --- a/app/models/original_picture.rb +++ b/app/models/original_picture.rb @@ -9,16 +9,44 @@ class OriginalPicture < ActiveRecord::Base validates :height, :presence => true, :numericality => true, :natural_number => true validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true validates :artist_id, :presence => true, :numericality => true, :existence => true - validates :md5, :presence => true, :length => {:maximum => 32} + validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32} before_destroy :destroy_with_file - def supply_default art + def supply_default end - def overwrite art - return false unless art - self.artist_id = art.id + def overwrite ar + self.artist_id = ar.id + end + + def own? ar + self.artist_id == ar.id + end + + def visible? ar + self.own?(ar) + end + + def dext + self.ext.downcase + end + + def filename + "#{self.id}.#{self.dext}" + end + + def mime_type + "image/#{self.dext}" + end + + def url + '/original_pictures/' + filename + end + + def opt_img_tag + tw, th = ResourcePicture.fix_size_both(MagicNumber['thumbnail_width'], MagicNumber['thumbnail_height'], self.width, self.height) + {:src => self.url, :width => tw, :height => th} end def self.default_page_size @@ -42,11 +70,11 @@ class OriginalPicture < ActiveRecord::Base page_size end - def self.list artist_id, opt = {}, page = 1, page_size = self.default_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => ['artist_id = ?', artist_id], - :order => 'updated_at desc', :limit => page_size, :offset => (page -1) * page_size} - ) + def self.mylist artist_id, page = 1, page_size = self.default_page_size + opt = {} + opt.merge!(self.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => ['original_pictures.artist_id = ?', artist_id], :order => 'original_pictures.updated_at desc'}) OriginalPicture.find(:all, opt) end @@ -62,23 +90,27 @@ class OriginalPicture < ActiveRecord::Base {:include => {:resource_picture => {}, :pictures => {}}} end - def self.show cid, artist, opt = {} - pic = OriginalPicture.find(cid, self.show_include_opt) - raise ActiveRecord::Forbidden unless pic.own?(artist) - pic + def self.show cid, ar + opt = {} + opt.merge!(self.show_opt) + res = OriginalPicture.find(cid, opt) + raise ActiveRecord::Forbidden unless res.visible?(ar) + res end - def self.edit cid, artist, opt = {} - pic = OriginalPicture.find(cid, self.show_include_opt) - raise ActiveRecord::Forbidden unless pic.own?(artist) - pic + def self.edit cid, ar + opt = {} + opt.merge!(self.show_opt) + res = OriginalPicture.find(cid, opt) + raise ActiveRecord::Forbidden unless res.own?(ar) + res end - def self.show_include_opt + def self.show_opt {:include => {:resource_picture => {}, :pictures => {}}} end - def self.show_json_include_opt + def self.show_json_opt {:include => {:resource_picture => {}, :pictures => {}}} end @@ -87,27 +119,6 @@ class OriginalPicture < ActiveRecord::Base self.resource_picture.destroy end - def dext - self.ext.downcase - end - - def filename - "#{self.id}.#{self.dext}" - end - - def mime_type - "image/#{self.dext}" - end - - def url - '/original_pictures/' + filename - end - - def opt_img_tag - tw, th = ResourcePicture.fix_size_both(MagicNumber['thumbnail_width'], MagicNumber['thumbnail_height'], self.width, self.height) - {:src => self.url, :width => tw, :height => th} - end - def data_to_mgk picture_data begin mgk = Magick::Image.from_blob(picture_data).shift @@ -144,9 +155,4 @@ class OriginalPicture < ActiveRecord::Base PictureIO.original_picture_io.get self.filename, subdir end - def own? art - return false unless art - self.artist_id == art.id - end - end diff --git a/app/models/panel_color.rb b/app/models/panel_color.rb index 820a541f..deb29312 100644 --- a/app/models/panel_color.rb +++ b/app/models/panel_color.rb @@ -5,6 +5,12 @@ class PanelColor < ActiveRecord::Base validates :z, :presence => true, :numericality => {:greater_than => 0} validates :code, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000} + def supply_default + end + + def overwrite + end + def self.default_page_size 25 end @@ -26,17 +32,11 @@ class PanelColor < ActiveRecord::Base page_size end - def self.offset cnt, prm = nil - offset = prm.to_i - offset = cnt - 1 if offset >= cnt - offset = cnt - offset.abs if offset < 0 - offset = 0 if offset < 0 - offset - end - - def self.list opt = {}, page = 1, page_size = self.default_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => 'panels.publish > 0', :order => 'panel_colors.updated_at desc', :limit => page_size, :offset => (page -1) * page_size}) + def self.list page = 1, page_size = self.default_page_size + opt = {} + opt.merge!(PanelColor.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => 'panels.publish > 0', :order => 'panel_colors.updated_at desc'}) PanelColor.find(:all, opt) end @@ -48,9 +48,11 @@ class PanelColor < ActiveRecord::Base {:include => {:panel => {:author => {}} }} end - def self.mylist au, opt = {}, page = 1, panel_color_page_size = Author.default_panel_color_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'panel_colors.updated_at desc', :limit => page_size, :offset => (page -1) * panel_color_page_size}) + def self.mylist au, page = 1, page_size = Author.default_panel_color_page_size + opt = {} + opt.merge!(PanelColor.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'panel_colors.updated_at desc'}) PanelColor.find(:all, opt) end diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index afbe97f1..772f9a09 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -4,7 +4,7 @@ class PanelPicture < ActiveRecord::Base validates :panel_id, :numericality => {:allow_blank => true} validates :picture_id, :numericality => true, :existence => true - validates :link, :length => {:maximum => 200} + validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true} validates :x, :presence => true, :numericality => true validates :y, :presence => true, :numericality => true validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :resize => true, :sync_vh => true @@ -47,17 +47,11 @@ class PanelPicture < ActiveRecord::Base page_size end - def self.offset cnt, prm = nil - offset = prm.to_i - offset = cnt - 1 if offset >= cnt - offset = cnt - offset.abs if offset < 0 - offset = 0 if offset < 0 - offset - end - - def self.list opt = {}, page = 1, page_size = self.default_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => 'panels.publish > 0', :order => 'panel_pictures.updated_at desc', :limit => page_size, :offset => (page -1) * page_size}) + def self.list page = 1, page_size = self.default_page_size + opt = {} + opt.merge!(PanelPicture.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => 'panels.publish > 0', :order => 'panel_pictures.updated_at desc'}) PanelPicture.find(:all, opt) end @@ -69,9 +63,11 @@ class PanelPicture < ActiveRecord::Base {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}} end - def self.mylist au, opt = {}, page = 1, panel_picture_page_size = Author.default_panel_picture_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'panel_pictures.updated_at desc', :limit => page_size, :offset => (page -1) * panel_picture_page_size}) + def self.mylist au, page = 1, page_size = Author.default_panel_picture_page_size + opt = {} + opt.merge!(PanelPicture.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'panel_pictures.updated_at desc'}) PanelPicture.find(:all, opt) end diff --git a/app/models/speech_balloon.rb b/app/models/speech_balloon.rb index 05b280ba..7103ea2e 100644 --- a/app/models/speech_balloon.rb +++ b/app/models/speech_balloon.rb @@ -14,10 +14,4 @@ class SpeechBalloon < ActiveRecord::Base validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} # validates :settings, :presence => true - before_create :supply_t - - def supply_t - self.t = SpeechBalloon.maximum(:t).to_i + 1 - end - end diff --git a/spec/controllers/artists_controller_spec.rb b/spec/controllers/artists_controller_spec.rb index 88babc0f..a2e1a328 100644 --- a/spec/controllers/artists_controller_spec.rb +++ b/spec/controllers/artists_controller_spec.rb @@ -254,6 +254,10 @@ describe ArtistsController do get :new, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it '絵師モデルにjson単体出力オプションを問い合わせている' do + Artist.should_receive(:show_json_opt).exactly(1) + get :new, :format => :json + end end end context '作家権限がないとき' do @@ -298,11 +302,25 @@ describe ArtistsController do sign_in @user @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken') end - context 'つつがなく終わるとき' do + context '事前チェックしておく' do + it '絵師モデルにデフォルト値補充を依頼している' do + Artist.any_instance.should_receive(:supply_default).exactly(1) + post :create, :artist => @attr + end + it '絵師モデルにカラム値復元を依頼している' do + Artist.any_instance.should_receive(:attributes=).exactly(1) + post :create, :artist => @attr + end + it '絵師モデルに上書き補充を依頼している' do + Artist.any_instance.should_receive(:overwrite).exactly(1) + post :create, :artist => @attr + end it 'モデルに保存依頼する' do Artist.any_instance.should_receive(:save).exactly(1) post :create, :artist => @attr end + end + context 'つつがなく終わるとき' do it "@artistに作成された絵師を保持していて、それがDBにある" do post :create, :artist => @attr assigns(:artist).should be_a(Artist) @@ -330,6 +348,10 @@ describe ArtistsController do post :create, :artist => @attr, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it '絵師モデルにjson単体出力オプションを問い合わせている' do + Artist.should_receive(:show_json_opt).exactly(1) + post :create, :artist => @attr, :format => :json + end it 'データがアレになっている' do post :create, :artist => @attr, :format => :json json = JSON.parse response.body @@ -462,6 +484,14 @@ describe ArtistsController do Artist.should_receive(:edit).exactly(1) put :update, :id => @artist.id, :artist => @attr end + it '絵師モデルにカラム値復元を依頼している' do + Artist.any_instance.should_receive(:attributes=).exactly(1) + put :update, :id => @artist.id, :artist => @attr + end + it '絵師モデルに上書き補充を依頼している' do + Artist.any_instance.should_receive(:overwrite).exactly(1) + put :update, :id => @artist.id, :artist => @attr + end it 'モデルに更新を依頼する' do Artist.any_instance.stub(:save).with(any_args).and_return true Artist.any_instance.should_receive(:save).exactly(1) diff --git a/spec/controllers/colors_controller_spec.rb b/spec/controllers/colors_controller_spec.rb index c0a301ef..40ad6410 100644 --- a/spec/controllers/colors_controller_spec.rb +++ b/spec/controllers/colors_controller_spec.rb @@ -67,6 +67,10 @@ describe ColorsController do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it '色マスターモデルにjson一覧出力オプションを問い合わせている' do + Color.should_receive(:list_json_opt).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body diff --git a/spec/controllers/comics_controller_spec.rb b/spec/controllers/comics_controller_spec.rb index 5d2f639a..37b885e0 100644 --- a/spec/controllers/comics_controller_spec.rb +++ b/spec/controllers/comics_controller_spec.rb @@ -1,5 +1,6 @@ # -*- encoding: utf-8 -*- require 'spec_helper' +#コミック describe ComicsController do before do @@ -67,6 +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 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body @@ -76,6 +81,7 @@ describe ComicsController do get :index, :format => :json json = JSON.parse response.body json.first.has_key?("title").should be_true + json.first.has_key?("visible").should be_true end end end @@ -136,10 +142,15 @@ 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 'データがアレになっている' do get :show, :id => @comic.id, :format => :json json = JSON.parse response.body json["title"].should match(/normal/) + json["visible"].should_not be_nil end end end @@ -260,6 +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 end context '作家権限がないとき' do before do @@ -293,11 +314,25 @@ describe ComicsController do sign_in @user @attr = FactoryGirl.attributes_for(:comic, :author_id => @author.id, :title => 'normal') end - context 'つつがなく終わるとき' do + context '事前チェックしておく' do + it 'コミックモデルにデフォルト値補充を依頼している' do + Comic.any_instance.should_receive(:supply_default).exactly(1) + post :create, :artist => @attr + end + it 'コミックモデルにカラム値復元を依頼している' do + Comic.any_instance.should_receive(:attributes=).exactly(1) + post :create, :artist => @attr + end + it 'コミックモデルに上書き補充を依頼している' do + Comic.any_instance.should_receive(:overwrite).exactly(1) + post :create, :artist => @attr + end it 'モデルに保存依頼する' do Comic.any_instance.should_receive(:save).exactly(1) - post :create, :comic => @attr + post :create, :artist => @attr end + end + context 'つつがなく終わるとき' do it "@comicに作成されたコミックを保持していて、それがDBにある" do post :create, :comic => @attr assigns(:comic).should be_a(Comic) @@ -329,6 +364,7 @@ describe ComicsController do post :create, :comic => @attr, :format => :json json = JSON.parse response.body json["title"].should match(/normal/) + json["visible"].should_not be_nil end end end @@ -362,26 +398,26 @@ describe ComicsController do Comic.any_instance.stub(:save).and_return(false) end it "未保存のコミックを保持している" do - post :create, :comic => {} + post :create, :comic => @attr assigns(:comic).should be_a_new(Comic) end context 'html形式' do it 'ステータスコード200 OKを返す' do - post :create, :comic => {} + post :create, :comic => @attr response.status.should eq 200 end it '新規ページを描画する' do - post :create, :comic => {} + post :create, :comic => @attr response.should render_template("new") end end context 'json形式' do it 'ステータスコード422 unprocessable_entity を返す' do - post :create, :comic => {}, :format => :json + post :create, :comic => @attr, :format => :json response.status.should eq 422 end it '応答メッセージUnprocessable Entityを返す' do - post :create, :comic => {}, :format => :json + post :create, :comic => @attr, :format => :json response.message.should match(/Unprocessable/) end end @@ -459,6 +495,14 @@ describe ComicsController do Comic.should_receive(:edit).exactly(1) put :update, :id => @comic.id, :comic => @attr end + it 'コミックモデルにカラム値復元を依頼している' do + Comic.any_instance.should_receive(:attributes=).exactly(1) + put :update, :id => @comic.id, :comic => @attr + end + it 'コミックモデルに上書き補充を依頼している' do + Comic.any_instance.should_receive(:overwrite).exactly(1) + put :update, :id => @comic.id, :comic => @attr + end it 'モデルに更新を依頼する' do Comic.any_instance.stub(:save).with(any_args).and_return true Comic.any_instance.should_receive(:save).exactly(1) diff --git a/spec/controllers/ground_colors_controller_spec.rb b/spec/controllers/ground_colors_controller_spec.rb index 8d40002a..ecbc9bcc 100644 --- a/spec/controllers/ground_colors_controller_spec.rb +++ b/spec/controllers/ground_colors_controller_spec.rb @@ -71,6 +71,10 @@ describe GroundColorsController do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it '間接背景モデルにjson一覧出力オプションを問い合わせている' do + GroundColor.should_receive(:list_json_opt).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body @@ -79,7 +83,7 @@ describe GroundColorsController do it 'リストの先頭くらいは間接背景っぽいものであって欲しい' do get :index, :format => :json json = JSON.parse response.body - json.first.has_key?("panel").should be_true + json.first.has_key?("panel_id").should be_true json.first.has_key?("color_id").should be_true json.first.has_key?("z").should be_true end diff --git a/spec/controllers/license_groups_controller_spec.rb b/spec/controllers/license_groups_controller_spec.rb index 63e42f7a..05da3ade 100644 --- a/spec/controllers/license_groups_controller_spec.rb +++ b/spec/controllers/license_groups_controller_spec.rb @@ -21,7 +21,7 @@ describe LicenseGroupsController do get :index response.should be_success end - it 'ライセンスモデルに一覧を問い合わせている' do + it 'ライセンスグループモデルに一覧を問い合わせている' do LicenseGroup.should_receive(:list).exactly(1) get :index end @@ -40,6 +40,10 @@ describe LicenseGroupsController do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'ライセンスグループモデルにjson一覧出力オプションを問い合わせている' do + LicenseGroup.should_receive(:list_json_opt).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body @@ -95,10 +99,17 @@ describe LicenseGroupsController do get :show, :id => @lg.id, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'ライセンスグループモデルにjson単体出力オプションを問い合わせている' do + LicenseGroup.should_receive(:show_json_opt).exactly(1) + get :show, :id => @lg.id, :format => :json + end it 'データがアレになっている' do get :show, :id => @lg.id, :format => :json json = JSON.parse response.body json["name"].should match(/peta/) + json["classname"].should_not be_nil + json["caption"].should_not be_nil + json["url"].should_not be_nil end end end diff --git a/spec/controllers/licenses_controller_spec.rb b/spec/controllers/licenses_controller_spec.rb index 7ab36081..0627afb7 100644 --- a/spec/controllers/licenses_controller_spec.rb +++ b/spec/controllers/licenses_controller_spec.rb @@ -42,6 +42,10 @@ describe LicensesController do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'ライセンスモデルにjson一覧出力オプションを問い合わせている' do + License.should_receive(:list_json_opt).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body @@ -50,6 +54,8 @@ describe LicensesController do it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do get :index, :format => :json json = JSON.parse response.body + json.first.has_key?("name").should be_true + json.first.has_key?("caption").should be_true json.first.has_key?("url").should be_true end end @@ -95,10 +101,16 @@ describe LicensesController do get :show, :id => @l.id, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'ライセンスモデルにjson単体出力オプションを問い合わせている' do + License.should_receive(:show_json_opt).exactly(1) + get :show, :id => @l.id, :format => :json + end it 'データがアレになっている' do get :show, :id => @l.id, :format => :json json = JSON.parse response.body json["name"].should match(/peta/) + json["caption"].should_not be_nil + json["url"].should_not be_nil end end end diff --git a/spec/controllers/original_pictures_controller_spec.rb b/spec/controllers/original_pictures_controller_spec.rb index 351ffd9d..5bc98f5d 100644 --- a/spec/controllers/original_pictures_controller_spec.rb +++ b/spec/controllers/original_pictures_controller_spec.rb @@ -17,7 +17,7 @@ describe OriginalPicturesController do before do @op = FactoryGirl.create :original_picture, :artist_id => @artist.id sign_in @user - OriginalPicture.stub(:list).and_return([@op, @op, @op]) + OriginalPicture.stub(:mylist).and_return([@op, @op, @op]) end context 'パラメータpageについて' do it '@pageに値が入る' do @@ -50,8 +50,8 @@ describe OriginalPicturesController do get :index response.should be_success end - it '原画モデルに一覧を問い合わせている' do - OriginalPicture.should_receive(:list).exactly(1) + it '原画モデルにマイリストを問い合わせている' do + OriginalPicture.should_receive(:mylist).exactly(1) get :index end it '@original_picturesにリストを取得している' do @@ -69,6 +69,10 @@ describe OriginalPicturesController do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it '原画モデルにjson一覧出力オプションを問い合わせている' do + OriginalPicture.should_receive(:list_json_opt).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body @@ -78,6 +82,9 @@ describe OriginalPicturesController do get :index, :format => :json json = JSON.parse response.body json.first.has_key?("ext").should be_true + json.first.has_key?("md5").should be_true + json.first.has_key?("artist_id").should be_true + json.first.has_key?("width").should be_true end end end @@ -174,6 +181,10 @@ describe OriginalPicturesController do OriginalPicture.any_instance.should_receive(:restore).exactly(1) get :show, :id => @pic.id, :format => :png end + it '画像モデルにMimeTypeを問い合わせる' do + OriginalPicture.any_instance.should_receive(:mime_type).exactly(1) + get :show, :id => @pic.id, :format => :png + end it '画像を送信する' do OriginalPicture.any_instance.stub(:restore).and_return('aaa') get :show, :id => @pic.id, :format => :png @@ -185,6 +196,10 @@ describe OriginalPicturesController do OriginalPicture.any_instance.should_receive(:restore).exactly(1) get :show, :id => @pic.id, :format => :gif end + it '画像モデルにMimeTypeを問い合わせる' do + OriginalPicture.any_instance.should_receive(:mime_type).exactly(1) + get :show, :id => @pic.id, :format => :gif + end it '画像を送信する' do OriginalPicture.any_instance.stub(:restore).and_return('bbb') get :show, :id => @pic.id, :format => :gif @@ -196,6 +211,10 @@ describe OriginalPicturesController do OriginalPicture.any_instance.should_receive(:restore).exactly(1) get :show, :id => @pic.id, :format => :jpeg end + it '画像モデルにMimeTypeを問い合わせる' do + OriginalPicture.any_instance.should_receive(:mime_type).exactly(1) + get :show, :id => @pic.id, :format => :jpeg + end it '画像を送信する' do OriginalPicture.any_instance.stub(:restore).and_return('ccc') get :show, :id => @pic.id, :format => :jpeg @@ -421,6 +440,16 @@ describe OriginalPicturesController do end 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 + OriginalPicture.should_receive(:show_json_opt).exactly(1) + get :new, :format => :json + end + end context '作家権限がないとき' do before do sign_out @user @@ -470,6 +499,13 @@ describe OriginalPicturesController do response.should render_template("artists/new") end end + context 'json形式' do + it '例外403 forbiddenを返す' do + lambda{ + get :new, :format => :json + }.should raise_error(ActiveRecord::Forbidden) + end + end end end diff --git a/spec/controllers/panel_colors_controller_spec.rb b/spec/controllers/panel_colors_controller_spec.rb index 102009d1..285d2f48 100644 --- a/spec/controllers/panel_colors_controller_spec.rb +++ b/spec/controllers/panel_colors_controller_spec.rb @@ -70,6 +70,10 @@ describe PanelColorsController do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'コマの色背景モデルにjson一覧出力オプションを問い合わせている' do + PanelColor.should_receive(:list_json_opt).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body diff --git a/spec/controllers/panel_pictures_controller_spec.rb b/spec/controllers/panel_pictures_controller_spec.rb index e020153e..69860659 100644 --- a/spec/controllers/panel_pictures_controller_spec.rb +++ b/spec/controllers/panel_pictures_controller_spec.rb @@ -74,6 +74,10 @@ describe PanelPicturesController do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do + PanelPicture.should_receive(:list_json_opt).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body @@ -83,6 +87,8 @@ describe PanelPicturesController do get :index, :format => :json json = JSON.parse response.body json.first.has_key?("link").should be_true + json.first.has_key?("x").should be_true + json.first.has_key?("y").should be_true end end end diff --git a/spec/factories.rb b/spec/factories.rb index ff13301b..384ef68f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -60,7 +60,7 @@ FactoryGirl.define do factory :comic, :class => Comic do |comic| comic.title "comic" - comic.visible 3 + comic.visible 1 end factory :original_picture, :class => OriginalPicture do |op| diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb index 4557d512..981102c1 100644 --- a/spec/models/author_spec.rb +++ b/spec/models/author_spec.rb @@ -20,7 +20,6 @@ describe Author do end it '上限データが通る' do @author.name = 'a'*30 - @author.save! @author.should be_valid end end diff --git a/spec/models/balloon_spec.rb b/spec/models/balloon_spec.rb index 9f30e693..a7317f99 100644 --- a/spec/models/balloon_spec.rb +++ b/spec/models/balloon_spec.rb @@ -16,17 +16,26 @@ describe Balloon do describe '検証に於いて' do before do - end - - it 'オーソドックスなデータなら通る' do @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id - @balloon.should be_valid end - + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @balloon.x = 0 + @balloon.y = 0 + @balloon.width = 1 + @balloon.height = 1 + @balloon.should be_valid + end + it '上限データが通る' do + @balloon.x = 99999 + @balloon.y = 99999 + @balloon.width = 99999 + @balloon.height = 99999 + @balloon.should be_valid + end + end + context 'speech_balloon_idを検証するとき' do - before do - @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id - end #ネストの保存はnilを許可しなければならないので数値チェックだけ it 'テストデータの確認' do @balloon.speech_balloon_id = @speech_balloon.id @@ -38,13 +47,6 @@ describe Balloon do end end context 'system_picture_idを検証するとき' do - before do - @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id - end - it 'テストデータの確認' do - @balloon.system_picture_id = @system_picture.id - @balloon.should be_valid - end it 'nullなら失敗する' do @balloon.system_picture_id = nil @balloon.should_not be_valid @@ -59,13 +61,6 @@ describe Balloon do end end context 'xを検証するとき' do - before do - @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id - end - it 'テストデータの確認' do - @balloon.x = '1' - @balloon.should be_valid - end it 'nullなら失敗する' do @balloon.x = nil @balloon.should_not be_valid @@ -84,13 +79,6 @@ describe Balloon do end end context 'yを検証するとき' do - before do - @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id - end - it 'テストデータの確認' do - @balloon.y = '1' - @balloon.should be_valid - end it 'nullなら失敗する' do @balloon.y = nil @balloon.should_not be_valid @@ -109,13 +97,6 @@ describe Balloon do end end context 'widthを検証するとき' do - before do - @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id - end - it 'テストデータの確認' do - @balloon.width = 1 - @balloon.should be_valid - end it 'nullなら失敗する' do @balloon.width = nil @balloon.should_not be_valid @@ -134,13 +115,6 @@ describe Balloon do end end context 'heightを検証するとき' do - before do - @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id - end - it 'テストデータの確認' do - @balloon.height = '1' - @balloon.should be_valid - end it 'nullなら失敗する' do @balloon.height = nil @balloon.should_not be_valid @@ -159,20 +133,7 @@ describe Balloon do end end context 'settingsを検証するとき' do - before do - @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id - end - it 'テストデータの確認' do - @balloon.settings = '' - @balloon.should be_valid - end - end - end - - describe 'データ補充に於いて' do - before do end - end end diff --git a/spec/models/color_spec.rb b/spec/models/color_spec.rb index bbb61261..5397f1f6 100644 --- a/spec/models/color_spec.rb +++ b/spec/models/color_spec.rb @@ -20,21 +20,25 @@ describe Color do describe '検証に於いて' do before do - end - - it 'オーソドックスなデータなら通る' do @c = FactoryGirl.build :color - @c.should be_valid end - context 'nameを検証するとき' do - before do - @c = FactoryGirl.build :color + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @c.name = 'a' + @c.code = 0 + @c.t = 0 + @c.should be_valid end - it 'テストデータの確認' do - @c.name = 'a'*50 + it '上限データが通る' do + @author.name = 'a'*30 + @c.code = 0xffffff + @c.t = 99999 @c.should be_valid end + end + + context 'nameを検証するとき' do it 'nullなら失敗する' do @c.name = '' @c.should_not be_valid @@ -49,13 +53,6 @@ describe Color do end end context 'codeを検証するとき' do - before do - @c = FactoryGirl.build :color - end - it 'テストデータの確認' do - @c.code = 0xffffff - @c.should be_valid - end it 'nullなら失敗する' do @c.code = nil @c.should_not be_valid @@ -74,13 +71,6 @@ describe Color do end end context 'tを検証するとき' do - before do - @c = FactoryGirl.build :color - end - it 'テストデータの確認' do - @c.t = '1' - @c.should be_valid - end it '数値でなければ失敗する' do @c.t = 'a' @c.should_not be_valid @@ -96,68 +86,36 @@ describe Color do end end - describe 'インポートに於いて' do - before do - end - context 'つつがなく終わるとき' do - it 'ファイルインポートを依頼する' do - Color.should_receive(:import_file).with(any_args).exactly(1) - Color.stub(:import_file).with(any_args).and_return([]) - Color.import(@f) - end - it '色更新を一回依頼する' do - Color.stub(:store).with(any_args).and_return(Color.new) - Color.should_receive(:store).with(any_args).exactly(1) - Color.import(@f) - end - it '色が追加される' do - lambda { - Color.import(@f) - }.should change Color, :count - end - it '[]を返す' do - r = Color.import(@f) - r.should eq [] - end + describe 'デフォルト値補充に於いて' do + it '名前がno nameになっている' do + @c = FactoryGirl.build :color, :name => nil + @c.supply_default + @c.name.should eq 'no name' end - context '複数データがつつがなく終わるとき' do - it '色更新を二回依頼する' do - Color.stub(:store).with(any_args).and_return(Color.new) - Color.should_receive(:store).with(any_args).exactly(2) - Color.import(@fs) - end - it '色が二個追加される' do - lambda { - r = Color.import(@fs) - }.should change(Color, :count).by 2 - end - it '[]を返す' do - r = Color.import(@fs) - r.should eq [] - end + end + + describe '上書き補充に於いて' do + it 'defined' do + @c = FactoryGirl.build :color + @c.overwrite end end - describe '単体取得に於いて' do + describe '上書き補充に於いて' do + end + + describe '閲覧許可に於いて' do before do - @c = FactoryGirl.create :color - end - it '指定の色を返す' do - c = Color.show @c.id - c.should eq @c - end - context '存在しない色を開こうとしたとき' do - it '404RecordNotFound例外を返す' do - lambda{ - Color.show 110 - }.should raise_error(ActiveRecord::RecordNotFound) - end + @c = FactoryGirl.build :color end + it '許可する' do + @c.visible?(@author).should == true + end end describe '一覧取得に於いて' do before do - @color = FactoryGirl.create :color + @c = FactoryGirl.create :color end context 'page補正について' do it '文字列から数値に変換される' do @@ -184,39 +142,167 @@ describe Color do Color.page_size('1000').should eq Color.max_page_size end end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + Color.stub(:list_opt).with(any_args).and_return({}) + Color.should_receive(:list_opt).with(any_args).exactly(1) + r = Color.list + end + end it 'リストを返す' do - cl = Color.list - cl.should eq [@color] + r = Color.list + r.should eq [@c] end it 'tで並んでいる' do - ncl = FactoryGirl.create :color, :t => 1, :name => 'name a' - cl = Color.list - cl.should eq [@color, ncl] + n = FactoryGirl.create :color, :name => 'new color', :t => 1 + l = Color.list + l.should eq [@c, n] end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do - @nc2 = FactoryGirl.create :color, :t => 1, :name => 'name a' - @nc3 = FactoryGirl.create :color, :t => 3, :name => 'name b' - @nc4 = FactoryGirl.create :color, :t => 2, :name => 'name c' - @nc5 = FactoryGirl.create :color, :t => 4, :name => 'name d' + @color2 = FactoryGirl.create :color, :name => 'new color a', :t => 1 + @color3 = FactoryGirl.create :color, :name => 'new color b', :t => 2 + @color4 = FactoryGirl.create :color, :name => 'new color c', :t => 3 + @color5 = FactoryGirl.create :color, :name => 'new color d', :t => 4 Color.stub(:default_page_size).and_return(2) end it '通常は2件を返す' do - cl = Color.list - cl.should have(2).items + r = Color.list + r.should have(2).items end it 'page=1なら末尾2件を返す' do #時系列で並んでいる - cl = Color.list( {}, 1) - cl.should eq [@color, @nc2] + r = Color.list(1) + r.should eq [@c, @color2] end it 'page=2なら中間2件を返す' do - cl = Color.list({}, 2) - cl.should eq [@nc4, @nc3] + r = Color.list(2) + r.should eq [@color3, @color4] end it 'page=3なら先頭1件を返す' do - cl = Color.list({}, 3) - cl.should eq [@nc5] + r = Color.list(3) + r.should eq [@color5] + end + end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @color2 = FactoryGirl.create :color, :name => 'new color a', :t => 1 + @color3 = FactoryGirl.create :color, :name => 'new color b', :t => 2 + @color4 = FactoryGirl.create :color, :name => 'new color c', :t => 3 + @color5 = FactoryGirl.create :color, :name => 'new color d', :t => 4 + Color.stub(:default_page_size).and_return(0) + end + it '通常は全件(5件)を返す' do + r = Color.list + r.should have(5).items + end + end + end + describe '一覧取得オプションに於いて' do + it '空のHashを返す' do + r = Color.list_opt + r.is_a?(Hash).should be_true + r.should be_empty + end + end + describe 'json一覧出力オプションに於いて' do + it '空のHashを返す' do + r = Color.list_json_opt + r.is_a?(Hash).should be_true + r.should be_empty + end + end + + describe '単体取得に於いて' do + before do + @c = FactoryGirl.create :color + end + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + Color.stub(:show_opt).with(any_args).and_return({}) + Color.should_receive(:show_opt).with(any_args).exactly(1) + r = Color.show @c.id, @author + end + it '閲覧許可を問い合わせている' do + Color.any_instance.stub(:visible?).with(any_args).and_return(true) + Color.any_instance.should_receive(:visible?).with(any_args).exactly(1) + r = Color.show @c.id, @author + end + end + it '指定の色を返す' do + r = Color.show @author.id, @author + r.should eq @c + end + context '閲覧許可が出なかったとき' do + it '403Forbidden例外を返す' do + Color.any_instance.stub(:visible?).and_return(false) + lambda{ + Color.show @c.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しない色を開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Color.show 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + + describe '単体取得オプションに於いて' do + it '空のHashを返す' do + r = Color.show_opt + r.is_a?(Hash).should be_true + r.should be_empty + end + end + describe 'json単体出力オプションに於いて' do + it '空のHashを返す' do + r = Color.show_json_opt + r.is_a?(Hash).should be_true + r.should be_empty + end + end + + describe 'インポートに於いて' do + before do + end + context 'つつがなく終わるとき' do + it 'ファイルインポートを依頼する' do + Color.should_receive(:import_file).with(any_args).exactly(1) + Color.stub(:import_file).with(any_args).and_return([]) + Color.import(@f) + end + it '色更新を一回依頼する' do + Color.stub(:store).with(any_args).and_return(Color.new) + Color.should_receive(:store).with(any_args).exactly(1) + Color.import(@f) + end + it '色が追加される' do + lambda { + Color.import(@f) + }.should change Color, :count + end + it '[]を返す' do + r = Color.import(@f) + r.should eq [] + end + end + context '複数データがつつがなく終わるとき' do + it '色更新を二回依頼する' do + Color.stub(:store).with(any_args).and_return(Color.new) + Color.should_receive(:store).with(any_args).exactly(2) + Color.import(@fs) + end + it '色が二個追加される' do + lambda { + r = Color.import(@fs) + }.should change(Color, :count).by 2 + end + it '[]を返す' do + r = Color.import(@fs) + r.should eq [] end end end diff --git a/spec/models/comic_spec.rb b/spec/models/comic_spec.rb index c73ec3b0..794cb210 100644 --- a/spec/models/comic_spec.rb +++ b/spec/models/comic_spec.rb @@ -18,172 +18,109 @@ describe Comic do describe '検証に於いて' do before do + @comic = FactoryGirl.build :comic, :author_id => @author.id end - it 'オーソドックスなデータなら通る' do - @comic = FactoryGirl.build :comic, :author_id => @author.id - @comic.should be_valid + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @comic.title = 'a' + @comic.visible = 0 + @comic.should be_valid + end + it '上限データが通る' do + @comic.title = 'a'*100 + @comic.visible = 1 + @comic.should be_valid + end end context 'titleを検証するとき' do it 'nullなら失敗する' do - @comic = FactoryGirl.build :comic, :author_id => @author.id, :title => nil + @comic.title = nil @comic.should_not be_valid end it '100文字以上なら失敗する' do - @comic = FactoryGirl.build :comic, :author_id => @author.id, :title => 'a'*101 + @comic.title = 'a'*101 @comic.should_not be_valid end end context 'visibleを検証するとき' do it 'nullなら失敗する' do - @comic = FactoryGirl.build :comic, :author_id => @author.id, :visible => nil + @comic.visible = nil @comic.should_not be_valid end it '負なら失敗する' do - @comic = FactoryGirl.build :comic, :author_id => @author.id, :visible => -1 + @comic.visible = -1 @comic.should_not be_valid end - it '4以上なら失敗する' do - @comic = FactoryGirl.build :comic, :author_id => @author.id, :visible => 4 + it '2以上なら失敗する' do + @comic.visible = 2 @comic.should_not be_valid end end end - describe 'データ補充に於いて' do - before do - @comic = Comic.new + describe 'デフォルト値補充に於いて' do + it 'visibleが0になっている' do + @comic = FactoryGirl.build :comic, :visible => nil + @comic.supply_default + @comic.visible.should eq 0 end - - context '初期値を補充するとき' do - it '空なら0が補充される' do - @comic.supply_default - @comic.visible.should == 0 - end - it 'visibleが空でないなら変化なし' do - @comic.visible = 1 - lambda{@comic.supply_default}.should_not change(@comic, :visible) - end + end + + describe '上書き補充に於いて' do + it '作家idが設定されている' do + @comic = FactoryGirl.build :comic, :author_id => nil + @comic.overwrite @author + @comic.author_id.should eq @author.id end end - describe '作者判定に於いて' do + describe '所持判定に於いて' do before do + @comic = FactoryGirl.build :comic, :author_id => @author.id end - it '自作のコミックならyes' do - comic = FactoryGirl.create :comic, :author_id => @author.id - comic.own?(@author).should == true + it '自分のコミックならyes' do + @comic.own?(@author).should == true end it '他人のコミックならno' do - comic = FactoryGirl.create :comic, :author_id => 0 - comic.own?(@author).should == false + @comic.own?(@other_author).should == false end it '作家が不明ならno' do - comic = FactoryGirl.create :comic, :author_id => @author.id - comic.own?(nil).should == false + @comic.own?(nil).should == false end end + describe '閲覧許可に於いて' do before do + @comic = FactoryGirl.build :comic, :author_id => @author.id end - it '自作の公開コミックを見るときは許可する' do - Comic.any_instance.stub(:own?).and_return(true) - comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 3 - comic.visible?(@author).should == true - end - it '自作のコミックは非公開でも許可する' do - Comic.any_instance.stub(:own?).and_return(true) - comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0 - comic.visible?(@author).should == true - end - it '他人のコミックでも公開コミックなら許可する' do - Comic.any_instance.stub(:own?).and_return(false) - comic = FactoryGirl.create :comic, :author_id => 0, :visible => 3 - comic.visible?(@author).should == true - end - it '他人のコミックで非公開コミックなら許可しない' do - Comic.any_instance.stub(:own?).and_return(false) - comic = FactoryGirl.create :comic, :author_id => 0, :visible => 0 - comic.visible?(@author).should == false - end - end - describe '単体取得に於いて' do - before do - @comic = FactoryGirl.create :comic, :author_id => @author.id - end - it '指定のコミックを返す' do - c = Comic.show @comic.id, @author.id - c.should eq @comic - end - end - describe '編集取得に於いて' do - before do - @comic = FactoryGirl.create :comic, :author_id => @author.id - end - it '指定のコミックを返す' do - Comic.any_instance.stub(:own?).and_return(true) - c = Comic.edit @comic.id, @author.id - c.should eq @comic - end - context '他人のコミックを開こうとしたとき' do - it '403Forbidden例外を返す' do - Comic.any_instance.stub(:own?).and_return(false) - lambda{ - Comic.edit @comic.id, @author - }.should raise_error(ActiveRecord::Forbidden) - end - end - context '存在しないコミックを開こうとしたとき' do - it '404RecordNotFound例外を返す' do - lambda{ - Comic.edit 110, @author - }.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - describe '関連テーブルプションに於いて' do - context 'オプションがないとき' do - it '2つの項目を含んでいる' do - r = Comic.show_include_opt - r.should have(2).items - end - it '作家を含んでいる' do - r = Comic.show_include_opt - r.has_key?(:author).should be_true - end - it 'ストーリーを含んでいる' do - r = Comic.show_include_opt - r.has_key?(:stories).should be_true - end - it 'ストーリーはコマを含んでいる' do - r = Comic.show_include_opt - r[:stories].has_key?(:panel).should be_true - end - end - end - describe 'json単体出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = Comic.show_json_include_opt - r.has_key?(:include).should be_true - end - it '2つの項目を含んでいる' do - r = Comic.show_json_include_opt[:include] - r.should have(2).items - end - it '作家を含んでいる' do - r = Comic.show_json_include_opt[:include] - r.has_key?(:author).should be_true - end - it 'ストーリーを含んでいる' do - r = Comic.show_json_include_opt[:include] - r.has_key?(:stories).should be_true - end - it 'ストーリーはコマを含んでいる' do - r = Comic.show_json_include_opt[:include] - r[:stories].has_key?(:panel).should be_true - end + it '自分の公開コミックを見るときは許可する' do + Comic.any_instance.stub(:own?).and_return(true) + Comic.any_instance.stub(:visible).and_return(1) + r = @comic.visible?(@author) + r.should == true + end + it '自分のコミックなら非公開でも許可する' do + Comic.any_instance.stub(:own?).and_return(true) + Comic.any_instance.stub(:visible).and_return(0) + r = @comic.visible?(@author) + r.should == true + end + it '他人のコミックでも公開なら許可する' do + Comic.any_instance.stub(:own?).and_return(false) + Comic.any_instance.stub(:visible).and_return(1) + r = @comic.visible?(@author) + r.should == true + end + it '他人のコミックで非公開なら許可しない' do + Comic.any_instance.stub(:own?).and_return(false) + Comic.any_instance.stub(:visible).and_return(0) + r = @comic.visible?(@author) + r.should == false + end end + describe '一覧取得に於いて' do before do @comic = FactoryGirl.create :comic, :author_id => @author.id @@ -213,6 +150,13 @@ describe Comic do Comic.page_size('1000').should eq Comic.max_page_size end end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + Comic.stub(:list_opt).with(any_args).and_return({}) + Comic.should_receive(:list_opt).with(any_args).exactly(1) + r = Comic.list + end + end it 'リストを返す' do c = Comic.list c.should eq [@comic] @@ -223,7 +167,8 @@ describe Comic do c.should eq [@comic] end it '時系列で並んでいる' do - v = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100 + #公開コミックは(他人のコミックであっても)含んでいる + v = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 100 c = Comic.list c.should eq [v, @comic] end @@ -241,18 +186,31 @@ describe Comic do end it 'page=1なら末尾2件を返す' do #時系列で並んでいる - c = Comic.list({}, 1) + c = Comic.list(1) c.should eq [@comic5, @comic4] end it 'page=2なら中間2件を返す' do - c = Comic.list({}, 2) + c = Comic.list(2) c.should eq [@comic3, @comic2] end it 'page=3なら先頭1件を返す' do - c = Comic.list({}, 3) + c = Comic.list(3) c.should eq [@comic] end end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100 + @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200 + @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300 + @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400 + Color.stub(:default_page_size).and_return(0) + end + it '通常は全件(5件)を返す' do + r = Comic.list + r.should have(5).items + end + end end describe 'list関連テーブルプションに於いて' do it 'includeキーを含んでいる' do @@ -303,6 +261,13 @@ describe Comic do before do @comic = FactoryGirl.create :comic, :author_id => @author.id end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + Comic.stub(:list_opt).with(any_args).and_return({}) + Comic.should_receive(:list_opt).with(any_args).exactly(1) + r = Comic.mylist @author + end + end it 'リストを返す' do c = Comic.mylist @author c.should eq [@comic] @@ -322,6 +287,162 @@ describe Comic do cl = Comic.mylist @author cl.should eq [nc, @comic] end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100 + @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200 + @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300 + @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400 + end + it '通常は2件を返す' do + c = Comic.mylist @author, 1, 2 + c.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + c = Comic.mylist(@author, 1, 2) + c.should eq [@comic5, @comic4] + end + it 'page=2なら中間2件を返す' do + c = Comic.mylist(@author, 2, 2) + c.should eq [@comic3, @comic2] + end + it 'page=3なら先頭1件を返す' do + c = Comic.mylist(@author, 3, 2) + c.should eq [@comic] + end + end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100 + @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200 + @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300 + @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400 + Color.stub(:default_page_size).and_return(0) + end + it '通常は全件(5件)を返す' do + r = Comic.mylist @author, 5, 0 + r.should have(5).items + end + end end + describe '単体取得に於いて' do + before do + @comic = FactoryGirl.create :comic, :author_id => @author.id + end + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + Comic.stub(:show_opt).with(any_args).and_return({}) + Comic.should_receive(:show_opt).with(any_args).exactly(1) + r = Comic.show @comic.id, @author + end + it '閲覧許可を問い合わせている' do + Comic.any_instance.stub(:visible?).with(any_args).and_return(true) + Comic.any_instance.should_receive(:visible?).with(any_args).exactly(1) + r = Comic.show @comic.id, @author + end + end + it '指定のコミックを返す' do + c = Comic.show @comic.id, @author.id + c.should eq @comic + end + context '閲覧許可が出なかったとき' do + it '403Forbidden例外を返す' do + Comic.any_instance.stub(:visible?).and_return(false) + lambda{ + Comic.show @author.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しない作家を開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Comic.show 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + + describe '編集取得に於いて' do + before do + @comic = FactoryGirl.create :comic, :author_id => @author.id + end + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + Comic.stub(:show_opt).with(any_args).and_return({}) + Comic.should_receive(:show_opt).with(any_args).exactly(1) + r = Comic.edit @comic.id, @author + end + it '所持判定を問い合わせている' do + Comic.any_instance.stub(:own?).with(any_args).and_return(true) + Comic.any_instance.should_receive(:own?).with(any_args).exactly(1) + r = Comic.edit @comic.id, @author + end + end + it '指定のコミックを返す' do + Comic.any_instance.stub(:own?).and_return(true) + c = Comic.edit @comic.id, @author.id + c.should eq @comic + end + context '他人のコミックを開こうとしたとき' do + it '403Forbidden例外を返す' do + Comic.any_instance.stub(:own?).and_return(false) + lambda{ + Comic.edit @comic.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しないコミックを開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Comic.edit 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '関連テーブルプションに於いて' do + it 'includeキーを含んでいる' do + r = Comic.show_opt + r.has_key?(:include).should be_true + end + it '2つの項目を含んでいる' do + r = Comic.show_opt[:include] + r.should have(2).items + end + it '作家を含んでいる' do + r = Comic.show_opt[:include] + r.has_key?(:author).should be_true + end + it 'ストーリーを含んでいる' do + r = Comic.show_opt[:include] + r.has_key?(:stories).should be_true + end + it 'ストーリーはコマを含んでいる' do + r = Comic.show_opt[:include] + r[:stories].has_key?(:panel).should be_true + end + end + describe 'json単体出力オプションに於いて' do + it 'includeキーを含んでいる' do + r = Comic.show_json_opt + r.has_key?(:include).should be_true + end + it '2つの項目を含んでいる' do + r = Comic.show_json_opt[:include] + r.should have(2).items + end + it '作家を含んでいる' do + r = Comic.show_json_opt[:include] + r.has_key?(:author).should be_true + end + it 'ストーリーを含んでいる' do + r = Comic.show_json_opt[:include] + r.has_key?(:stories).should be_true + end + it 'ストーリーはコマを含んでいる' do + r = Comic.show_json_opt[:include] + r[:stories].has_key?(:panel).should be_true + end + end end diff --git a/spec/models/ground_color_spec.rb b/spec/models/ground_color_spec.rb index 556956e9..38c56cf1 100644 --- a/spec/models/ground_color_spec.rb +++ b/spec/models/ground_color_spec.rb @@ -25,27 +25,26 @@ describe GroundColor do before do @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id, :color_id => @color.id end - it 'オーソドックスなデータなら通る' do - @gc.save - @gc.should be_valid + + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @gc.z = 1 + @gc.should be_valid + end + it '上限データが通る' do + @gc.z = 99999 + @gc.should be_valid + end end context 'panel_idを検証するとき' do #ネストの保存はnilを許可しなければならないので数値チェックだけ - it 'テストデータの確認' do - @gc.panel_id = @panel.id - @gc.should be_valid - end it '数値でなければ失敗する' do @gc.panel_id = 'a' @gc.should_not be_valid end end context 'color_idを検証するとき' do - it 'テストデータの確認' do - @gc.color_id = @color.id - @gc.should be_valid - end it 'nullなら失敗する' do @gc.color_id = nil @gc.should_not be_valid @@ -54,16 +53,12 @@ describe GroundColor do @gc.color_id = 'a' @gc.should_not be_valid end - it '存在する実素材でなければ失敗する' do + it '存在する色でなければ失敗する' do @gc.color_id = 0 @gc.should_not be_valid end end context 'zを検証するとき' do - it 'テストデータの確認' do - @gc.z = 1 - @gc.should be_valid - end it 'nullなら失敗する' do @gc.z = nil @gc.should_not be_valid @@ -82,6 +77,21 @@ describe GroundColor do end end end + + describe 'デフォルト値補充に於いて' do + it 'defined' do + @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id, :color_id => @color.id + @gc.supply_default + end + end + + describe '上書き補充に於いて' do + it 'defined' do + @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id, :color_id => @color.id + @gc.overwrite + end + end + describe '一覧取得に於いて' do before do @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id @@ -111,12 +121,21 @@ describe GroundColor do GroundColor.page_size('1000').should eq GroundColor.max_page_size end end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel}) + GroundColor.should_receive(:list_opt).with(any_args).exactly(1) + r = GroundColor.list + end + end it 'リストを返す' do pl = GroundColor.list pl.should eq [@gc] end it '時系列で並んでいる' do - npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100 + #公開コマなら(他人のコマであっても)含んでいる + opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + npl = FactoryGirl.create :ground_color, :panel_id => opl.id, :color_id => @color.id, :updated_at => Time.now + 100 pl = GroundColor.list pl.should eq [npl, @gc] end @@ -128,10 +147,10 @@ describe GroundColor do end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do - @npl2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100 - @npl3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200 - @npl4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300 - @npl5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400 + @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100 + @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200 + @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300 + @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400 GroundColor.stub(:default_page_size).and_return(2) end it '通常は2件を返す' do @@ -140,19 +159,32 @@ describe GroundColor do end it 'page=1なら末尾2件を返す' do #時系列で並んでいる - pl = GroundColor.list( {}, 1) - pl.should eq [@npl5, @npl4] + pl = GroundColor.list(1) + pl.should eq [@gc5, @gc4] end it 'page=2なら中間2件を返す' do - pl = GroundColor.list({}, 2) - pl.should eq [@npl3, @npl2] + pl = GroundColor.list(2) + pl.should eq [@gc3, @gc2] end it 'page=3なら先頭1件を返す' do - pl = GroundColor.list({}, 3) + pl = GroundColor.list(3) pl.should eq [@gc] end end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100 + @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200 + @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300 + @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400 + end + it '通常は全件(5件)を返す' do + r = GroundColor.list 5, 0 + r.should have(5).items + end + end end + describe 'list関連テーブルプションに於いて' do it 'includeキーを含んでいる' do r = GroundColor.list_opt @@ -202,6 +234,13 @@ describe GroundColor do before do @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel}) + GroundColor.should_receive(:list_opt).with(any_args).exactly(1) + r = GroundColor.mylist @author + end + end it 'リストを返す' do pl = GroundColor.mylist @author pl.should eq [@gc] @@ -217,6 +256,49 @@ describe GroundColor do pl = GroundColor.mylist @author pl.should eq [@gc] end + it '自分のコマの景色は非公開でも含んでいる' do + hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 + npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100 + pl = GroundColor.mylist @author + pl.should eq [npl, @gc] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100 + @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200 + @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300 + @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400 + end + it '通常は2件を返す' do + c = GroundColor.mylist @author, 1, 2 + c.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + c = GroundColor.mylist(@author, 1, 2) + c.should eq [@gc5, @gc4] + end + it 'page=2なら中間2件を返す' do + c = GroundColor.mylist(@author, 2, 2) + c.should eq [@gc3, @gc2] + end + it 'page=3なら先頭1件を返す' do + c = GroundColor.mylist(@author, 3, 2) + c.should eq [@gc] + end + end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100 + @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200 + @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300 + @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400 + end + it '通常は全件(5件)を返す' do + r = GroundColor.mylist @author, 5, 0 + r.should have(5).items + end + end end end diff --git a/spec/models/ground_picture_spec.rb b/spec/models/ground_picture_spec.rb index 9a45e754..94714dd0 100644 --- a/spec/models/ground_picture_spec.rb +++ b/spec/models/ground_picture_spec.rb @@ -24,27 +24,27 @@ describe GroundPicture do before do @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id end - it 'オーソドックスなデータなら通る' do - @gp.save - @gp.should be_valid + + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @gp.z = 1 + @gp.should be_valid + end + it '上限データが通る' do + @gp.z = 99999 + @gp.should be_valid + end end + context 'panel_idを検証するとき' do #ネストの保存はnilを許可しなければならないので数値チェックだけ - it 'テストデータの確認' do - @gp.panel_id = @panel.id - @gp.should be_valid - end it '数値でなければ失敗する' do @gp.panel_id = 'a' @gp.should_not be_valid end end context 'picture_idを検証するとき' do - it 'テストデータの確認' do - @gp.picture_id = @panel.id - @gp.should be_valid - end it 'nullなら失敗する' do @gp.picture_id = nil @gp.should_not be_valid @@ -59,10 +59,6 @@ describe GroundPicture do end end context 'zを検証するとき' do - it 'テストデータの確認' do - @gp.z = 1 - @gp.should be_valid - end it 'nullなら失敗する' do @gp.z = nil @gp.should_not be_valid @@ -81,6 +77,21 @@ describe GroundPicture do end end end + + describe 'デフォルト値補充に於いて' do + it 'defined' do + @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + @gp.supply_default + end + end + + describe '上書き補充に於いて' do + it 'defined' do + @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + @gp.overwrite + end + end + describe '一覧取得に於いて' do before do @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id @@ -110,12 +121,21 @@ describe GroundPicture do GroundPicture.page_size('1000').should eq GroundPicture.max_page_size end end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) + GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) + r = GroundPicture.list + end + end it 'リストを返す' do pl = GroundPicture.list pl.should eq [@gp] end it '時系列で並んでいる' do - npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100 + #公開コマなら(他人のコマであっても)含んでいる + opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + npl = FactoryGirl.create :ground_picture, :panel_id => opl.id, :picture_id => @p.id, :updated_at => Time.now + 100 pl = GroundPicture.list pl.should eq [npl, @gp] end @@ -127,10 +147,10 @@ describe GroundPicture do end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do - @npl2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100 - @npl3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200 - @npl4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300 - @npl5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400 + @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100 + @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200 + @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300 + @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400 GroundPicture.stub(:default_page_size).and_return(2) end it '通常は2件を返す' do @@ -139,18 +159,30 @@ describe GroundPicture do end it 'page=1なら末尾2件を返す' do #時系列で並んでいる - pl = GroundPicture.list( {}, 1) - pl.should eq [@npl5, @npl4] + pl = GroundPicture.list(1) + pl.should eq [@gp5, @gp4] end it 'page=2なら中間2件を返す' do - pl = GroundPicture.list({}, 2) - pl.should eq [@npl3, @npl2] + pl = GroundPicture.list(2) + pl.should eq [@gp3, @gp2] end it 'page=3なら先頭1件を返す' do - pl = GroundPicture.list({}, 3) + pl = GroundPicture.list(3) pl.should eq [@gp] end end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100 + @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200 + @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300 + @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400 + end + it '通常は全件(5件)を返す' do + r = GroundPicture.list 5, 0 + r.should have(5).items + end + end end describe 'list関連テーブルプションに於いて' do it 'includeキーを含んでいる' do @@ -217,6 +249,13 @@ describe GroundPicture do before do @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) + GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) + r = GroundPicture.mylist @author + end + end it 'リストを返す' do pl = GroundPicture.mylist @author pl.should eq [@gp] @@ -232,6 +271,50 @@ describe GroundPicture do pl = GroundPicture.mylist @author pl.should eq [@gp] end + it '自分のコマの景色は非公開でも含んでいる' do + hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 + npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100 + pl = GroundPicture.mylist @author + pl.should eq [npl, @gp] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100 + @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200 + @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300 + @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400 + end + it '通常は2件を返す' do + c = GroundPicture.mylist @author, 1, 2 + c.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + c = GroundPicture.mylist(@author, 1, 2) + c.should eq [@gp5, @gp4] + end + it 'page=2なら中間2件を返す' do + c = GroundPicture.mylist(@author, 2, 2) + c.should eq [@gp3, @gp2] + end + it 'page=3なら先頭1件を返す' do + c = GroundPicture.mylist(@author, 3, 2) + c.should eq [@gp] + end + end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100 + @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200 + @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300 + @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400 + end + it '通常は全件(5件)を返す' do + r = GroundPicture.mylist @author, 5, 0 + r.should have(5).items + end + end end + end diff --git a/spec/models/license_group_spec.rb b/spec/models/license_group_spec.rb index 8279cfba..a6ca057a 100644 --- a/spec/models/license_group_spec.rb +++ b/spec/models/license_group_spec.rb @@ -13,21 +13,27 @@ describe LicenseGroup do end describe '検証に於いて' do before do - end - - it 'オーソドックスなデータなら通る' do @lg = FactoryGirl.build :license_group - @lg.should be_valid end - context 'nameを検証するとき' do - before do - @lg = FactoryGirl.build :license_group + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @lg.name = 'a' + @lg.classname = 'a' + @lg.caption = 'a' + @lg.url = 'http://test.jp/' + @lg.should be_valid end - it 'テストデータの確認' do + it '上限データが通る' do @lg.name = 'a'*50 + @lg.classname = 'a'*50 + @lg.caption = 'a'*30 + @lg.url = 'http://test.jp/aaaaa' + 'a' * 180 @lg.should be_valid end + end + + context 'nameを検証するとき' do it 'nullなら失敗する' do @lg.name = '' @lg.should_not be_valid @@ -42,13 +48,6 @@ describe LicenseGroup do end end context 'classnameを検証するとき' do - before do - @lg = FactoryGirl.build :license_group - end - it 'テストデータの確認' do - @lg.classname = 'a'*50 - @lg.should be_valid - end it 'nullなら失敗する' do @lg.classname = '' @lg.should_not be_valid @@ -59,13 +58,6 @@ describe LicenseGroup do end end context 'captionを検証するとき' do - before do - @lg = FactoryGirl.build :license_group - end - it 'テストデータの確認' do - @lg.caption = 'a'*30 - @lg.should be_valid - end it 'nullなら失敗する' do @lg.caption = '' @lg.should_not be_valid @@ -76,13 +68,6 @@ describe LicenseGroup do end end context 'urlを検証するとき' do - before do - @lg = FactoryGirl.build :license_group - end - it 'テストデータの確認' do - @lg.url = 'http://test.com/' - @lg.should be_valid - end it 'nullなら失敗する' do @lg.url = '' @lg.should_not be_valid @@ -98,6 +83,126 @@ describe LicenseGroup do end end + describe 'デフォルト値補充に於いて' do + it 'defined' do + @lg = FactoryGirl.build :license_group, :name => "1" + @lg.supply_default + end + end + + describe '上書き補充に於いて' do + it 'defined' do + @lg = FactoryGirl.build :license_group, :name => "1" + @lg.overwrite + end + end + + describe '閲覧許可に於いて' do + #ライセンスグループは作家作成する前から存在するので、閲覧制限の意味がない + end + + describe '一覧取得に於いて' do + before do + @lg = FactoryGirl.create :license_group, :name => "1" + end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + LicenseGroup.stub(:list_opt).with(any_args).and_return({}) + LicenseGroup.should_receive(:list_opt).with(any_args).exactly(1) + r = LicenseGroup.list + end + end + it 'リストを返す' do + l = LicenseGroup.list + l.should eq [@lg] + end + it '名前順で並んでいる' do + @lg2 = FactoryGirl.create :license_group, :name => "5", :url => 'http://test.ptn/10' + l = LicenseGroup.list + l.should eq [@lg, @lg2] + end + end + describe 'list関連テーブルプションに於いて' do + it 'includeキーを含んでいる' do + r = LicenseGroup.list_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = LicenseGroup.list_opt[:include] + r.should have(1).items + end + it 'ライセンスを含んでいる' do + r = LicenseGroup.list_opt[:include] + r.has_key?(:licenses).should be_true + end + end + describe 'json一覧出力オプションに於いて' do + it 'includeキーを含んでいる' do + r = LicenseGroup.list_json_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = LicenseGroup.list_json_opt[:include] + r.should have(1).items + end + it 'ライセンスを含んでいる' do + r = LicenseGroup.list_json_opt[:include] + r.has_key?(:licenses).should be_true + end + end + + describe '単体取得に於いて' do + before do + @lg = FactoryGirl.create :license_group + end + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + LicenseGroup.stub(:show_opt).with(any_args).and_return({}) + LicenseGroup.should_receive(:show_opt).with(any_args).exactly(1) + r = LicenseGroup.show @lg.id + end + end + it '指定のコマを返す' do + l = LicenseGroup.show @lg.id + l.should eq @lg + end + context '存在しないライセンスグループを開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + LicenseGroup.show 110 + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '単体出力オプションに於いて' do + it 'includeキーを含んでいる' do + r = LicenseGroup.show_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = LicenseGroup.show_opt[:include] + r.should have(1).items + end + it 'ライセンスを含んでいる' do + r = LicenseGroup.show_opt[:include] + r.has_key?(:licenses).should be_true + end + end + describe 'json単体出力オプションに於いて' do + it 'includeキーを含んでいる' do + r = LicenseGroup.show_json_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = LicenseGroup.show_json_opt[:include] + r.should have(1).items + end + it 'ライセンスを含んでいる' do + r = LicenseGroup.show_json_opt[:include] + r.has_key?(:licenses).should be_true + end + end + describe '更新に於いて' do before do @n = @j.keys.first @@ -263,78 +368,4 @@ describe LicenseGroup do end end - describe '単体取得に於いて' do - before do - @lg = FactoryGirl.create :license_group - end - it '指定のコマを返す' do - l = LicenseGroup.show @lg.id - l.should eq @lg - end - end - describe '関連テーブルプションに於いて' do - context 'オプションがないとき' do - it 'ライセンスを含んでいる' do - r = LicenseGroup.show_include_opt - r.has_key?(:licenses).should be_true - end - end - end - describe 'json単体出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = LicenseGroup.show_json_include_opt - r.has_key?(:include).should be_true - end - it '1つの項目を含んでいる' do - r = LicenseGroup.show_json_include_opt[:include] - r.should have(1).items - end - it 'ライセンスを含んでいる' do - r = LicenseGroup.show_json_include_opt[:include] - r.has_key?(:licenses).should be_true - end - end - describe '一覧取得に於いて' do - before do - @lg = FactoryGirl.create :license_group, :name => "1" - end - it 'リストを返す' do - l = LicenseGroup.list - l.should eq [@lg] - end - it '名前順で並んでいる' do - @lg2 = FactoryGirl.create :license_group, :name => "5", :url => 'http://test.ptn/10' - l = LicenseGroup.list - l.should eq [@lg, @lg2] - end - end - describe 'list関連テーブルプションに於いて' do - it 'includeキーを含んでいる' do - r = LicenseGroup.list_opt - r.has_key?(:include).should be_true - end - it '1つの項目を含んでいる' do - r = LicenseGroup.list_opt[:include] - r.should have(1).items - end - it 'ライセンスを含んでいる' do - r = LicenseGroup.list_opt[:include] - r.has_key?(:licenses).should be_true - end - end - describe 'json一覧出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = LicenseGroup.list_json_opt - r.has_key?(:include).should be_true - end - it '1つの項目を含んでいる' do - r = LicenseGroup.list_json_opt[:include] - r.should have(1).items - end - it 'ライセンスを含んでいる' do - r = LicenseGroup.list_json_opt[:include] - r.has_key?(:licenses).should be_true - end - end - end diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index 5f7f4d03..b6b2ccb7 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -12,15 +12,22 @@ describe License do @l = FactoryGirl.build :license, :license_group_id => @lg.id, :system_picture_id => @sp.id end - it 'オーソドックスなデータなら通る' do - @l.should be_valid + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @l.name = 'a' + @l.caption = 'a' + @l.url = 'http://test.jp/' + @l.should be_valid + end + it '上限データが通る' do + @l.name = 'a'*50 + @l.caption = 'a'*30 + @l.url = 'http://test.jp/aaaaa' + 'a' * 180 + @l.should be_valid + end end context 'license_group_idを検証するとき' do - it 'テストデータの確認' do - @l.license_group_id = @lg.id - @l.should be_valid - end it 'nullなら失敗する' do @l.license_group_id = '' @l.should_not be_valid @@ -35,10 +42,6 @@ describe License do end end context 'nameを検証するとき' do - it 'テストデータの確認' do - @l.name = 'a'*50 - @l.should be_valid - end it 'nullなら失敗する' do @l.name = '' @l.should_not be_valid @@ -53,10 +56,6 @@ describe License do end end context 'captionを検証するとき' do - it 'テストデータの確認' do - @l.caption = 'a'*30 - @l.should be_valid - end it 'nullなら失敗する' do @l.caption = '' @l.should_not be_valid @@ -67,11 +66,6 @@ describe License do end end context 'urlを検証するとき' do - it 'テストデータの確認' do - @l.url = 'http://test.jp/aaaaa' + 'a' * 180 - @l.save! - @l.should be_valid - end it 'nullなら失敗する' do @l.url = '' @l.should_not be_valid @@ -80,16 +74,12 @@ describe License do @l.url = 'http://test.jp/aaaaa' + 'a' * 181 @l.should_not be_valid end - it 'url形式でなら失敗する' do + it 'url形式でないなら失敗する' do @l.url = 'a'*200 @l.should_not be_valid end end context 'system_picture_idを検証するとき' do - it 'テストデータの確認' do - @l.system_picture_id = @sp.id - @l.should be_valid - end it 'nullなら失敗する' do @l.system_picture_id = '' @l.should_not be_valid @@ -105,6 +95,136 @@ describe License do end end + describe 'デフォルト値補充に於いて' do + it 'defined' do + @sp = FactoryGirl.create :system_picture + @lg = FactoryGirl.create :license_group + @l = FactoryGirl.build :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id + @l.supply_default + end + end + + describe '上書き補充に於いて' do + it 'defined' do + @sp = FactoryGirl.create :system_picture + @lg = FactoryGirl.create :license_group + @l = FactoryGirl.build :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id + @l.overwrite + end + end + + describe '閲覧許可に於いて' do + #ライセンスは作家作成する前から存在するので、閲覧制限の意味がない + end + + describe '一覧取得に於いて' do + before do + @sp = FactoryGirl.create :system_picture + @lg = FactoryGirl.create :license_group + @l = FactoryGirl.create :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id + @lg2 = FactoryGirl.create :license_group, :name => 'pubdm' + end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + License.stub(:list_opt).with(any_args).and_return({}) + License.should_receive(:list_opt).with(any_args).exactly(1) + r = License.list + end + end + it 'リストを返す' do + l = License.list + l.should eq [@l] + end + it '名前順で並んでいる' do + @l2 = FactoryGirl.create :license, :name => 'peta3.0', :url => 'http://pe.ta/3.0', :license_group_id => @lg.id, :system_picture_id => @sp.id + @l3 = FactoryGirl.create :license, :name => 'pd1.0', :url => 'http://pb.dm/1.0', :license_group_id => @lg2.id, :system_picture_id => @sp.id + l = License.list + l.should eq [@l3, @l, @l2] + end + end + describe 'list関連テーブルプションに於いて' do + it 'includeキーを含んでいる' do + r = License.list_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = License.list_opt[:include] + r.should have(1).items + end + it 'ライセンスグループを含んでいる' do + r = License.list_opt[:include] + r.has_key?(:license_group).should be_true + end + end + describe 'json一覧出力オプションに於いて' do + it 'includeキーを含んでいる' do + r = License.list_json_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = License.list_json_opt[:include] + r.should have(1).items + end + it 'ライセンスグループを含んでいる' do + r = License.list_json_opt[:include] + r.has_key?(:license_group).should be_true + end + end + + describe '単体取得に於いて' do + before do + @sp = FactoryGirl.create :system_picture + @lg = FactoryGirl.create :license_group + @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id + end + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + License.stub(:show_opt).with(any_args).and_return({}) + License.should_receive(:show_opt).with(any_args).exactly(1) + r = License.show @l.id + end + end + it '指定のライセンスを返す' do + l = License.show @l.id + l.should eq @l + end + context '存在しないライセンスを開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + License.show 110 + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '単体取得オプションに於いて' do + it 'includeキーを含んでいる' do + r = License.show_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = License.show_opt[:include] + r.should have(1).items + end + it 'ライセンスグループを含んでいる' do + r = License.show_opt[:include] + r.has_key?(:license_group).should be_true + end + end + describe 'json単体出力オプションに於いて' do + it 'includeキーを含んでいる' do + r = License.show_json_opt + r.has_key?(:include).should be_true + end + it '1つの項目を含んでいる' do + r = License.show_json_opt[:include] + r.should have(1).items + end + it 'ライセンスグループを含んでいる' do + r = License.show_json_opt[:include] + r.has_key?(:license_group).should be_true + end + end + describe '更新に於いて' do before do @lg = FactoryGirl.create :license_group @@ -220,90 +340,4 @@ describe License do end end - describe '単体取得に於いて' do - before do - @sp = FactoryGirl.create :system_picture - @lg = FactoryGirl.create :license_group - @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id - end - it '指定のコマを返す' do - l = License.show @l.id - l.should eq @l - end - end - describe '関連テーブルプションに於いて' do - context 'オプションがないとき' do - it 'ライセンスグループを含んでいる' do - r = License.show_include_opt - r.should eq [:license_group] - end - end - context 'オプションで素材ライセンスを含ませたとき' do - it 'ライセンスグループと素材ライセンスを含んでいる' do - r = License.show_include_opt(:include => :resource_picture_license) - r.should eq [:license_group, :resource_picture_license] - end - end - end - describe 'json単体出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = License.show_json_include_opt - r.has_key?(:include).should be_true - end - it '1つの項目を含んでいる' do - r = License.show_json_include_opt[:include] - r.should have(1).items - end - it 'ライセンスグループを含んでいる' do - r = License.show_json_include_opt[:include] - r.has_key?(:license_group).should be_true - end - end - describe '一覧取得に於いて' do - before do - @sp = FactoryGirl.create :system_picture - @lg = FactoryGirl.create :license_group - @l = FactoryGirl.create :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id - @lg2 = FactoryGirl.create :license_group, :name => 'pubdm' - end - it 'リストを返す' do - l = License.list - l.should eq [@l] - end - it '名前順で並んでいる' do - @l2 = FactoryGirl.create :license, :name => 'peta3.0', :url => 'http://pe.ta/3.0', :license_group_id => @lg.id, :system_picture_id => @sp.id - @l3 = FactoryGirl.create :license, :name => 'pd1.0', :url => 'http://pb.dm/1.0', :license_group_id => @lg2.id, :system_picture_id => @sp.id - l = License.list - l.should eq [@l3, @l, @l2] - end - end - describe 'list関連テーブルプションに於いて' do - it 'includeキーを含んでいる' do - r = License.list_opt - r.has_key?(:include).should be_true - end - it '1つの項目を含んでいる' do - r = License.list_opt[:include] - r.should have(1).items - end - it 'ライセンスグループを含んでいる' do - r = License.list_opt[:include] - r.has_key?(:license_group).should be_true - end - end - describe 'json一覧出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = License.list_json_opt - r.has_key?(:include).should be_true - end - it '1つの項目を含んでいる' do - r = License.list_json_opt[:include] - r.should have(1).items - end - it 'ライセンスグループを含んでいる' do - r = License.list_json_opt[:include] - r.has_key?(:license_group).should be_true - end - end - end diff --git a/spec/models/original_picture_license_group_spec.rb b/spec/models/original_picture_license_group_spec.rb index fa0dd933..ac8dc1a7 100644 --- a/spec/models/original_picture_license_group_spec.rb +++ b/spec/models/original_picture_license_group_spec.rb @@ -19,21 +19,19 @@ describe OriginalPictureLicenseGroup do describe '検証に於いて' do before do - end - - it 'オーソドックスなデータなら通る' do @ol = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id - @ol.should be_valid end - context 'original_picture_idを検証するとき' do - before do - @ol = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @ol.should be_valid end - it 'テストデータの確認' do - @ol.original_picture_id = @op.id + it '上限データが通る' do @ol.should be_valid end + end + + context 'original_picture_idを検証するとき' do it 'nullなら失敗する' do @ol.original_picture_id = nil @ol.should_not be_valid @@ -48,13 +46,6 @@ describe OriginalPictureLicenseGroup do end end context 'license_group_idを検証するとき' do - before do - @ol = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id - end - it 'テストデータの確認' do - @ol.license_group_id = @lg.id - @ol.should be_valid - end it 'nullなら失敗する' do @ol.license_group_id = nil @ol.should_not be_valid diff --git a/spec/models/original_picture_spec.rb b/spec/models/original_picture_spec.rb index 4314fd3f..b3327704 100644 --- a/spec/models/original_picture_spec.rb +++ b/spec/models/original_picture_spec.rb @@ -18,21 +18,29 @@ describe OriginalPicture do describe '検証に於いて' do before do - end - - it 'オーソドックスなデータなら通る' do @op = FactoryGirl.build :original_picture, :artist_id => @artist.id - @op.should be_valid end - context 'extを検証するとき' do - before do - @op = FactoryGirl.build :original_picture, :artist_id => @artist.id + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @op.ext = 'png' #リストにない拡張子は通らないし + @op.width = 1 + @op.height = 1 + @op.filesize = 1 + @op.md5 = 'a'*32 + @op.should be_valid end - it 'テストデータの確認' do + it '上限データが通る' do @op.ext = 'jpeg' + @op.width = 99999 + @op.height = 99999 + @op.filesize = 2000000 + @op.md5 = 'a'*32 @op.should be_valid end + end + + context 'extを検証するとき' do it 'nullなら失敗する' do @op.ext = '' @op.should_not be_valid @@ -47,13 +55,6 @@ describe OriginalPicture do end end context 'widthを検証するとき' do - before do - @op = FactoryGirl.build :original_picture, :artist_id => @artist.id - end - it 'テストデータの確認' do - @op.width = 1 - @op.should be_valid - end it 'nullなら失敗する' do @op.width = nil @op.should_not be_valid @@ -72,13 +73,6 @@ describe OriginalPicture do end end context 'heightを検証するとき' do - before do - @op = FactoryGirl.build :original_picture, :artist_id => @artist.id - end - it 'テストデータの確認' do - @op.height = 1 - @op.should be_valid - end it 'nullなら失敗する' do @op.height = nil @op.should_not be_valid @@ -97,13 +91,6 @@ describe OriginalPicture do end end context 'filesizeを検証するとき' do - before do - @op = FactoryGirl.build :original_picture, :artist_id => @artist.id - end - it 'テストデータの確認' do - @op.filesize = 1 - @op.should be_valid - end it 'nullなら失敗する' do @op.filesize = nil @op.should_not be_valid @@ -122,13 +109,6 @@ describe OriginalPicture do end end context 'artist_idを検証するとき' do - before do - @op = FactoryGirl.build :original_picture - end - it 'テストデータの確認' do - @op.artist_id = @artist.id - @op.should be_valid - end it 'nullなら失敗する' do @op.artist_id = nil @op.should_not be_valid @@ -143,28 +123,34 @@ describe OriginalPicture do end end context 'md5を検証するとき' do - before do - @op = FactoryGirl.build :original_picture - end - it 'テストデータの確認' do - @op.md5 = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - @op.should be_valid - end it 'nullなら失敗する' do @op.md5 = '' @op.should_not be_valid end - it '32文字以上なら失敗する' do + it '31文字なら失敗する' do + @op.md5 = 'a'*31 + @op.should_not be_valid + end + it '33文字なら失敗する' do @op.md5 = 'a'*33 @op.should_not be_valid end end end - describe 'データ補充に於いて' do - before do + describe 'デフォルト値補充に於いて' do + it 'defined' do + @op = FactoryGirl.build :original_picture, :artist_id => @artist.id + @op.supply_default + end + end + + describe '上書き補充に於いて' do + it '絵師idが設定されている' do + @op = FactoryGirl.build :original_picture, :artist_id => nil + @op.overwrite @artist + @op.artist_id.should eq @artist.id end - end describe '作者判定に於いて' do @@ -172,104 +158,117 @@ describe OriginalPicture do end it '自作の原画ならyes' do op = FactoryGirl.create :original_picture, :artist_id => @artist.id - op.own?(@author).should == true + op.own?(@artist).should == true end it '他人のならno' do op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id - op.own?(@author).should == false - end - it '作家が不明ならno' do - op = FactoryGirl.create :original_picture, :artist_id => @artist.id - op.own?(nil).should == false - end - it '作家が絵師でないならno' do - other_user = FactoryGirl.create( :user_yas) - op = FactoryGirl.create :original_picture, :artist_id => @artist.id - op.own?(@other_author).should == false + op.own?(@artist).should == false end end - describe '単体取得に於いて' do + + describe '閲覧許可に於いて' do before do @op = FactoryGirl.create :original_picture, :artist_id => @artist.id end - it '指定の原画を返す' do - pic = OriginalPicture.show @op.id, @artist - pic.should eq @op - end - context '他人の原画を開こうとしたとき' do - it '403Forbidden例外を返す' do - lambda{ - pic = OriginalPicture.show @op.id, @other_artist - }.should raise_error(ActiveRecord::Forbidden) - end - end - context '存在しない原画を開こうとしたとき' do - it '404RecordNotFound例外を返す' do - lambda{ - pic = OriginalPicture.show 0, @artist - }.should raise_error(ActiveRecord::RecordNotFound) - end + it '自分の原画を見るときは許可する' do + OriginalPicture.any_instance.stub(:own?).and_return(true) + r = @op.visible?(@artist) + r.should == true + end + it '他人の原画なら許可しない' do + OriginalPicture.any_instance.stub(:own?).and_return(false) + r = @op.visible?(@artist) + r.should == false + end + end + + #大文字混じりは検証ではねているので、無用になっている + describe '拡張子に於いて' do + before do + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id, :ext => 'jpeg' end + it '画像ファイル拡張子を英数小文字で返す' do + r = @op.dext + r.should eq 'jpeg' + end end - describe '編集取得に於いて' do + + describe 'ファイル名に於いて' do before do @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + OriginalPicture.any_instance.stub(:dext).and_return('gif') end - it '指定の原画を返す' do - pic = OriginalPicture.edit @op.id, @artist - pic.should eq @op - end - context '他人の原画を開こうとしたとき' do - it '403Forbidden例外を返す' do - lambda{ - pic = OriginalPicture.edit @op.id, @other_artist - }.should raise_error(ActiveRecord::Forbidden) - end - end - context '存在しない原画を開こうとしたとき' do - it '404RecordNotFound例外を返す' do - lambda{ - pic = OriginalPicture.edit 0, @artist - }.should raise_error(ActiveRecord::RecordNotFound) - end + it '拡張子取得を依頼している' do + OriginalPicture.any_instance.should_receive(:dext).exactly(1) + @op.filename end + it 'id+拡張子のフォーマットで返す' do + r = @op.filename + r.should eq "#{@op.id}.gif" + end end - describe '単体出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = OriginalPicture.show_include_opt - r.has_key?(:include).should be_true - end - it '2つの項目を含んでいる' do - r = OriginalPicture.show_include_opt[:include] - r.should have(2).items - end - it '素材を含んでいる' do - r = OriginalPicture.show_include_opt[:include] - r.has_key?(:resource_picture).should be_true + + describe 'MimeTypeに於いて' do + before do + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + OriginalPicture.any_instance.stub(:dext).and_return('gif') end - it '実素材を含んでいる' do - r = OriginalPicture.show_include_opt[:include] - r.has_key?(:pictures).should be_true + it '拡張子取得を依頼している' do + OriginalPicture.any_instance.should_receive(:dext).exactly(1) + @op.mime_type end + it 'image/拡張子のフォーマットで返す' do + r = @op.mime_type + r.should eq "image/gif" + end end - describe 'json単体出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = OriginalPicture.show_json_include_opt - r.has_key?(:include).should be_true - end - it '2つの項目を含んでいる' do - r = OriginalPicture.show_json_include_opt[:include] - r.should have(2).items + + describe 'ファイルのurlに於いて' do + before do + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + OriginalPicture.any_instance.stub(:filename).and_return('3.gif') end - it '素材を含んでいる' do - r = OriginalPicture.show_json_include_opt[:include] - r.has_key?(:resource_picture).should be_true + it 'ファイル名取得を依頼している' do + OriginalPicture.any_instance.should_receive(:filename).exactly(1) + @op.url end - it '実素材を含んでいる' do - r = OriginalPicture.show_json_include_opt[:include] - r.has_key?(:pictures).should be_true + it '/original_pictures/3.gifのフォーマットで返す' do + r = @op.url + r.should eq "/original_pictures/3.gif" + end + end + + describe '画像タグオプションに於いて' do + before do + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif') + ResourcePicture.stub(:fix_size_both).with(any_args).and_return([40, 30]) + end + it 'サムネイル画像の幅高さ取得を依頼している' do + ResourcePicture.should_receive(:fix_size_both).with(any_args).exactly(1) + @op.opt_img_tag + end + it '戻り値はHashで返す' do + r = @op.opt_img_tag + r.is_a?(Hash).should be_true + end + it 'srcキーを含んでいる' do + r = @op.opt_img_tag + r.has_key?(:src).should be_true + r[:src].should eq '/original_pictures/3.gif' + end + it 'widthキーを含んでいる' do + r = @op.opt_img_tag + r.has_key?(:width).should be_true + r[:width].should eq 40 + end + it 'heightキーを含んでいる' do + r = @op.opt_img_tag + r.has_key?(:height).should be_true + r[:height].should eq 30 end end + describe '一覧取得に於いて' do before do @op = FactoryGirl.create :original_picture, :artist_id => @artist.id @@ -299,46 +298,6 @@ describe OriginalPicture do OriginalPicture.page_size('1000').should eq OriginalPicture.max_page_size end end - it 'リストを返す' do - pic = OriginalPicture.list @artist.id - pic.should eq [@op] - end - it '他人の原画は含んでいない' do - FactoryGirl.create :original_picture, :artist_id => @other_artist.id - pic = OriginalPicture.list @artist.id - pic.should eq [@op] - end - it '時系列で並んでいる' do - newpic = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100 - pic = OriginalPicture.list @artist.id - pic.should eq [newpic, @op] - end - context 'DBに5件あって1ページの件数を2件に変えたとして' do - before do - @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100 - @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200 - @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300 - @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400 - OriginalPicture.stub(:default_page_size).and_return(2) - end - it '通常は2件を返す' do - pic = OriginalPicture.list @artist.id - pic.should have(2).items - end - it 'page=1なら末尾2件を返す' do - #時系列で並んでいる - pic = OriginalPicture.list( @artist.id, {}, 1) - pic.should eq [@op5, @op4] - end - it 'page=2なら中間2件を返す' do - pic = OriginalPicture.list( @artist.id, {}, 2) - pic.should eq [@op3, @op2] - end - it 'page=3なら先頭1件を返す' do - pic = OriginalPicture.list( @artist.id, {}, 3) - pic.should eq [@op] - end - end end describe 'list関連テーブルプションに於いて' do it 'includeキーを含んでいる' do @@ -376,6 +335,76 @@ describe OriginalPicture do r.has_key?(:pictures).should be_true end end + + describe '自分のコミック一覧取得に於いて' do + before do + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + OriginalPicture.stub(:list_opt).with(any_args).and_return({}) + OriginalPicture.should_receive(:list_opt).with(any_args).exactly(1) + r = OriginalPicture.mylist @artist + end + end + it 'リストを返す' do + r = OriginalPicture.mylist @artist + r.should eq [@op] + end + it '時系列で並んでいる' do + nc = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100 + r = OriginalPicture.mylist @artist + r.should eq [nc, @op] + end + it '他人のコミックはxxxでも含まない' do + nc = FactoryGirl.create :original_picture, :artist_id => @other_artist.id + r = OriginalPicture.mylist @artist + r.should eq [@op] + end + it '自分のコミックはxxxでも含んでいる' do + nc = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100 + r = OriginalPicture.mylist @artist + r.should eq [nc, @op] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100 + @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200 + @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300 + @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400 + end + it '通常は2件を返す' do + r = OriginalPicture.mylist @artist, 1, 2 + r.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + r = OriginalPicture.mylist @artist, 1, 2 + r.should eq [@op5, @op4] + end + it 'page=2なら中間2件を返す' do + r = OriginalPicture.mylist @artist, 2, 2 + r.should eq [@op3, @op2] + end + it 'page=3なら先頭1件を返す' do + r = OriginalPicture.mylist @artist, 3, 2 + r.should eq [@op] + end + end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100 + @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200 + @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300 + @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400 + end + it '通常は全件(5件)を返す' do + r = OriginalPicture.mylist @artist, 5, 0 + r.should have(5).items + end + end + end + describe '更新履歴一覧取得に於いて' do before do @op = FactoryGirl.create :original_picture, :artist_id => @artist.id @@ -400,6 +429,115 @@ describe OriginalPicture do r.should eq [@p2, @p] end end + + describe '単体取得に於いて' do + before do + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + end + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + OriginalPicture.stub(:show_opt).with(any_args).and_return({}) + OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1) + r = OriginalPicture.show @op.id, @artist + end + it '閲覧許可を問い合わせている' do + OriginalPicture.any_instance.stub(:visible?).with(any_args).and_return(true) + OriginalPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1) + r = OriginalPicture.show @op.id, @artist + end + end + it '指定の原画を返す' do + pic = OriginalPicture.show @op.id, @artist + pic.should eq @op + end + context '他人の原画を開こうとしたとき' do + it '403Forbidden例外を返す' do + OriginalPicture.any_instance.stub(:visible?).and_return(false) + lambda{ + pic = OriginalPicture.show @op.id, @other_artist + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しない原画を開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + pic = OriginalPicture.show 0, @artist + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '編集取得に於いて' do + before do + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + end + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + OriginalPicture.stub(:show_opt).with(any_args).and_return({}) + OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1) + r = OriginalPicture.edit @op.id, @artist + end + it '所持判定を問い合わせている' do + OriginalPicture.any_instance.stub(:own?).with(any_args).and_return(true) + OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1) + r = OriginalPicture.edit @op.id, @artist + end + end + it '指定の原画を返す' do + pic = OriginalPicture.edit @op.id, @artist + pic.should eq @op + end + context '他人の原画を開こうとしたとき' do + it '403Forbidden例外を返す' do + OriginalPicture.any_instance.stub(:own?).and_return(false) + lambda{ + r = OriginalPicture.edit @op.id, @other_artist + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しない原画を開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + r = OriginalPicture.edit 0, @artist + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '単体出力オプションに於いて' do + it 'includeキーを含んでいる' do + r = OriginalPicture.show_opt + r.has_key?(:include).should be_true + end + it '2つの項目を含んでいる' do + r = OriginalPicture.show_opt[:include] + r.should have(2).items + end + it '素材を含んでいる' do + r = OriginalPicture.show_opt[:include] + r.has_key?(:resource_picture).should be_true + end + it '実素材を含んでいる' do + r = OriginalPicture.show_opt[:include] + r.has_key?(:pictures).should be_true + end + end + describe 'json単体出力オプションに於いて' do + it 'includeキーを含んでいる' do + r = OriginalPicture.show_json_opt + r.has_key?(:include).should be_true + end + it '2つの項目を含んでいる' do + r = OriginalPicture.show_json_opt[:include] + r.should have(2).items + end + it '素材を含んでいる' do + r = OriginalPicture.show_json_opt[:include] + r.has_key?(:resource_picture).should be_true + end + it '実素材を含んでいる' do + r = OriginalPicture.show_json_opt[:include] + r.has_key?(:pictures).should be_true + end + end describe 'RMagick変換に於いて' do before do @op = FactoryGirl.build :original_picture, :artist_id => @artist.id @@ -426,70 +564,54 @@ describe OriginalPicture do describe '作成・更新に於いて' do before do @op = FactoryGirl.build :original_picture, :artist_id => @artist.id - #RMagickのスタブをおいておく - class Mgk ; class Image ; end ; end - @filesize = 76543 - Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new]) - Mgk.any_instance.stub(:format).with(any_args).and_return('png') - Mgk.any_instance.stub(:rows).with(any_args).and_return(200) - Mgk.any_instance.stub(:columns).with(any_args).and_return(100) - Mgk.any_instance.stub(:filesize).with(any_args).and_return(@filesize) - Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data') - #原画ファイル削除だけは必ず成功するものとしておく - PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true) - #素材取得は新規作成ケースでテストしておく - ResourcePicture.stub(:update_picture).with(any_args).and_return( - FactoryGirl.build :resource_picture, :artist_id => @artist.id - ) + @bd = File.open(Rails.root + 'spec/StandardA.gif', 'rb').read end context '事前チェック' do before do #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。 #それで外部のメソッド呼び出しだけに着目してテストする。 - OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new) OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true) PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true) end it 'RMagick変換を依頼している' do OriginalPicture.any_instance.should_receive(:data_to_mgk).exactly(1) - @op.store 'bindata', @artist + @op.store @bd, @artist end it '自身に属性をセットしている' do OriginalPicture.any_instance.should_receive(:attributes=).exactly(1) - @op.store 'bindata', @artist + @op.store @bd, @artist end it '自身が保存されている' do OriginalPicture.any_instance.should_receive(:save).exactly(1) - @op.store 'bindata', @artist + @op.store @bd, @artist end it 'PictureIoに画像データの保存を依頼している' do PictureIO::LocalPicture.any_instance.should_receive(:put).with(any_args).exactly(1) - @op.store 'bindata', @artist + @op.store @bd, @artist end end context 'つつがなく終わるとき' do before do #すべての処理を正常パターンで通過させ、保存機能をチェックする。 - OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new) # OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true) - PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true) +# PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true) end it '自身に属性をセットしている' do lambda { - @op.store 'bindata', @artist + @op.store @bd, @artist }.should change @op, :filesize end it '原画モデルが作成されている' do lambda { - @op.store 'bindata', @artist + @op.store @bd, @artist }.should change OriginalPicture, :count end it '原画が保存されている' do - @op.store 'bindata', @artist + @op.store @bd, @artist OriginalPicture.find(@op).should_not be_nil end it 'Trueを返す' do - @op.store('bindata', @artist).should eq true + @op.store(@bd, @artist).should eq true end end #以下から例外ケース。処理先頭から失敗させていく @@ -498,23 +620,22 @@ describe OriginalPicture do OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(false) end it 'falseを返す' do - @op.store('bindata', @artist).should be_false + @op.store(@bd, @artist).should be_false end it '自身の保存は呼ばれていない' do OriginalPicture.any_instance.should_not_receive(:save) - @op.store('bindata', @artist) + @op.store(@bd, @artist) end end context '自身の保存に失敗したとき' do before do - OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new) OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false) end it 'falseを返す' do - @op.store('bindata', @artist).should be_false + @op.store(@bd, @artist).should be_false end it '更新されていない' do - @op.store('bindata', @artist) + @op.store(@bd, @artist) @op.should be_a_new OriginalPicture end it '原画の保存は呼ばれていない' do @@ -523,24 +644,23 @@ describe OriginalPicture do end context '原画の保存に失敗したとき' do before do - OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new) OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true) PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(false) end it 'falseを返す' do - @op.store('bindata', @artist).should be_false + @op.store(@bd, @artist).should be_false end it '更新されていない' do - @op.store('bindata', @artist) + @op.store(@bd, @artist) @op.should be_a_new OriginalPicture end it '対象素材オブジェクトの保存は呼ばれていない' do ResourcePicture.any_instance.should_not_receive(:save) - @op.store('bindata', @artist) + @op.store(@bd, @artist) end it '全体エラーメッセージがセットされている' do lambda { - @op.store('bindata', @artist) + @op.store(@bd, @artist) }.should change(@op.errors[:base], :count) end end diff --git a/spec/models/panel_color_spec.rb b/spec/models/panel_color_spec.rb index 7f0c5b5c..7740421a 100644 --- a/spec/models/panel_color_spec.rb +++ b/spec/models/panel_color_spec.rb @@ -24,11 +24,21 @@ describe PanelColor do before do @pc = FactoryGirl.build :panel_color, :panel_id => @panel.id end - it 'オーソドックスなデータなら通る' do - @pc.save - @pc.should be_valid + + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @pc.z = 1 + @pc.code = 0 + @pc.should be_valid + end + it '上限データが通る' do + @pc.z = 99999 + @pc.code = 0xffffff + @pc.should be_valid + end end + context 'panel_idを検証するとき' do #ネストの保存はnilを許可しなければならないので数値チェックだけ it 'テストデータの確認' do @@ -85,6 +95,21 @@ describe PanelColor do end end end + + describe 'デフォルト値補充に於いて' do + it 'defined' do + @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id + @pc.supply_default + end + end + + describe '上書き補充に於いて' do + it 'defined' do + @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id + @pc.overwrite + end + end + describe '一覧取得に於いて' do before do @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id @@ -119,7 +144,9 @@ describe PanelColor do pl.should eq [@pc] end it '時系列で並んでいる' do - npl = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 100 + #公開コマなら(他人のコマであっても)含んでいる + opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + npl = FactoryGirl.create :panel_color, :panel_id => opl.id, :z => 2, :updated_at => Time.now + 100 pl = PanelColor.list pl.should eq [npl, @pc] end @@ -131,10 +158,10 @@ describe PanelColor do end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do - @npl2 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100 - @npl3 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200 - @npl4 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300 - @npl5 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400 + @pc2 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100 + @pc3 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200 + @pc4 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300 + @pc5 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400 PanelColor.stub(:default_page_size).and_return(2) end it '通常は2件を返す' do @@ -143,18 +170,30 @@ describe PanelColor do end it 'page=1なら末尾2件を返す' do #時系列で並んでいる - pl = PanelColor.list( {}, 1) - pl.should eq [@npl5, @npl4] + pl = PanelColor.list(1) + pl.should eq [@pc5, @pc4] end it 'page=2なら中間2件を返す' do - pl = PanelColor.list({}, 2) - pl.should eq [@npl3, @npl2] + pl = PanelColor.list(2) + pl.should eq [@pc3, @pc2] end it 'page=3なら先頭1件を返す' do - pl = PanelColor.list({}, 3) + pl = PanelColor.list(3) pl.should eq [@pc] end end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @pc2 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100 + @pc3 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200 + @pc4 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300 + @pc5 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400 + end + it '通常は全件(5件)を返す' do + r = PanelColor.list 5, 0 + r.should have(5).items + end + end end describe 'list関連テーブルプションに於いて' do it 'includeキーを含んでいる' do @@ -197,6 +236,13 @@ describe PanelColor do before do @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + PanelColor.stub(:list_opt).with(any_args).and_return({:include => :panel}) + PanelColor.should_receive(:list_opt).with(any_args).exactly(1) + r = PanelColor.mylist @author + end + end it 'リストを返す' do pl = PanelColor.mylist @author pl.should eq [@pc] @@ -212,6 +258,49 @@ describe PanelColor do pl = PanelColor.mylist @author pl.should eq [@pc] end + it '自分のコマの景色は非公開でも含んでいる' do + hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 + npl = FactoryGirl.create :panel_color, :panel_id => hpl.id, :z => 2, :updated_at => Time.now + 100 + pl = PanelColor.mylist @author + pl.should eq [npl, @pc] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @pc2 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100 + @pc3 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200 + @pc4 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300 + @pc5 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400 + end + it '通常は2件を返す' do + c = PanelColor.mylist @author, 1, 2 + c.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + c = PanelColor.mylist(@author, 1, 2) + c.should eq [@pc5, @pc4] + end + it 'page=2なら中間2件を返す' do + c = PanelColor.mylist(@author, 2, 2) + c.should eq [@pc3, @pc2] + end + it 'page=3なら先頭1件を返す' do + c = PanelColor.mylist(@author, 3, 2) + c.should eq [@pc] + end + end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @pc2 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100 + @pc3 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200 + @pc4 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300 + @pc5 = FactoryGirl.create :panel_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400 + end + it '通常は全件(5件)を返す' do + r = PanelColor.mylist @author, 5, 0 + r.should have(5).items + end + end end end diff --git a/spec/models/panel_picture_spec.rb b/spec/models/panel_picture_spec.rb index f3a70a30..a85ed4b9 100644 --- a/spec/models/panel_picture_spec.rb +++ b/spec/models/panel_picture_spec.rb @@ -27,27 +27,38 @@ describe PanelPicture do Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0) Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0) end - it 'オーソドックスなデータなら通る' do - @pp.save - @pp.should be_valid + + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @pp.link = 'http://test.jp/' + @pp.x = -99999 + @pp.y = -99999 + @pp.z = 1 + @pp.t = 0 + @pp.width = -99999 + @pp.height = -99999 + @pp.should be_valid + end + it '上限データが通る' do + @pp.link = 'http://test.jp/aaaaa' + 'a' * 180 + @pp.x = 99999 + @pp.y = 99999 + @pp.z = 99999 + @pp.t = 99999 + @pp.width = 99999 + @pp.height = 99999 + @pp.should be_valid + end end context 'panel_idを検証するとき' do #ネストの保存はnilを許可しなければならないので数値チェックだけ - it 'テストデータの確認' do - @pp.panel_id = @panel.id - @pp.should be_valid - end it '数値でなければ失敗する' do @pp.panel_id = 'a' @pp.should_not be_valid end end context 'linkを検証するとき' do - it 'テストデータの確認' do - @pp.link = 'abcdefghi0abcdefghi0abcdefghi0abcdefghi0abcdefghi0'*4 - @pp.should be_valid - end it 'nullでも通る' do @pp.link = '' @pp.should be_valid @@ -56,12 +67,12 @@ describe PanelPicture do @pp.link = 'a'*201 @pp.should_not be_valid end + it 'url形式でないなら失敗する' do + @pp.link = 'a'*200 + @pp.should_not be_valid + end end context 'xを検証するとき' do - it 'テストデータの確認' do - @pp.x = '1' - @pp.should be_valid - end it 'nullなら失敗する' do @pp.x = nil @pp.should_not be_valid @@ -80,10 +91,6 @@ describe PanelPicture do end end context 'yを検証するとき' do - it 'テストデータの確認' do - @pp.y = '1' - @pp.should be_valid - end it 'nullなら失敗する' do @pp.y = nil @pp.should_not be_valid @@ -102,12 +109,6 @@ describe PanelPicture do end end context 'widthを検証するとき' do - before do - end - it 'テストデータの確認' do - @pp.width = 1 - @pp.should be_valid - end it 'nullなら失敗する' do @pp.width = nil @pp.should_not be_valid @@ -173,12 +174,6 @@ describe PanelPicture do end end context 'heightを検証するとき' do - before do - end - it 'テストデータの確認' do - @pp.height = '1' - @pp.should be_valid - end it 'nullなら失敗する' do @pp.height = nil @pp.should_not be_valid @@ -248,10 +243,6 @@ describe PanelPicture do end end context 'zを検証するとき' do - it 'テストデータの確認' do - @pp.z = 1 - @pp.should be_valid - end it 'nullなら失敗する' do @pp.z = nil @pp.should_not be_valid @@ -270,10 +261,6 @@ describe PanelPicture do end end context 'tを検証するとき' do - it 'テストデータの確認' do - @pp.t = 0 - @pp.should be_valid - end it 'nullなら失敗する' do @pp.t = nil @pp.should_not be_valid @@ -288,10 +275,6 @@ describe PanelPicture do end end context 'picture_idを検証するとき' do - it 'テストデータの確認' do - @pp.picture_id = @p.id - @pp.should be_valid - end it 'nullなら失敗する' do @pp.picture_id = nil @pp.should_not be_valid @@ -336,17 +319,26 @@ describe PanelPicture do PanelPicture.page_size('1000').should eq PanelPicture.max_page_size end end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) + PanelPicture.should_receive(:list_opt).with(any_args).exactly(1) + r = PanelPicture.list + end + end it 'リストを返す' do - pl = PanelPicture.list - pl.should eq [@pp] + r = PanelPicture.list + r.should eq [@pp] end it '時系列で並んでいる' do - npl = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id, + #公開されたコマのコマ絵は(他人のコマ絵であっても)含んでいる + hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + npl = FactoryGirl.create :panel_picture, :panel_id => hc.id, :t => 0, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 100 - pl = PanelPicture.list - pl.should eq [npl, @pp] + r = PanelPicture.list + r.should eq [npl, @pp] end - it '非公開のコマは含まない' do + it '非公開のコマのコマ絵は自分のコマであっても含まない' do hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id, :width => @p.width, :height => @p.height @@ -356,13 +348,13 @@ describe PanelPicture do context 'DBに5件あって1ページの件数を2件に変えたとして' do before do @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id, - :width => @p.width, :height => @p.height, :updated_at => Time.now + 100 + :width => @p.width, :height => @p.height, :updated_at => Time.now + 100 @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id, - :width => @p.width, :height => @p.height, :updated_at => Time.now + 200 + :width => @p.width, :height => @p.height, :updated_at => Time.now + 200 @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id, - :width => @p.width, :height => @p.height, :updated_at => Time.now + 300 + :width => @p.width, :height => @p.height, :updated_at => Time.now + 300 @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id, - :width => @p.width, :height => @p.height, :updated_at => Time.now + 400 + :width => @p.width, :height => @p.height, :updated_at => Time.now + 400 PanelPicture.stub(:default_page_size).and_return(2) end it '通常は2件を返す' do @@ -371,18 +363,34 @@ describe PanelPicture do end it 'page=1なら末尾2件を返す' do #時系列で並んでいる - pl = PanelPicture.list( {}, 1) + pl = PanelPicture.list(1) pl.should eq [@npl5, @npl4] end it 'page=2なら中間2件を返す' do - pl = PanelPicture.list({}, 2) + pl = PanelPicture.list(2) pl.should eq [@npl3, @npl2] end it 'page=3なら先頭1件を返す' do - pl = PanelPicture.list({}, 3) + pl = PanelPicture.list(3) pl.should eq [@pp] end end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 100 + @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 200 + @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 300 + @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 400 + end + it '通常は全件(5件)を返す' do + r = PanelPicture.list 5, 0 + r.should have(5).items + end + end end describe 'list関連テーブルプションに於いて' do it 'includeキーを含んでいる' do @@ -450,6 +458,13 @@ describe PanelPicture do @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :width => @p.width, :height => @p.height end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) + PanelPicture.should_receive(:list_opt).with(any_args).exactly(1) + r = PanelPicture.mylist @author + end + end it 'リストを返す' do pl = PanelPicture.mylist @author pl.should eq [@pp] @@ -460,13 +475,65 @@ describe PanelPicture do pl = PanelPicture.mylist @author pl.should eq [npl, @pp] end - it '他人のコマは公開でも含まない' do + it '他人のコマのコマ絵は公開コマでも含まない' do hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id, :width => @p.width, :height => @p.height pl = PanelPicture.mylist @author pl.should eq [@pp] end + it '自分のコマのコマ絵は非公開コマでも含んでいる' do + pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 + ni = FactoryGirl.create :panel_picture, :panel_id => pl.id, :picture_id => @p.id, + :width => @p.width, :height => @p.height + r = PanelPicture.mylist @author + r.should eq [ni, @pp] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 100 + @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 200 + @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 300 + @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 400 + end + it '通常は2件を返す' do + r = PanelPicture.mylist @author, 1, 2 + r.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + r = PanelPicture.mylist(@author, 1, 2) + r.should eq [@npl5, @npl4] + end + it 'page=2なら中間2件を返す' do + r = PanelPicture.mylist(@author, 2, 2) + r.should eq [@npl3, @npl2] + end + it 'page=3なら先頭1件を返す' do + r = PanelPicture.mylist(@author, 3, 2) + r.should eq [@pp] + end + end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do + @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 100 + @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 200 + @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 300 + @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id, + :width => @p.width, :height => @p.height, :updated_at => Time.now + 400 + end + it '通常は全件(5件)を返す' do + r = PanelPicture.mylist @author, 5, 0 + r.should have(5).items + end + end end end diff --git a/spec/models/speech_balloon_spec.rb b/spec/models/speech_balloon_spec.rb index af576ec8..0414328d 100644 --- a/spec/models/speech_balloon_spec.rb +++ b/spec/models/speech_balloon_spec.rb @@ -15,35 +15,32 @@ describe SpeechBalloon do describe '検証に於いて' do before do - end - - it 'オーソドックスなデータなら通る' do @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id - @sb.should be_valid end - context 'panel_idを検証するとき' do - before do - @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @sb.classname = 'a' + @sb.z = 1 + @sb.t = 0 + @sb.should be_valid end - #ネストの保存はnilを許可しなければならないので数値チェックだけ - it 'テストデータの確認' do - @sb.panel_id = @panel.id + it '上限データが通る' do + @sb.classname = 'a'*50 + @sb.z = 99999 + @sb.t = 99999 @sb.should be_valid end + end + + context 'panel_idを検証するとき' do + #ネストの保存はnilを許可しなければならないので数値チェックだけ it '数値でなければ失敗する' do @sb.panel_id = 'a' @sb.should_not be_valid end end context 'speech_balloon_template_idを検証するとき' do - before do - @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id - end - it 'テストデータの確認' do - @sb.speech_balloon_template_id = @speech_balloon_template.id - @sb.should be_valid - end it 'nullなら失敗する' do @sb.speech_balloon_template_id = nil @sb.should_not be_valid @@ -58,13 +55,6 @@ describe SpeechBalloon do end end context 'classnameを検証するとき' do - before do - @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id - end - it 'テストデータの確認' do - @sb.classname = 'abcdefghi0abcdefghi0abcdefghi0abcdefghi0abcdefghi0' - @sb.should be_valid - end it 'nullなら失敗する' do @sb.classname = '' @sb.should_not be_valid @@ -75,13 +65,6 @@ describe SpeechBalloon do end end context 'tを検証するとき' do - before do - @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id - end - it 'テストデータの確認' do - @sb.t = 0 - @sb.should be_valid - end it 'nullなら失敗する' do @sb.t = nil @sb.should_not be_valid @@ -96,20 +79,7 @@ describe SpeechBalloon do end end context 'settingsを検証するとき' do - before do - @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id - end - it 'テストデータの確認' do - @sb.settings = '{}' - @sb.should be_valid - end end end - describe 'データ補充に於いて' do - before do - end - - end - end diff --git a/spec/models/speech_spec.rb b/spec/models/speech_spec.rb index f54f225f..292155f0 100644 --- a/spec/models/speech_spec.rb +++ b/spec/models/speech_spec.rb @@ -16,15 +16,28 @@ describe Speech do end describe '検証に於いて' do - it 'オーソドックスなデータなら通る' do + before do @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id - @speech.should be_valid end + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @speech.x = 0 + @speech.y = 0 + @speech.width = 1 + @speech.height = 1 + @speech.should be_valid + end + it '上限データが通る' do + @speech.x = 99999 + @speech.y = 99999 + @speech.width = 99999 + @speech.height = 99999 + @speech.should be_valid + end + end + context 'speech_balloon_idを検証するとき' do - before do - @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id - end #ネストの保存はnilを許可しなければならないので数値チェックだけ it 'テストデータの確認' do @speech.speech_balloon_id = @speech_balloon.id @@ -38,13 +51,6 @@ describe Speech do context 'contentを検証するとき' do end context 'xを検証するとき' do - before do - @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id - end - it 'テストデータの確認' do - @speech.x = '1' - @speech.should be_valid - end it 'nullなら失敗する' do @speech.x = nil @speech.should_not be_valid @@ -63,13 +69,6 @@ describe Speech do end end context 'yを検証するとき' do - before do - @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id - end - it 'テストデータの確認' do - @speech.y = '1' - @speech.should be_valid - end it 'nullなら失敗する' do @speech.y = nil @speech.should_not be_valid @@ -88,13 +87,6 @@ describe Speech do end end context 'widthを検証するとき' do - before do - @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id - end - it 'テストデータの確認' do - @speech.width = 1 - @speech.should be_valid - end it 'nullなら失敗する' do @speech.width = nil @speech.should_not be_valid @@ -113,13 +105,6 @@ describe Speech do end end context 'heightを検証するとき' do - before do - @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id - end - it 'テストデータの確認' do - @speech.height = '1' - @speech.should be_valid - end it 'nullなら失敗する' do @speech.height = nil @speech.should_not be_valid @@ -138,13 +123,6 @@ describe Speech do end end context 'settingsを検証するとき' do - before do - @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id - end - it 'テストデータの確認' do - @speech.settings = '' - @speech.should be_valid - end end end -- 2.11.0