All Questions
8 questions
2
votes
1
answer
404
views
Rspec shoulda matcher test on activerecord model fails due to validation of associated model
My model has a validation concerning one of it's associated models. My rspec tests of the model are failing due to this validation.
describe NewOfferRange do
it { is_expected.to ...
1
vote
1
answer
119
views
Trouble writing test for validating uniqueness of value in my join table
A little while ago I was able to find a solution on how to create a uniqueness validation in my join table:
class Album < ApplicationRecord
has_many :album_artists
has_many :artists, through: :...
0
votes
1
answer
75
views
how to test rails custom validation
I have a custom validation that checks whether a param is valid JSON or not:
def is_valid_json
begin
!!JSON.parse(preferences)
rescue
errors.add(:preferences, "This is not valid ...
1
vote
1
answer
228
views
Rails inclusion validation failure
I have a model that contains two integer columns representing start_time and end_time. These times are represented by the minute offset for that day.
class Example < ActiveRecord::Base
...
1
vote
1
answer
500
views
ActiveRecord reporting a failed validation, but there are no validations defined
I'm just starting to use RSpec with a new project (after being a minitest user for a while). I've created a single MVC, called contracts. Here is the model file:
class Contract < ActiveRecord::...
5
votes
2
answers
7k
views
rspec - how to check that allow_blank exists
I have a test for uniqueness which works:
it { should validate_uniqueness_of(:name).case_insensitive }
however when I try to do a similar test for name it fails
it { should validate_presence_of(:...
29
votes
4
answers
22k
views
How to test which validation failed in ActiveRecord?
I have a model like this:
class User < ActiveRecord::Base
validates_length_of :name, :in => (2..5)
end
I want to test this validation:
it "should not allow too short name" do
u = User.new(...
1
vote
2
answers
2k
views
RoR, RSpec - problem with validation testing
Through rspec (I'm using rspec-1.3.0, rspec-rails-1.3.2 gems) generator (ruby script/generate rspec_model suggestion section_id:integer user_id:integer subject:string content:text state:string type:...