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 7855857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:30:34+00:00 2026-06-02T20:30:34+00:00

I have a model with a Time attribute. I want to check that time

  • 0

I have a model with a Time attribute. I want to check that time can not be empty (better choice probably would be to check that input is time but i have no ideas how to deal with that). I tried this validation:

#  id              :integer         not null, primary key
#  school_class_id :integer
#  meeting_time    :time
class Meeting < ActiveRecord::Base                                                    
  validates :meeting_time,
              :presence => { :message => "can't be empty!" }                                                            
end

Then i tried to check this in spec and this fails (empty time is ok but it should not be). What do i do wrong?

Rspec:

#  id              :integer         not null, primary key
#  school_class_id :integer
#  meeting_time    :time

require 'spec_helper'

describe Meeting do
  before(:each) do
    @class = FactoryGirl.create( :school_class )
    @attr_meeting = {
      :meeting_theme => 'Text is here',
      :meeting_date => "#{Date.today}",
      :meeting_time => "#{Time.now}",
      :meeting_room => '1234'
    }
  end

  describe "Validations" do
    describe "Rejection" do
      it "should reject blank time" do
        wrong_attr = @attr_meeting.merge( :meeting_time => "  " )
        @class.meetings.build( wrong_attr ).should_not be_valid
      end
    end
  end
end

Error:

 Meeting Validations Rejection should reject blank time
     Failure/Error: @class.meetings.build( wrong_attr ).should_not be_valid
       expected valid? to return false, got true
  • 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-06-02T20:30:35+00:00Added an answer on June 2, 2026 at 8:30 pm

    In your example, you assign " " to the meeting_time, not nil or "". But Time object somehow can be successfuly generated from non-empty, even blank string. Setting meeting_time to "" or nil should solve yout problem.

    Maybe I don’t fully understand something, but I think it’s not very logical and predictable behaviour. Need to take a look into the sources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data model that contains a DateTime attribute, date. I want to
I have a User model that has a :credits attribute. I want a simple
I have an ActiveRecord Appointment model, which includes topic and time attributes. I would
I have an article model and a user model. The user can follow that
I have Post and Comment model. I want to achieve the following: Each time
I have a model, ContactEmail that has a date_sent attribute and an email_id, referencing
For example, if I have a simple model with a time attribute named start_time
I have a Comment model that I want people to be able to save
I have a model in django that have a boolean private/public attribute: class TestModel(models.Model):
I have a date time property in a linq to sql model and I

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.