shoulda Questions
4
Solved
I have the following validation in my ActiveRecord.
validates :active, :inclusion => {:in => ['Y', 'N']}
I am using the following to test my model validations.
should_not allow_value('A')...
Prohibit asked 14/9, 2011 at 11:34
2
In my device model, I have
enum device_type: { ios: 1 , android: 2 }
validates :device_type, presence: true, inclusion: { in: device_types.keys }
And in my device_spec.rb, I write some tests for...
Searby asked 28/12, 2015 at 15:13
3
I put the following code into an RSpec test:
it { should validate_format_of(:email).not_with('test@test')}
and setup the actual class with:
validates :email, :presence => true, :format =>...
Hypnotism asked 9/11, 2010 at 13:58
5
Solved
I am upgrading a Rails 2 to Rails 3 application (code not written by me).
The (well tested code) uses shoulda and Test::Unit, and extensively uses the macros should_create and should_change.
I und...
Vermicelli asked 4/2, 2011 at 17:59
2
Solved
I have a model
class Certificate < ApplicationRecord
notification_object
belongs_to :user
belongs_to :share_class, optional: true
belongs_to :round, optional: true
belongs_to :company, op...
Chesterton asked 9/1, 2019 at 16:26
5
Solved
I know you can easily test a belongs to relationship using Shoulda:
describe Dog dog
it { should belong_to(:owner) }
end
Is it possible to test a more complicated belongs_to relationship using ...
Housewife asked 2/9, 2012 at 8:15
2
Solved
I have a User model that has a child association of items. The :name of items should be unique for the user, but it should allow different users to have an item with the same name.
The Item model ...
10
Solved
The background: I'm having some problems with Thoughtbot's "Factory Girl" gem, with is used to create objects to use in unit and other tests. I'd like to go to the console and run different Factory...
Chiu asked 26/6, 2009 at 16:29
4
Solved
I have 3 models, user, game, and player. There's basically a many to many relationship between users and games, with players as the join table, except players have other info so it has its own mode...
Milled asked 28/4, 2013 at 21:32
3
Solved
I'm working on my first Ruby gem and have bundled cucumber, rspec and shoulda-matches for testing. When I run rspec, I get the following error:
/app/my_gem/spec/spec_helper.rb:6:in `<top (requ...
Alternation asked 14/4, 2015 at 15:47
2
I am testing the delete action of my resource controller as follows:
describe ResourceController do
context "DELETE destroy" do
before :each do
delete :destroy, id: @resource.id
end
it { shou...
Platt asked 3/3, 2012 at 8:2
1
Solved
I am trying to do some basic rspec testing with shoulda matchers and I've come upon an error I haven't seen asked on SO before.
I have a unique attribute called name, but for reasons required of t...
Deathful asked 14/10, 2016 at 22:40
1
Solved
I use rspec-rails with shoulda-matcher to test my model. Here is the code:
user_ticket.rb
class UserTicket < ActiveRecord::Base
belongs_to :user
belongs_to :ticket
enum relation_type: %w( ...
Lingam asked 5/9, 2016 at 7:47
4
Solved
I'm using Shoulda in combination with Test::Unit on one of the projects I work on. The issue I'm running into is that I recently changed this:
class MyModel < ActiveRecord::Base
validates_pres...
Endpaper asked 5/1, 2010 at 21:19
2
Solved
I have a Private methods in my model like the following:
validate :record_uniq
private
def record_uniq
if record_already_exists?
errors.add(:base, "already exists")
end
end
def record_al...
Antoniettaantonin asked 27/3, 2013 at 11:19
2
Solved
I have a shoulda matcher in my avatar_parts_spec.rb and I can't get it pass:
Test:
require 'rails_helper'
RSpec.describe AvatarPart, :type => :model do
it { should validate_presence_of(:name...
Olathe asked 20/11, 2014 at 18:18
2
Solved
What is the correct format for using shoulda-matchers and RSpec's new expect syntax?
2
Solved
I know that RSpec has the --profile option, but I'm only using MiniTest/shoulda for my current project.
Paterson asked 12/5, 2014 at 23:56
2
Solved
I have a method which compares if two text files have the same content.
How do I compare if two text files have the same content using RSpec?
3
Solved
In my Rails app, I make heavy use of subdirectories of the model directory and hence of namespaced models - that is, I have the following directory heirarchy:
models
|
+- base_game
| |
| +- foo.rb...
Piteous asked 29/7, 2011 at 14:40
1
Solved
How do I test this ActiveRecord relation using shoulda matchers?
Models
class User < ActiveRecord::Base
has_many :articles
end
class Article < ActiveRecord::Base
belongs_to :author, clas...
Sole asked 9/2, 2014 at 10:24
2
Solved
I am trying to figure out another way of writing the should change count test (without lambda).
I am using Rails 3. I am also utilizing the shoulda matcher gem
Reason - All test cases are in the f...
Frostbite asked 6/9, 2012 at 19:7
2
Solved
I have a before_validation :do_something, :on => :create in one of my models.
I want to test that this happens, and doesn't happen on :save.
Is there a succinct way to test this (using Rails 3...
Sik asked 6/4, 2011 at 8:37
1
One thing I've noticed is that in most of the projects I do, the one spec that always takes a long time (30 seconds +) is this shoulda/paperclip helper:
it { should validate_attachment_content_typ...
Resorcinol asked 16/11, 2011 at 4:50
1
Solved
I updated 'shoulda-matchers' in the Gemfile in my rails project from version 1.4.2 to 2.0.0 and now when I run my rspec tests, it is giving me the following error
undefined method `assign_to' for ...
Hyaline asked 15/4, 2013 at 22:21
1 Next >
© 2022 - 2024 — McMap. All rights reserved.