...result.to_d(0) is the required precision parameter, which is applied to the BigDecimal return value. Using Rationals has some pitfalls you should be aware of: Multiplying a Rational with...
...entire layout will probably also contain that text (in a descendant) and Capybara will return it. See Find the innermost DOM element that contains a given string. Footnotes
Furthermore, you can add a "modifier" to the percent notation to control the return type of the expression: %s Symbol %i Array of Symbols %q String
Ruby's __FILE__ keyword returns the path to the current file. On popular for this are Ruby binaries: #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) require 'my_cli'
...which's expected name is hard coded. A popular example is extension_allowlist, which returns an array of strings and let's you only upload files that have a filename...
...Project.find_each do |project| project.recalculate_statistics! end Both find_in_batches and find_each return records ordered by ID because they need to be able to iterate in batches. Modern...
...your browser window for 10 seconds. The reason is that evaluate_script will always return a result. The return value will be converted back to Ruby objects, which in case...
...offense for rule "space-before-blocks" [#180343876] Fix ESLint offense for rule "no-useless-return" [#180343876] Add ESLint without any offenses
...classic "unit tests" where you instantiate an object, call a method and observe its return value or side effects. Your MovieDB already uses the gem rspec-rails which has many...
If the given ID was not found, a redirect to /movies is returned. The HTTP status 307 is used for the redirect. The movies index shows a flash...
...rescue ActionController::ParameterMissing {} end def note_scope # Restrict what the user may access by returning a scope with conditions. Note.all end def load_notes @notes ||= note_scope .strict_loading # Raise...
...preloaded will raise an ActiveRecord::StrictLoadingViolationError. There is a private method #note_params that returns a permitted attributes hash that can be set through the #update and #create actions.
...path(path, expires_at = 2.hours.from_now, allow_fuzzy_expiry: true, secret: Rails.application.secrets.url_signature_secret) return unless path uri = URI.parse(path) if allow_fuzzy_expiry expires_at = expires_at.end_of_hour...
...never create a new object in an implicit conversion method. This method should either return self or not be implemented at all. Obviously, this is the reason behind this recent...
...The more tests you already have, the less useful an additional test becomes ("Diminishing returns"). Tests sometimes fail even though the code is fine, especially when the test is coupled...
}, "last_data_send_time" : null, tells me, that this process did not return any data to the client "path" : "/admin/search_user?query=4", shows me the request caused the...
To return non-HTML responses (like XLS spreadsheets), we usually use the respond_to do |format| format.xls do # send spreadsheet end end This is often, but not always the same...
...redirect_to @movie # else # render 'new' # end render plain: params.inspect end Note that #inspect returns a human-readable representation of an object. All Ruby objects implement this. Submit the new...
...than calling other step definitions. Because you are using plain ruby, you can use return values, structured arguments (e.g. hash options), etc. I often have files like the session_steps.rb (below...
...Yarn requires Node.js 4.0 or higher to be installed. Check if command -v "node" returns a path and you load NVM before Yarn. This could look like this:
...the component. Use Jasmine spies to mock the window.fetch() method, inspect its calls and return a promise for a Response...
...in a central place makes your code DRY. E.g. Movie.human_attribute_name(:title) will return the title translation from activerecord.attributes.movie.title. Browse through the locale files of a recent sample app...
...it will wait for any beforeunload to be handled before e.g. a page.refresh statement returns. That that this also applies to wrapped calls like accept_confirm { page.refresh }. Recommendation
...order of test-writing and implementation is up to you. When you're done, return to writing the code. The specced thing now exists, so you can continue making that...
Class Rectangle with properties width and height. It offers an area method that returns the product of width and height. Write an average function that takes an arbitrary number...
config.before_send = lambda do |event, hint| log_sentry_event(event, hint) event # Return event so it can be processed by dummy DummyTransport end end Then add this helper...