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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:35:54+00:00 2026-05-22T00:35:54+00:00

I have a model # == Schema Information # # Table name: posts #

  • 0

I have a model

# == Schema Information
#
# Table name: posts
#
#  id             :integer         not null, primary key
#  name           :string(255)
#  title          :string(255)
#  content        :text
#  created_at     :datetime
#  updated_at     :datetime
#  abstract       :text
#  category_id    :integer
#  finalversion   :boolean         default(FALSE)
#  published_date :date
#

class Post < ActiveRecord::Base
  has_many :tags
  belongs_to :category

  validates :published_date, :presence => true

  default_scope :order => 'created_at DESC'

  accepts_nested_attributes_for :tags, :allow_destroy => :true,
    :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }

  def prev_post
    self.class.first(:conditions => ["id < ?", id], :order => "id desc")
  end


  def next_post
    self.class.first(:conditions => ["id > ?", id], :order => "id asc")
  end

  def seo_title
    title.gsub(/\s+/,'_')
  end

end

and a factory

FactoryGirl.define do
  factory :post do
    published_date Date.today
    association :category, :factory => :category
    title Forgery::LoremIpsum.words
    name Forgery::LoremIpsum.word
    content Forgery::LoremIpsum.words(100, :random => 250)
    abstract Forgery::LoremIpsum.words(100, :random => 50)
    finalversion true
  end
end

and in the rails console I have no problem doing

FactoryGirl.create :post

to get a valid object and am able to access the *published_date* attribute. However in my spec

require 'spec_helper'


(1..5).map do |i|
  title        = "a title\t#{i}"
  escape_title = "a_title_#{i}"
  perma_link = "/posts/#{i}/title/#{escape_title}"

  describe "A post with title '#{title}'" do

    before do
      @post = FactoryGirl.create :post, :id=>i, :title => title
      visit '/posts'
    end

    it "should appear in all links with permalink #{perma_link}" do
      within "section.post_#{@post.id}" do
        page.should have_xpath(%Q%.//h1/a[@href="#{perma_link}"]%)
        within "div.teaser" do
          page.should have_xpath(%Q%.//a[@href="#{perma_link}"]%)
        end
      end
    end
  end
end

I get the backtrace error

  5) A post with title 'a title 5' should appear in all links with permalink /posts/5/title/a_title_5
     Failure/Error: @post = FactoryGirl.create :post, :id=>i, :title => title
     NoMethodError:
       undefined method `published_date=' for #<Post:0x000001047266b8>
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/activemodel-3.0.5/lib/active_model/attribute_methods.rb:364:in `method_missing'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/activerecord-3.0.5/lib/active_record/attribute_methods.rb:46:in `method_missing'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/bundler/gems/factory_girl-4f5f5df39a1b/lib/factory_girl/proxy/build.rb:13:in `set'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/bundler/gems/factory_girl-4f5f5df39a1b/lib/factory_girl/attribute/static.rb:12:in `add_to'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/bundler/gems/factory_girl-4f5f5df39a1b/lib/factory_girl/factory.rb:93:in `block in run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/bundler/gems/factory_girl-4f5f5df39a1b/lib/factory_girl/factory.rb:91:in `each'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/bundler/gems/factory_girl-4f5f5df39a1b/lib/factory_girl/factory.rb:91:in `run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/bundler/gems/factory_girl-4f5f5df39a1b/lib/factory_girl/syntax/methods.rb:54:in `create'
     # ./spec/integration/posts_permalinks_spec.rb:12:in `block (3 levels) in <top (required)>'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:29:in `instance_eval'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:29:in `run_in'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:64:in `block in run_all'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:64:in `each'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:64:in `run_all'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:110:in `run_hook'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:191:in `block in eval_before_eachs'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:191:in `each'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:144:in `run_before_each'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:48:in `block (2 levels) in run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:106:in `with_around_hooks'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:46:in `block in run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:99:in `block in with_pending_capture'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:98:in `catch'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:98:in `with_pending_capture'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:45:in `run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:262:in `block in run_examples'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:258:in `map'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:258:in `run_examples'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:232:in `run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:27:in `block (2 levels) in run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:27:in `map'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:27:in `block in run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/reporter.rb:12:in `report'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:24:in `run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
     # /Users/bradphelan/.rvm/gems/ruby-1.9.2-p180@ingd/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'

I’m totally stumped on it. Any ideas

Brad

  • 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-22T00:35:55+00:00Added an answer on May 22, 2026 at 12:35 am

    Did you run rake db:test:prepare? It looks to me like your Post model has published_date, but your Factory is saying it doesn’t exist. Not running this rake task would be the major thing that would cause this.

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

Sidebar

Related Questions

I have the following mysql table schema: SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; -- -- Database: `network` --
I have a model Vehicle which actually maps to the at_vehicles table. So while
Lets imagine I have the same database schema as here: http://www.databaseanswers.org/data_models/driving_school/index.htm If a customer
I have a model being populated by my data layer and then I have
I have some model objects I'm using in my Java client application. Later these
I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to
I have a model Question with a field called userid , before one ask
I have a model Foo which have a ForeignKey to the User model. Later,
Let's say I have a model like this class Foo(db.Model): id = db.StringProperty() bar
Let's say I have this model named Product with a field named brand .

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.