I recently updated my app, from doorkeeper 5.3.3 to 5.4.0 but changes to Doorkeeper::AccessToken.find_or_create_for were made apparently, but I can't find anything in the CHANGELOG
so
#access_token = Doorkeeper::AccessToken.find_or_create_for(
oauth_client,
model.user.id,
oauth_scopes,
oauth_expiry_time,
oauth_server.refresh_token_enabled?
)
returns now an ArgumentError
ArgumentError (wrong number of arguments (given 5, expected 0; required keywords: application, resource_owner, scopes)):
Has this also happened to anybody else?
Doorkeeper::AccessToken.find_or_create_for seems to expects keyword arguments instead of a simple list of arguments nowadays.
#access_token = Doorkeeper::AccessToken.find_or_create_for(
application: oauth_client,
resource_owner: model.user.id,
scopes: oauth_scopes,
expires_in: oauth_expiry_time,
use_refresh_token: oauth_server.refresh_token_enabled?
)
Related
I am really stuck. I am upgrading my Rails app to Ruby 3 (from 2.7). When running tests, I always run into this issue when I visit a path:
state = "new"
visit status_path(state: “state")
I receive the following error when running rspec:
Capybara starting Puma...
* Version 5.6.4 , codename: Birdie's Version
* Min threads: 0, max threads: 4
* Listening on http://127.0.0.1:58568
ArgumentError: wrong number of arguments (given 2, expected 1)
from ~/.rbenv/versions/3.0.5/lib/ruby/3.0.0/net/protocol.rb:116:in `initialize'
My Gemfile is as such:
gem "capybara" # 3.38.0
gem "selenium-webdriver" # 4.8.0
gem "webdrivers" # 5.2.0
(They're all on the latest version)
My setup doesn't look wrong:
require "webdrivers/chromedriver"
Webdrivers.cache_time = 86_400 # 1 day
Capybara.register_driver :headless_chrome do |app|
Capybara::Selenium::Driver.load_selenium
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |options|
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
end
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
Capybara.javascript_driver = :headless_chrome
Troubleshooting:
I tried Puma 6 - same issue.
The controllers at status_path is not even hit. This errors occurs right after Puma loads up.
I do not think it's the Capybara setup, and I just cannot find where it is calling the Ruby 3 library wrong (net/protocol).
I downgraded capybara to 3.37.1, and same issue.
Thank you
FYI Upgrading from 2.7 to 3 you will more often than not see this error. It's highly likely that some code you were previously using in 2.7 will be not correctly hashing some args.
The first hit when googling this will take you back to SO (Won't share link as SO doesn't like links). But to paraphrase from the official ruby byline when updating
Separation of positional and keyword arguments in Ruby 3.0:
In most cases, you can avoid incompatibility by adding the double splat operator. It explicitly specifies passing keyword arguments instead of a Hash object. Likewise, you may add braces {} to explicitly pass a Hash object, instead of keyword arguments.
TL;DR - Try doing splatting your hash args collection kwargs -> **kwargs - Your rails path likely isn't a kwarg but a hash --> { key: value }
EDIT: Reasoning (If you're interested), is that prior to ruby3. Ruby would try assess and guesstimate what you meant. From ruby3 onwards it has made a change and fill forcibly use what you give it (A lot of people used to use kwargs but wanted them treated as a single hash, now you need to stipulate this!)
I am currently trying to SearchResult query in kuzzle android sdk earlier it was working but after upgrading the version I have an error when I perform SearchResult I get following error : java.util.concurrent.ExecutionException: io.kuzzle.sdk.Exceptions.ApiErrorException: Wrong type for argument "from" (expected: integer)
Any idea of the reason ? Thanks
Actually the error message gives you the answer: Wrong type for argument "from" (expected: integer)
I suspect that your from argument is not an integer type.
Since upgrading to Rails 5 I have a query that is not working. It is unable to get results from a table by its alias. The error is that "from" takes zero arguments now. The version of arel is 9.0, the version of Rails is 5.2.4.3
offers = Offer.arel_table
o2 = offers.alias("o2")
seen_offers = offers.from("offers as o2").project(o2[:merchant_id], o2[:display_name])
this is the error:
ArgumentError: wrong number of arguments (given 1, expected 0)
Arel::Table#from takes 0 arguments because it generates a SelectManager:
SelectManager.new(self)
What you are looking for is SelectManager#from and the issue is easily correctable (just switch the project and the from)
offers.project(o2[:merchant_id], o2[:display_name]).from(o2)
project will return a SelectManager and then from will simply change the source
On the redmine of my company, there is this bug where I get an internal error if I want to search into a project.
Here is the log corresponding to the error:
Processing by SearchController#index as HTML
Parameters: {"utf8"=>"✓", "issues"=>"1", "q"=>"test", "id"=>"sprint"}
Current user: me (id=60)
Completed 500 Internal Server Error in 85.0ms
TypeError (no implicit conversion of nil into String):
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb:126:in `search'
app/controllers/search_controller.rb:74:in `block in index'
app/controllers/search_controller.rb:73:in `each'
app/controllers/search_controller.rb:73:in `index'
The lines corresponding to the error in the controller are :
if !#tokens.empty?
# no more than 5 tokens to search for
#tokens.slice! 5..-1 if #tokens.size > 5
#results = []
#results_by_type = Hash.new {|h,k| h[k] = 0}
limit = 10
#scope.each do |s|
r, c = s.singularize.camelcase.constantize.search(#tokens, projects_to_search,
:all_words => #all_words,
:titles_only => #titles_only,
:limit => (limit+1),
:offset => offset,
:before => params[:previous].nil?)
#results += r
Here is my config :
Environment:
Redmine version 2.6.9.stable
Ruby version 2.3.0-p0 (2015-12-25) [x86_64-linux]
Rails version 3.2.22
Environment production
Database adapter PostgreSQL
SCM:
Git 1.9.1
Filesystem
Redmine plugins:
no plugin installed
What is interesting is that when I search only one letter, i'm redirected on the search page, but I don't have an internal error.
I'm very new to Redmine developpement and to Ruby, I was just assigned to try to fix this bug. Do any of you have an idea of how to fix it ?
Thanks.
I had the same issue, I was able to fix it by downgrading my ruby & rails version, a working set is :
Rails 3.2.19
Ruby 2.1.4p265
It's look like it's due to a braking change in ruby-2.3.0.
It's really odd. We are using 'Redmine' -2.0.3.1 and we do not have that kind of behaviour.
It seems that "someone" messed up the form linked to the search input. Try to follow that data from when you press enter until it answer you with the 500 error code.
If you can , change the environment to development, this way it will show you more detailed errors.
But I can't help you much more , you didn't provide enough info about the problem.
This all worked fine in rails 2.3.5, but when a contractor firm upgraded directly to 2.3.14 suddenly all the integration tests were saying:
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
I have a before_filter on my ApplicationController that sets a bunch of cookies for some javascript to use, and I found that if I comment out all but one of the lines that sets cookie values, it works fine, and it doesn't matter which line I leave in.
before_filter :set_cookies
def set_cookies
cookies['logged_in'] = (logged_in ? 'y' : 'n')
cookies['gets_premium'] = (gets_premium ? 'y' : 'n')
cookies['is_admin'] = (is_admin ? 'y' : 'n')
end
If only one of these lines is active, everything is fine in the integration test, otherwise I get the error above. For example, consider the following test / response:
test "foo" do
get '/'
end
$ ruby -I"lib:test" test/integration/foo_test.rb -n test_foo -v
Loaded suite test/integration/foo_test
Started
test_foo(FooTest): E
Finished in 5.112648 seconds.
1) Error:
test_foo(FooTest):
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
test/integration/foo_test.rb:269:in `test_foo'
1 tests, 0 assertions, 0 failures, 1 errors
But if any two of those cookie setting lines are commented out, I get:
$ ruby -I"lib:test" test/integration/foo_test.rb -n test_foo -v
Loaded suite test/integration/foo_test
Started
test_foo(FooTest): .
Finished in 1.780388 seconds.
1 tests, 0 assertions, 0 failures, 0 errors
The website running in development and production mode works fine - this is just a matter of getting the tests passing. Also, with debugging output I have verified that the error does not get thrown in the method where the cookies get set, that all executes fine, it's somewhere later that the error happens (but the backtrace doesn't tell me where)
This turned out to be a bug in how rack rack writes cookies to the client along with the session cookie. Rack was including double newlines and omitting semi-colons.
Browsers like firefox can handle mildly malformed cookie data, but the integration test client couldn't.
To fix this I had to rewrite the cookie header before sending it to the client.
In environment.rb:
require 'rack_rails_cookie_header_hack'
And in lib/rack_rails_cookie_header_hack.rb:
class RackRailsCookieHeaderHack
def initialize(app)
#app = app
end
def call(env)
status, headers, body = #app.call(env)
if headers['Set-Cookie']
cookies = headers['Set-Cookie']
cookies = cookies.split("\n") if is_str = cookies.is_a?(String)
if cookies.respond_to?(:collect!)
cookies.collect! { |h| h.strip }
cookies.delete_if { |h| h.empty? }
cookies.collect! { |h| h.include?(';') ? h : h + ';' }
end
headers['Set-Cookie'] = is_str ? cookies.join("\n").strip : cookies
end
[status, headers, body]
end
end
Sorry the sources aren't articulated, I actually fixed this awhile ago and came across this questions and figured I'd post my patch.
L0ne's answer works for me, but you also need to include this - it can go at the bottom of lib/rack_rails_cookie_header_hack.rb, providing you're requiring it at the bottom of your environment.rb file - ie after the Rails::Initializer has run:
ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, RackRailsCookieHeaderHack)
Old forgotten issues...
I haven't tested Lone's fix but he has correctly identified the problem. If you catch the exception and print using exception.backtrace, you'll see that the problem is caused by
gems/actionpack/lib/action_controller/integration.rb:329
The offending code is this:
cookies.each do |cookie|
name, value = cookie.match(/^([^=]*)=([^;]*);/)[1,2]
#cookies[name] = value
end
If you're like me, and you're only interested in some super quick integration tests, and don't care too much about future maintainability (since it's rails 2), then you can just add a conditional filter in that method
cookies.each do |cookie|
unless cookie.blank?
name, value = cookie.match(/^([^=]*)=([^;]*);/)[1,2]
#cookies[name] = value
end
end
and problem solved