Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
0 answers
95 views

Using test_prof before_all recipe with manual connection switching in multiple db setup

I am using test-prof gem with before_all recipe to create all the necessary records for the suite and run a heavy service afterwards. Yet I'm running into a problem when a block of queries is executed ...
potashin's user avatar
  • 44.6k
0 votes
0 answers
36 views

RSpec test failing because of file field

When I test my Gallery Controller I get the following error: Failure/Error: expect(response).to redirect_to show_profile_show_profile_path Expected response to be a <3XX: redirect>, ...
cnks's user avatar
  • 81
0 votes
1 answer
68 views

How to prevent ActiveRecord from making an associated record in a callback before it is saved?

I have two models, Branch and Organization. An organization has many branches. A branch cannot exist without an associated organization, and an organization cannot exist without at least one branch. ...
lull's user avatar
  • 23
1 vote
0 answers
222 views

RSpec: Looks like tests connect to the default reading role always

i have a model definition like below class ExternalRecord < ApplicationRecord self.abstract_class = true connects_to database: { writing: :main, reading: :main, main: :main, ...
opensource-developer's user avatar
-1 votes
2 answers
147 views

Is testing relations in Rails considered to be a best practice? [closed]

Wondering if testing of a relations in Rails widely considered to be a best practice or not. We have disagreement on the team on testing relations. IMO it's redundant, i.e. to have each has_many :...
Handsome Jack's user avatar
0 votes
2 answers
415 views

Rspec does not execute a "before_destroy" callback

In my book model, I have a "before_destroy" callback (with a potentially ugly method) as follows: before_destroy :destroy_fallback private def destroy_fallback unless self....
tkhobbes's user avatar
  • 682
0 votes
1 answer
38 views

Why can't you pass a variable containing an array of "row objects" to the .excluding/.where.not method in Rails?

I'm currently learning ActiveRecord and working through some testing drills in RSpec. An abbreviated version of the test that is tripping me up is below. I can make it pass by changing the results ...
Brenna S's user avatar
0 votes
1 answer
158 views

Assert ActiveRecord method is called through class method with RSpec

I'm stumped on what appears to be a fairly simple thing I'd like to do. I've got a pretty simple class: class User def self.find_by_search(query) query = query.to_s.strip if query.upcase....
Tomizechsterson's user avatar
0 votes
0 answers
52 views

Obejct is keeping association after change foreing key at Rspec example

I'm trying to merge two or more registers with their associations for example: worker.files.count #3, notice that worker has_many: files (dependent_destroy association) and file model belongs to ...
MJCune's user avatar
  • 11
0 votes
0 answers
303 views

ActiveRecord::QueryMethods not working within rspec test but in console it working fine

I have a test where I want to test that a book_group cannot delete when is associated with a book, this test failed but in the application, this feature works fine describe 'callbacks' do context '...
Andres23Ramirez's user avatar
0 votes
1 answer
387 views

How to correctly check if a result set is ActiveRecord::Associations::CollectionProxy

I want to check if my result set is of type ActiveRecord::Associations::CollectionProxy for example my models are as follows class Dashboard < ApplicationRecord has_and_belongs_to_many :...
opensource-developer's user avatar
0 votes
2 answers
1k views

How to expect raise ActiveRecord::RecordNotFound rspec?

How to get the test pass for this error? Rspec controller and result context 'invalid confirmation_token' do subject do post signup_step5_path, params: { user:...
user avatar
0 votes
1 answer
233 views

Rspec DB View Is Empty

I created a LeadIndex view within my Rails application that is based on my Lead model. When running my test suite (Rspec) the table (db view) is recognized but returns as an empty [] of LeadIndex::...
Hash G's user avatar
  • 125
2 votes
1 answer
3k views

PG::UndefinedColumn: ERROR: column courts.user_id does not exist

This is the error I receive when I run a test for this file. The error is in line 83 when I attempt to remove the user from the database using the 'destroy' method. This is the repo in question frozen ...
Ivan Derlich's user avatar
0 votes
2 answers
1k views

Rails testing with RSpec double: ActiveRecord::AssociationTypeMismatch:

I am new to RSpec (not very experienced yet with RoR neither!) I am working on a web app where I have a Course model. To create a new Course I need to use Teacher and Student objects. I want to create ...
Francois Dumas Lattaque's user avatar
0 votes
1 answer
163 views

How to skip the method of a callback in rspec when there is no method name?

I have some callbacks like this: after_destroy :send_email And I can skip them in Rspec passing the name: Model.skip_callback(:destroy, :after, :send_email) But what if I have something like: ...
AlbertMunichMar's user avatar
0 votes
1 answer
289 views

expected ActiveRecord::RecordNotFound but nothing was raised

How to get the test pass for this error? Rspec result **2) Api::V1::UsersController GET #show - a user it fails showing a user Failure/Error: expect do get 'show', params: { id: 2 } end.to ...
Gonza's user avatar
  • 107
0 votes
1 answer
522 views

Using where.not in rspec should_receive

I am trying to test the parameters to where.not by rspec but am unable to find the function that is used to make the call on the Active Record. Can anyone tell me how to mock where.not for a class in ...
Prabhjot Singh Rai's user avatar
2 votes
1 answer
848 views

Migration not executed from rspec

I created the following migration script (using bundle exec rails generate migration CreateSequenceStudentId): class CreateSequenceStudentId < ActiveRecord::Migration[6.0] def change # Based ...
Ram's user avatar
  • 917
2 votes
1 answer
126 views

Test case with enum requires key after upgrade Rails from v4 to v5

I am in the process of upgrading my Rails app from v4 to v5. When I run the tests, some of them fail which used to pass before. For instance, (enum) enum session_type: {regular: 0, demo: 1, ...
anz's user avatar
  • 1,032
0 votes
1 answer
537 views

Rails Active Record: has_many using custom id's

I am creating a referral system. My goal is to refer to an object by a unique id rather than a Rails' custom id. These are my following models: class User < ApplicationRecord set_primary_key :...
John's user avatar
  • 1
1 vote
1 answer
344 views

after upgrading to rails 5.1.7 have an error ArgumentError: invalid argument: nil

after upgrading to rails 5.1.7 have an error ArgumentError: invalid argument: nil. tests: describe 'default_for scope' do it 'joins intel_tags' do scope = IntelTagging.default_for('...
ABA's user avatar
  • 59
2 votes
1 answer
2k views

No connection pool with 'primary' found for RSpec

I have a fresh Rails 6 codebase with a pg database and am getting an error when trying to run a simple rspec test. What might be the issue here? 1) SomeModel Object Itself sets the name correctly ...
stk1234's user avatar
  • 1,096
0 votes
0 answers
44 views

Why is this model's association disappearing from the test once the assertion is made (after a rails 5.1 > 5.2 upgrade)?

I have a model in this application that tracks role changes. The test I'm about to describe has been passing for the last couple years no problem and only starting failing as I upgraded the rails ...
Justus Eapen's user avatar
  • 1,149
2 votes
1 answer
326 views

How to prevent RSpec from running specs twice in Rails plugin with dummy app?

I'm writing a Rails extension. To test it, I use RSpec. In order to make models to test the plugin on, I use a pregenerated dummy app: rails plugin new yaffle --dummy-path=spec/dummy --skip-test --...
Steve Redka's user avatar
1 vote
1 answer
226 views

Rspec failure: Coupon.increment_counter not incrementing the record value

Why would this be failing? How do I correct the rspec test or my code? MODEL class Coupon < ApplicationRecord def redeem! Coupon.increment_counter(:times_redeemed, self.id) end end Rspec ...
user2012677's user avatar
  • 5,725
0 votes
2 answers
434 views

AssociationTypeMismatch but `expected` and `got` are the same class with the same object id

This is a rails application. Rails 5.1, Rspec 3.6. I have a failing test in my Rspec test suite and I cannot understand the error message. As far as I can see, the association expects and gets exactly ...
Sam J's user avatar
  • 75
1 vote
0 answers
379 views

ActiveStorage file in a spec : ActiveRecord::LockWaitTimeout

Yesterday I had a stub problem, which turns out to be an ActiveStorage problem. I work on a system that stores cached data with ActiveStorage. We are using Rails 5.2.3 with the multiverse gem. I want ...
Ruff9's user avatar
  • 1,192
1 vote
2 answers
368 views

Why does my production logs show an ActiveRecord::RecordNotUnique error but my local binding.pry shows me an ActiveModel::Errors?

I have a signup form that contains validations on the model and database to prevent duplicate entries. I use honeybadger in production for my error logging. When a user attempts to sign up with the ...
wheresmyspaceship's user avatar
1 vote
1 answer
1k views

uninitialized constant ApplicationRecord rspec

1) created a model called Skill 2) ran some seeds 3) ran rspec --init 4) created file skill_spec.rb with the code below require_relative "../app/models/skill" describe Skill do describe "...
Naoki Mi's user avatar
0 votes
1 answer
890 views

ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException "DESC tablename, does it exist?" error while running migrations for test setup

I am trying to setup database in test environment. But I am not able to migrate the database I looked on internet for hours. Even though this is a common problem, none of the solutions provided ...
Moriarty's user avatar
  • 159
1 vote
2 answers
2k views

ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base with mongoid

I have a Rails 4.2.8 app, ruby 2.4.4 with a Mongo database, using the mongoid ODB. I want to run tests against this application using rspec. The most basic test gives me this error: ActiveRecord::...
ypicard's user avatar
  • 3,693
0 votes
1 answer
1k views

after_destroy callback claims object still exists

I have an after_destroy callback that I'd expect to return nil but instead still has a value. class WeighIn < ActiveRecord::Base belongs_to :check_in after_destroy :add_employee_weightloss ...
Jeremy Thomas's user avatar
0 votes
3 answers
2k views

How to test if an ActiveRecord association is being used with RSpec?

What is the best way to see if their Active Record associations are no longer being used? How can I write a rspec test to see if the association is no longer being used? I have to refactor someone ...
sarri xx's user avatar
1 vote
2 answers
2k views

Foreign key constraint issue with uniqueness validation test

Running Rails 4.2.8 I've added a new model with a foreign_key of user_id. While functionally everything seems to work fine, when I run a test confirming the uniqueness validation of user_id I am ...
Tony Beninate's user avatar
0 votes
2 answers
1k views

How to run migrations for test suite.

I have a ruby app that uses ActiveRecord and sqllite. I am trying to write tests but I get this error: Failure/Error: user = described_class.create(name: name) ActiveRecord::StatementInvalid: ...
Kayla Fitzgerald's user avatar
0 votes
1 answer
357 views

rails/rspec: Fabricator - testing associations (ActiveModel::MissingAttributeError)

I am writing tests for my models and came across an error I can't seem to resolve. I'm using rspec and Fabricator. Things work fine when being tested in isolation but when I try to test for ...
Joanna Gaudyn's user avatar
1 vote
1 answer
876 views

NoMethodError: undefined method `stub!' for nil:NilClass

I'm trying to put the rspec for active link condition present in the application_helper.rb. Application_helper.rb code: def active_class(link_path) current_page?(link_path) ? 'active' : '' end ...
Renusudhan's user avatar
0 votes
1 answer
42 views

Why is ActiveRecord creating different ruby object when querying the same record?

I'm trying to test a named scope in my Rails model with RSpec using FactoryBot. I'm creating several records, where only one is returned by the scope. RSpec.describe GemNamespace::GemModel, type: :...
istrasci's user avatar
  • 1,351
0 votes
2 answers
485 views

How to disable ActiveRecord::Migration verbosity?

In short I want to remove the display of the ActiveRecord::Migration.create_table and drop_table functions that I use in an spec file, how can I do that ? (I answered myself, but I still thinks its a ...
rlaures's user avatar
  • 335
-1 votes
1 answer
101 views

build record with has_many through association, no db

In the context of testing a method not querying the db when given a preloaded relation, I would like to build a record with preloaded associations. I run into trouble when trying to build a record ...
Matthias Michael Engh's user avatar
0 votes
0 answers
695 views

Rspec test association with change matcher

I have a model User that updates a global role (from Rolify) with an after_save callback. I'm trying to test that the user's Permissions (a db view) are preserved when a global role is changed. ...
mindlis's user avatar
  • 1,647
1 vote
1 answer
87 views

Rails custom model validator fails rspec tests

I have a custom validator to verify the content of 2 fields in my database. When I use it through my UI, it works fine, however my rspec tests are failing and I can't understand why. Here is the ...
Godzilla74's user avatar
  • 2,482
0 votes
0 answers
1k views

In RSpec, how to test with an instance variable in the initialize method?

I have a class with the following initialized method to cache all users from the database: class Student < People def initialize super @all_users = Hash[User.pluck(:name, :id)] ...
CiCi's user avatar
  • 31
1 vote
1 answer
498 views

ConstraintException does not raise in rspec

I want to write a test that handles FOREIGN KEY constraint error when deleting a record, but ConstraintException is not raised. the table's schema like below class CreateCountries < ActiveRecord::...
Masamoto Miyata's user avatar
2 votes
1 answer
950 views

ActiveRecord could not connect to database server when running Rspec

So I'm running rspec tests with jruby-1.7.16.1 after completing a bundle install, and they are all failing to the same error: Failure/Error: Unable to find arjdbc/jdbc/RubyJdbcConnection.java to ...
Sean Raia's user avatar
0 votes
2 answers
49 views

Unable to run ruby spec tests of rails app backed by neo4j

I have recently inherited a rails app backed by neo4j instead of postgres. When I try to run the spec tests like this NEO4J_TYPE=bolt NEO4J_URL="bolt://localhost" bundle exec rake spec I get /...
american-ninja-warrior's user avatar
3 votes
0 answers
542 views

rails rspec stubbed ActiveRecord::Relation for ActiveRecord Serialize

can I stub ActiveRecord::Relation for ActiveRecord Serialize !? I could stub ActiveRecord::Relation .. but it doesn't work for ActiveRecord Serialize ! In my controller, I have sth like this: @res =...
Yaman ALTareh's user avatar
0 votes
1 answer
2k views

Rails Rspec - ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction:

I have this controller method def dashboard method1 method2 method3 .. end Everything is working fine in development environment.. but in test environment, i am getting this error after first ...
Sachin srinivasan's user avatar
1 vote
1 answer
1k views

RSpec has_many through #<ActiveRecord::Associations::CollectionProxy>

I have a has many through relationship model like this: class Physician < ApplicationRecord has_many :appointments has_many :patients, through: :appointments end class Appointment < ...
nrmb's user avatar
  • 490

1
2 3 4 5
7