diff --git a/lib/repost/senpai.rb b/lib/repost/senpai.rb index f535e90..4885498 100644 --- a/lib/repost/senpai.rb +++ b/lib/repost/senpai.rb @@ -35,7 +35,7 @@ def perform :submit_text, :authenticity_token, :charset, :autosubmit_nonce def form_head - "
" + %Q() end def form_body @@ -57,29 +57,29 @@ def form_input(key, value) form_input("#{key}[]", inner_value) end.join else - "" + %Q() end end def form_footer - "
" + %Q() end def csrf_token - "" + %Q() end def no_script - ") end def submit_section - "
+ %Q(
#{section_html} - -
" + +
) end def generated_form_id @@ -88,14 +88,14 @@ def generated_form_id def auto_submit_script nonce_attr = %Q( nonce="#{autosubmit_nonce}") if autosubmit_nonce - " - document.getElementById('#{form_id}').submit(); - " + %Q( + document.getElementById("#{form_id}").submit(); + ) end def process_value(value) return value if value.is_a?(Integer) - '\'' + value.to_s + '\'' + %Q("#{value.to_s.gsub("\"", '\'')}") end end end diff --git a/spec/senpai_spec.rb b/spec/senpai_spec.rb index 4fcf774..5091239 100644 --- a/spec/senpai_spec.rb +++ b/spec/senpai_spec.rb @@ -8,7 +8,7 @@ aggregate_failures do expect(html).to include('form') expect(html).to include(url) - expect(html).to include("type='submit'") + expect(html).to include("type=\"submit\"") end end @@ -24,7 +24,9 @@ count: 696, string_size: '234', boolean: true, - string_boolean: 'false' + string_boolean: 'false', + quoted_string: "Tuan O'Keefe", + double_quoted_string: "Sam O\"Daren" } end @@ -32,14 +34,17 @@ it 'generates post form' do aggregate_failures do - expect(html).to include("input type='hidden'") - expect(html).to include("value='#{params[:name]}'") - expect(html).to include("value='#{params[:description]}'") - expect(html).to include("value='#{params[:string_size]}'") - expect(html).to include("value='#{params[:string_boolean]}'") + puts html + expect(html).to include("input type=\"hidden\"") + expect(html).to include("value=\"#{params[:name]}\"") + expect(html).to include("value=\"#{params[:description]}\"") + expect(html).to include("value=\"#{params[:string_size]}\"") + expect(html).to include("value=\"#{params[:string_boolean]}\"") + expect(html).to include("value=\"#{params[:quoted_string]}\"") + expect(html).to include("value=\"#{params[:double_quoted_string].gsub("\"", "\'")}\"") expect(html).to include("value=#{params[:count]}") - expect(html).to include("value='#{params[:boolean]}'") + expect(html).to include("value=\"#{params[:boolean]}\"") end end @@ -58,13 +63,13 @@ it 'handles arbitrarily nested params' do aggregate_failures do - expect(html).to include("name='top_level[top_level_item]' value='hello'") - expect(html).to include("name='top_level[second_level][third_level]' value='qwerty'") - expect(html).to include("name='top_level[second_level][array][]' value=1") - expect(html).to include("name='top_level[second_level][array][]' value=2") - expect(html).to include("name='top_level[second_level][array][]' value='3'") - expect(html).to include("name='top_level[second_level][array][][a]' value=4") - expect(html).to include("name='top_level[second_level][array][][b]' value='5'") + expect(html).to include("name=\"top_level[top_level_item]\" value=\"hello\"") + expect(html).to include("name=\"top_level[second_level][third_level]\" value=\"qwerty\"") + expect(html).to include("name=\"top_level[second_level][array][]\" value=1") + expect(html).to include("name=\"top_level[second_level][array][]\" value=2") + expect(html).to include("name=\"top_level[second_level][array][]\" value=\"3\"") + expect(html).to include("name=\"top_level[second_level][array][][a]\" value=4") + expect(html).to include("name=\"top_level[second_level][array][][b]\" value=\"5\"") end end end @@ -81,8 +86,8 @@ it 'handles enumerable params' do aggregate_failures do - expect(html).to include("name='multi_item[]' value='hello'") - expect(html).to include("name='second_level[multi_item][]' value='qwerty'") + expect(html).to include("name=\"multi_item[]\" value=\"hello\"") + expect(html).to include("name=\"second_level[multi_item][]\" value=\"qwerty\"") end end end