You can not use the hash_including argument matcher with a nested hash: describe 'user' do let(:user) { {id: 1, name: 'Foo', thread: {id: 1, title: 'Bar'} } it do
...user).to match( hash_including( id: 1, thread: {id: 1} ) ) end end The example will fail and returns a not very helpful error message: expected {:id => 1, :name => "Foo", :thread...
...the filename "([^\"]*)"$/ do |filename| patiently do match = page.all('img').find do |img| img[:src].include?("/#{filename}") end expect(match).to be_present end end Note that the check needs to...
...helper since the DOM might change between page.all('img') and the check img[:src].include?, causing a Selenium::WebDriver::Error::StaleElementReferenceError. If you can express a check in a readable...
Consul 0.6.1+ gives you a way to dynamically access and query powers for a given name, model class or record...
When you eagerly load an association list using the .include option, and at the same time have a .where on an included table, two things happen: Rails tries to load...
...the activity from above now suddenly no longer contains any other users: activity = Activity. .includes(:users) .where(users: { id: [4] }) .find(42) activity.users.ids # here happens the unexpected # => [4]
...as simple as I could. More often than not, real JSON endpoints may also include data from (hopefully preloaded) associated records or data that needs to be transformed at render...
Inspect the record scope that is used to generate the JSON. Does scope.explain include a reference to an index it's using? Does it come with an ORDER that...
...of the given parent's descendants matching the given selector. The list will also include the parent element if it matches the selector itself. up.element.closest() Returns the first element that...
...could have happened earlier. Recommendation for our projects New projects New projects should not include jQuery Use a Polyfill like dom4 to normalize browser support Use up.element, Umbrella.js oder even...
...the plugin being installed and in the end wasn't sure if it was included in the standard image or not. With the above command, it will be installed, if...
...it is not already included. In your docker-compose.yml add: opensearch: image: registry.makandra.de/makandra/my-project/opensearch:1.0 build: ./docker/opensearch command: ["./opensearch-docker-entrypoint.sh", "-Ediscovery.type=single-node"] ports: - "127.0.0.1:9200:9200" environment: - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m...
...Usage in RSpec feature specs Copy the DownloadHelpers module to spec/support. You can now include the helper in all your feature specs: RSpec.configure do |config| config.include(DownloadHelpers, type: :feature)
...Usage in Cucumber scenarios Copy the DownloadHelpers module to features/support. Then include the helper in your scenarios and define some step definitions: World(DownloadHelpers) When('I download {string}') do |locator...
...e.g. the superclass of the superclass): ActiveRecord::RecordNotFound.ancestors.include?(StandardError) # => true Note that ancestors also includes the receiving class itself as well as any included modules (which is quite practical for...
Let's have a look at the internal transformation process of ffmpeg. It includes (de)muxing packets and de/encoding frames to keep everything in sync. The ASCII illustration is...
...Video Playback" section). The result can be verified with ffmpeg -i output.mp4 and should include lines similar to these: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
Expected [...] to contain exactly "XXX" ActiveRecord::Base is monkey patched by super_diff/rspec-rails (includes rspec and rails) super_diff/rails (includes active_record and active_support) super_diff/active_record
...mail (or even password reset e-mail), or something similar. The e-mail also includes some reflected text. For example, a user may be able to give their name, and...
...is used within the e-mail. The spammer will then abuse that text to include his advertisment. Potential counter measures are: Add a captcha. Rate limit the sign-up or...
...testing uncomfortable. Automatic insertion of soft hyphens You can use JavaScript libraries like hypher (includes LGPL patterns!) to automatically insert soft hyphens into the text of a DOM node.
...language like URLs or source code. Unlike soft hyphens a tag will not be included in the clipboard when copying text. Option 4: overflow-wrap CSS property
...models to another model (or split a model into different new models). If this includes a lot of associated records, it may not be wise to try to do it...
...being sent to the user. Vary: Accept in Rails Vary: Accept is unfortunately not included by default in Rails < 6.1. That is a bug and differs from the HTTP-specification...
...in RFC 2616 14.44 which states: An HTTP/1.1 server SHOULD include a Vary header field with any cacheable response that is subject to server-driven negotiation. Doing so allows a...
...e.g. all attributes need to be present when initializing an object. Example: class User include ActiveModel::Attributes attribute :salutation attribute :first_name attribute :last_name attribute :street_and_number
...also works for more complex conditions, e.g. with ranges like where(created_at: 2.days.ago..), including orphan checks via where.missing(...). Important The inverted scope will not return rows where role is...
...for example for: Scopes using joins or similar, as where_values_hash does not include those. Conditions where values are ranges, e.g. where(created_at: 1.week.ago..) has an empty where...
Add zip_tricks to your Gemfile and bundle install. In your controller, include ZipTricks::RailsStreaming. You can then use the zip_tricks_stream method in controller actions to...
...own Last-Modified or ETag header to achieve that. Example controller: class DocumentsController < ApplicationController include ZipTricks::RailsStreaming def download documents = Document.all fresh_when Time.current # Sets `Last-Modified` header (see above...
Our applications not only need to be functional, they need to be fast. But, to quote Donald Knuth, premature optimization...
In FactoryBot factories, Rails' file_fixture is not available by default. To enable it, include a support module from rspec-rails: FactoryBot::SyntaxRunner.include(RSpec::Rails::FileFixtureSupport) That includes ActiveSupport::Testing...
...used (in development and tests)' do get 'http://www.example.com/test/set_cookie' response.headers['Set-Cookie'].should include('test=') # Cookie is still set response.headers['Set-Cookie'].should_not include('; Secure') end end
...will fail when trying to compile their assets up front. class ApplicationController < ActionController::Base include EsbuildErrorRendering if Rails.env.development? end module ApplicationController::EsbuildErrorRendering ESBUILD_ERROR = Rails.root.join("esbuild_error_#{Rails.env}.txt") # see...
...have an indefinitely high resolution). When ordering lists by timestamps, you should therefore always include a final order condition using the primary key of the table. class Photo < ActiveRecord::Base...
...scope :by_date, -> { order('created_at DESC, id DESC') } end Photo.by_date Remember to include the id field in the database index...
...you need to skip those items that are #marked_for_destruction?. Otherwise you will include items that have been ticked for deletion in a nested form. See ActiveRecord: When aggregating...