From: yasushiito Date: Wed, 10 Jul 2013 10:20:01 +0000 (+0900) Subject: t#31653:add scenario X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=commitdiff_plain;h=0aac365f8835eff6469a051b21f9314a337e3f1b t#31653:add scenario --- diff --git a/app/models/speech.rb b/app/models/speech.rb index 134c038b..5c5cdcd1 100644 --- a/app/models/speech.rb +++ b/app/models/speech.rb @@ -6,12 +6,13 @@ class Speech < ActiveRecord::Base validates :y, :presence => true, :numericality => true validates :width, :presence => true, :numericality => true, :natural_number => true validates :height, :presence => true, :numericality => true, :natural_number => true + validates :quotes, :length => {:maximum => 15}, :quotes_even => true # validates :settings, :presence => true before_validation :valid_encode def valid_encode - ['content', 'settings'].each do |a| + ['content', 'quotes', 'settings'].each do |a| next if attributes[a] == nil raise Pettanr::BadRequest unless attributes[a].valid_encoding? end @@ -131,4 +132,8 @@ class Speech < ActiveRecord::Base self.content + "\n" end + def feed + ERB::Util.html_escape(self.content) + end + end diff --git a/app/views/panels/_form.html.erb b/app/views/panels/_form.html.erb index 7b945e89..f99dd66b 100644 --- a/app/views/panels/_form.html.erb +++ b/app/views/panels/_form.html.erb @@ -121,7 +121,16 @@
<% @panel.panel_elements.each do |elm| %>
- <%= h elm.plain_scenario -%> + <% case elm.class.to_s %> + <% when 'PanelPicture' %> + <%= render 'panel_pictures/scenario', :panel_picture => elm %> + <% when 'SpeechBalloon' %> + <%= render elm.speech_balloon_template.engine_name + '/speech_balloons/scenario', :speech_balloon => elm %> + <% when 'GroundPicture' %> + <%= render 'ground_pictures/scenario', :ground_picture => elm %> + <% when 'GroundColor' %> + <%= render 'ground_colors/scenario', :ground_color => elm %> + <% end %>
<% end %>
diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 2a201d44..f61767f8 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -126,6 +126,7 @@ ja: resize: はサイズを変更できません。 reverse: は反転できません。 sync_vh: は縦横比を変更できません。 + quotes_even: はカッコの開きと閉じを空白区切りのペアで入力してください。 template: body: 次の項目を確認してください。 header: diff --git a/db/migrate/20130709074533_add_quotes_on_speeches.rb b/db/migrate/20130709074533_add_quotes_on_speeches.rb new file mode 100644 index 00000000..f514507c --- /dev/null +++ b/db/migrate/20130709074533_add_quotes_on_speeches.rb @@ -0,0 +1,9 @@ +class AddQuotesOnSpeeches < ActiveRecord::Migration + def up + add_column :speeches, :quotes, :string, :limit => 15, :default => "' '" + end + + def down + remove_column :speeches, :quotes + end +end diff --git a/lib/validators/quotes_even_validator.rb b/lib/validators/quotes_even_validator.rb new file mode 100644 index 00000000..0c60d5f6 --- /dev/null +++ b/lib/validators/quotes_even_validator.rb @@ -0,0 +1,6 @@ +class QuotesEvenValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + record.errors[attribute] << (options[:message] || I18n.t('activerecord.errors.messages.quotes_even')) if value.to_s.split(/ /).size.odd? + end +end + diff --git a/spec/models/speech_spec.rb b/spec/models/speech_spec.rb index 489a9a2c..dfeb35b4 100644 --- a/spec/models/speech_spec.rb +++ b/spec/models/speech_spec.rb @@ -31,6 +31,7 @@ describe Speech do @speech.y = 0 @speech.width = 1 @speech.height = 1 + @speech.quotes = '' @speech.should be_valid end it '上限データが通る' do @@ -38,6 +39,7 @@ describe Speech do @speech.y = 99999 @speech.width = 99999 @speech.height = 99999 + @speech.quotes = '[ ] [ ] [ ] [ ]' @speech.should be_valid end end @@ -127,6 +129,16 @@ describe Speech do @speech.should_not be_valid end end + context 'quotesを検証するとき' do + it '奇数なら失敗する' do + @speech.quotes = '[ ] [' + @speech.should_not be_valid + end + it '16文字以上なら失敗する' do + @speech.quotes = '[ ] [ ] [ ] [ ] [ ]' + @speech.should_not be_valid + end + end context 'settingsを検証するとき' do end end @@ -147,6 +159,15 @@ describe Speech do end end + context 'quotesを検証するとき' do + it 'Shift JISなら失敗する' do + @speech.quotes = "\x83G \x83r \x83 ]\x83D" + lambda{ + @speech.valid_encode + }.should raise_error(Pettanr::BadRequest) + end + end + context 'settingsを検証するとき' do it 'Shift JISなら失敗する' do @speech.settings = "\x83G\x83r\x83]\x83D"