Skip to content

Show changes in my rails_param pull request #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ruby "3.1.4"
gem "bootsnap", require: false
gem "puma", "~> 5.0"
gem "rails", "~> 7.0.8"
gem "rails_param"
gem "rails_param", git: "https://github.com/jlw/rails_param.git", branch: "allow-blank-non-string-non-required"
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

group :development, :test do
Expand Down
14 changes: 10 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/jlw/rails_param.git
revision: 315f6e8d3598ea2bd23d65edb226133cbd6c431c
branch: allow-blank-non-string-non-required
specs:
rails_param (1.3.1)
actionpack (>= 3.2.0)
activesupport (>= 3.2.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -155,9 +164,6 @@ GEM
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
rails_param (1.3.1)
actionpack (>= 3.2.0)
activesupport (>= 3.2.0)
railties (7.0.8)
actionpack (= 7.0.8)
activesupport (= 7.0.8)
Expand Down Expand Up @@ -222,7 +228,7 @@ DEPENDENCIES
debug
puma (~> 5.0)
rails (~> 7.0.8)
rails_param
rails_param!
rspec-rails
selenium-webdriver
tzinfo-data
Expand Down
49 changes: 8 additions & 41 deletions app/views/bars/_test_output.html.erb
Original file line number Diff line number Diff line change
@@ -1,54 +1,21 @@

bars search
<span class="f2"> handles GET searches</span>
<span class="f3"> handles GET searches without a user ID (PENDING: not handled by rails_param v1.3.1)
</span><span class="f2"> fails on GET searches without a user ID</span>
<span class="f2"> handles GET searches without a user ID</span>
<span class="f2"> fails on GET searches without a user ID</span>
<span class="f2"> handles POST searches</span>
<span class="f3"> handles POST searches without a user ID (PENDING: not handled by rails_param v1.3.1)
</span><span class="f2"> fails on POST searches without a user ID</span>
<span class="f2"> handles POST searches without a user ID</span>
<span class="f2"> fails on POST searches without a user ID</span>

/bars
<span class="f2"> handles searches with both options</span>
<span class="f2"> handles searches without a user ID</span>
<span class="f2"> handles searches without a null user ID</span>
<span class="f2"> rejects searches with an empty string user ID</span>
<span class="f2"> DOES NOT reject searches with an empty string user ID</span>
<span class="f2"> rejects searches with a string user ID</span>
<span class="f2"> rejects searches with a string user ID</span>
<span class="f2"> handles searches with just a user ID</span>

Pending: (Failures listed here are expected and do not affect your suite's status)

1) bars search handles GET searches without a user ID
<span class="f6"># not handled by rails_param v1.3.1</span>
<span class="f3">Failure/Error: param! :user_id, Integer</span>

<span class="f3">RailsParam::InvalidParameterError:</span>
<span class="f3"> '' is not a valid Integer</span>
<span class="f6"># ./app/controllers/bars_controller.rb:18:in `search_params'</span>
<span class="f6"># ./app/controllers/bars_controller.rb:5:in `search'</span>
<span class="f6"># ./spec/features/bars_spec.rb:22:in `block (3 levels) in &lt;top (required)&gt;'</span>
<span class="f6"># ./spec/features/bars_spec.rb:20:in `block (2 levels) in &lt;top (required)&gt;'</span>
<span class="f6"># ------------------</span>
<span class="f6"># --- Caused by: ---</span>
<span class="f6"># ArgumentError:</span>
<span class="f6"># invalid value for Integer(): &quot;&quot;</span>
<span class="f6"># ./app/controllers/bars_controller.rb:18:in `search_params'</span>

2) bars search handles POST searches without a user ID
<span class="f6"># not handled by rails_param v1.3.1</span>
<span class="f3">Failure/Error: param! :user_id, Integer</span>

<span class="f3">RailsParam::InvalidParameterError:</span>
<span class="f3"> '' is not a valid Integer</span>
<span class="f6"># ./app/controllers/bars_controller.rb:18:in `search_params'</span>
<span class="f6"># ./app/controllers/bars_controller.rb:5:in `search'</span>
<span class="f6"># ./spec/features/bars_spec.rb:55:in `block (3 levels) in &lt;top (required)&gt;'</span>
<span class="f6"># ./spec/features/bars_spec.rb:53:in `block (2 levels) in &lt;top (required)&gt;'</span>
<span class="f6"># ------------------</span>
<span class="f6"># --- Caused by: ---</span>
<span class="f6"># ArgumentError:</span>
<span class="f6"># invalid value for Integer(): &quot;&quot;</span>
<span class="f6"># ./app/controllers/bars_controller.rb:18:in `search_params'</span>

Finished in 0.06814 seconds (files took 0.64709 seconds to load)
<span class="f3">12 examples, 0 failures, 2 pending</span>
Finished in 0.12059 seconds (files took 0.64364 seconds to load)
<span class="f2">13 examples, 0 failures</span>

14 changes: 8 additions & 6 deletions spec/features/bars_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
end

it "handles GET searches without a user ID" do
pending "not handled by rails_param v1.3.1"

visit "/bars"
within "#get-search" do
fill_in "Foo", with: "fff"
Expand All @@ -30,8 +28,11 @@
visit "/bars"
within "#get-search" do
fill_in "Foo", with: "fff"
expect { click_on "Search" }.to raise_exception RailsParam::InvalidParameterError, "'' is not a valid Integer"
click_on "Search"
end

expect(page).to have_css("#param-foo", text: "“fff”")
expect(page).to have_css("#param-user-id", text: "“”")
end

it "handles POST searches" do
Expand All @@ -47,8 +48,6 @@
end

it "handles POST searches without a user ID" do
pending "not handled by rails_param v1.3.1"

visit "/bars"
within "#post-search" do
fill_in "Foo", with: "fff"
Expand All @@ -63,7 +62,10 @@
visit "/bars"
within "#post-search" do
fill_in "Foo", with: "fff"
expect { click_on "Search" }.to raise_exception RailsParam::InvalidParameterError, "'' is not a valid Integer"
click_on "Search"
end

expect(page).to have_css("#param-foo", text: "“fff”")
expect(page).to have_css("#param-user-id", text: "“”")
end
end
12 changes: 9 additions & 3 deletions spec/requests/bars_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@
expect(body).to eq(search_params: { foo: 'fff', user_id: nil })
end

it "rejects searches with an empty string user ID" do
expect { post '/bars/search', params: { foo: 'fff', user_id: '' }, as: :json }
.to raise_exception RailsParam::InvalidParameterError, "'' is not a valid Integer"
it "DOES NOT reject searches with an empty string user ID" do
post '/bars/search', params: { foo: 'fff', user_id: '' }, as: :json

expect(body).to eq(search_params: { foo: 'fff', user_id: nil })
end

it "rejects searches with a string user ID" do
expect { post '/bars/search', params: { foo: 'fff', user_id: 'abc' }, as: :json }
.to raise_exception RailsParam::InvalidParameterError, "'abc' is not a valid Integer"
end

it "rejects searches with a string user ID" do
Expand Down