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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:28:43+00:00 2026-06-09T12:28:43+00:00

When a contract gets created, it takes a Unit, User and Discount and uses

  • 0

When a contract gets created, it takes a Unit, User and Discount and uses those param items (models) to generate an Invoice.

Everything works fine in the browser. But when running a spec, I’m getting undefined method 'value' for nil:NilClass [/app/models/option.rb:19:in 'get_from_database'

Line 18-20 of Option.rb. This is a model for getting site options (configurable by the admin) from the database. Works fine normally (browser tests).

def self.get_from_database(name)
  $option[name] = self.find_by_name(name).send('value')
end

And it’s being called from Contract.rb:

def start_date=(date)
    self[:start_date] = Date.strptime(date, Option.get_from_database('short_date'))
end

Any idea why I’m getting this error? If I comment out this line and re-run the spec test, I get another nil:NilClass error from another class method call.

I’ve just started working with rspec, so I’m sure I’m missing something. NOTE: The first test works, the second doesn’t.

require 'spec_helper'

module ContractSpecHelper
  def contract_params
    {  :start_date => "08/09/2012",
       :client_id => '1', 
       :pay_interval_id => '1', 
       :billing_day => "1",
       :prorated => '1',
       :require_next => "1",
       :include_today => "1",
       :unit_id => '45',
       :due => "1" }
  end
end

describe 'Contract' do
  include ContractSpecHelper

  before :each do
    @contract = Contract.new
  end

  describe '#new' do
    it "requires a unit, user, and pay interval id" do
      @contract.should_not be_valid
    end

    it "creates an invoice once saved" do
      @contract.attributes = contract_params
      @contract.save

      @contract.should have(1).invoice
    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-06-09T12:28:44+00:00Added an answer on June 9, 2026 at 12:28 pm

    The issue appears be that Option.find_by_name(name) is returning nil.

    The most likely cause of this is that you’re not populating the options table in the test environment. Either change your code to handle Option record not existing, or use fixtures/factory_girl/machinist/ before block (etc) to create option records in your test environment.

    (To answer your other question, your environment should be loaded in your spec_helper. You shouldn’t need to manually include your rails models into your rspec specs.)

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

Sidebar

Related Questions

I've created a contract-last web-service which is deployed on a Jboss AS on my
I am looking for adding a version number to the wsdl that gets created
I created a new air project in aptana but launching it gets me This
If my contract looks as follows: [OperationContract] void DoSomething(int id, out string moreInfo); this
My Service Contract [ServiceContract] public interface ITsdxService { [OperationContract] [WebGet(UriTemplate=/GetTestCostCentre)] CostCentre GetTestCostCentre(); [OperationContract] [WebInvoke(UriTemplate=/SetCostCentre,
Was: Design by contract: predict methods needed, discipline yourself and deal with code that
I'm generating my data contract with a command line like: svcutil /ct:System.Collections.Generic.List`1 MySchema.xsd In
I am trying to write contract tests for some widely used interfaces: Along the
Let's say I have a WCF contract such as [ServiceContract] public interface IContract {
I'm trying to understand the contract of drainPermits in the Java Semaphore class The

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.