Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:02:28+00:00 2026-05-23T12:02:28+00:00

I have been really stuck on this problem. My validation for my model fails

  • 0

I have been really stuck on this problem. My validation for my model fails (like it should) when I’m testing it out in rails console, but my rspec example fails because it validates anyway (which it shouldn’t). What am I missing here or where should I start looking?

Thanks,
Ivan

See below:

    ivan:~/Development/ruby/IvanEnviromanRefinery [git:master+]  → bundle exec rspec ../refinerycms-link/
    .............................F.

    Failures:

      1) BlogPost bookmark links must have a link url if it is a link
         Failure/Error: Factory.build(:post,
           expected valid? to return false, got true
         # /Users/ivan/Development/ruby/refinerycms-link/spec/models/blog_post_spec.rb:197:in `block (3 levels) in <top (required)>'

    Finished in 6.56 seconds
    31 examples, 1 failure

    Failed examples:

    rspec /Users/ivan/Development/ruby/refinerycms-link/spec/models/blog_post_spec.rb:196 # BlogPost bookmark links must have a link url if it is a link


    ivan:~/Development/ruby/IvanEnviromanRefinery [git:master+]  → rails console
    Loading development environment (Rails 3.0.9)
    ruby-1.9.2-p180 :001 > b = BlogPost.new
     => #<BlogPost id: nil, title: nil, body: nil, draft: nil, published_at: nil, created_at: nil, updated_at: nil, user_id: nil, cached_slug: nil, custom_url: nil, link_url: nil, is_link: nil, custom_teaser: nil> 
    ruby-1.9.2-p180 :002 > b.title=' 2011-06-24 8:34 '
     => " 2011-06-24 8:34 " 
    ruby-1.9.2-p180 :003 > b.body='goo'
     => "goo" 
    ruby-1.9.2-p180 :004 > b.is_link = true
     => true 
    ruby-1.9.2-p180 :005 > b.valid?
     => false
    ruby-1.9.2-p180 :007 > b.save
     => false 
    ruby-1.9.2-p180 :008 > b.errors
     => {:link_url=>["must have a link_url if is_link is true"]} 
    ruby-1.9.2-p180 :009 > 


    require 'spec_helper'
    Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}

    describe BlogPost do
      let(:blog_post ) { Factory :post }

      ...

        describe "bookmark links" do
          it "may have a bookmark link" do
           Factory.build(:post,
                        :title => "a link",
                        :body => "link text",
                        :is_link => true,
                        :link_url => "http://example.com").should be_valid
           end
          it "must have a link url if it is a link" do
            Factory.build(:post,
                                 :title => "a link",
                                 :body => "link text",
                                 :is_link => true).should_not be_valid
          end     
        end
    end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:02:28+00:00Added an answer on May 23, 2026 at 12:02 pm

    Are you certain that in your second expectation the link_url isnt set somehow? Try outputting the value and check the logs

    it "must have a link url if it is a link" do
      post = Factory.build(:post,
       :title => "a link",
       :body => "link text",
       :is_link => true)
      Rails.logger.info "Post link: #{post.link_url}"
      post.should_not be_valid
    end   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a really weird problem that I have been having. When I download
I have been stuck on this problem for a while now. I want to
This is a (hopefully) really simple question - I have been told recently that
I have been building IMO a really cool RIA. But its now close to
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]
I have been maintaining an installation for a while but I am not really
I am really new to Python and I have been looking for an example
I am after so advice really. I have been thinking about a client server
I have some really complicated legacy code I've been working on that crashes when
Recently I've been doing lots of weekend coding, and have began to really need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.