Rails 3 with composed_of model and validation get error "NoMethodError: undefined method `marked_for_destruction?'" - validation

I have tried to add custom validation as is written in Rails 3 with composed_of model and validation but i got strange error: "NoMethodError: undefined method `marked_for_destruction?' for Money"
And I don't understand what is wrong.
Can you help me?
Model:
# == Schema Information
#
# Table name: transactions
#
# id :integer not null, primary key
# text :string(255)
# amount_cents :integer default(0), not null
# ...
class Transaction < ActiveRecord::Base
attr_accessible :text, :amount, ...
validates :text, :length => { :maximum => 255 }
composed_of :amount, :class_name => "Money", :mapping => %w(amount_cents cents),
:converter => Proc.new { |value| Money.to_money(value) }
validates :amount, :presence => true, :numericality => { :greater_than_or_equal_to => 0 }
validates_associated :amount
...
end
class Money
attr_reader :cents
def initialize(cents)
#cents = cents
end
class << self
def to_money(str_money)
cents = (str_money.to_f * 100).to_i
Money.new(cents)
end
def to_money?(str_money)
/\A\d+(\.\d+)?\z/ == str_money.to_s
end
end
def ==(value)
#cents == self.class.to_money(value).cents
end
def to_i
#cents
end
def to_f
#cents.to_f
end
def to_s
return nil if #cents.nil?
unit, subunit = #cents.abs.divmod(100)
unit_str = ""
subunit_str = ""
fraction_str = ""
unit_str, subunit_str = unit.to_s, subunit.to_s
subunit_str.insert(0, '0') while subunit_str.length < 2
absolute_str = "#{unit_str}.#{subunit_str}#{fraction_str}"
absolute_str.tap do |str|
str.insert(0, "-") if #cents < 0
end
end
def inspect
"#<Money cents:#{#cents} to_s:#{self.to_s}>"
end
end
Error:
1.9.3p194 :001 > t = Transaction.new
=> #<Transaction id: nil, text: nil, amount_cents: 0, date: nil, created_at: nil, updated_at: nil, transaction_type_id: nil, account_id: nil, user_id: nil, trans_account_id: nil, trans_amount_cents: 0>
1.9.3p194 :002 > t.amount = 100
=> 100
1.9.3p194 :003 > t.valid?
NoMethodError: undefined method `marked_for_destruction?' for #<Money cents:10000 to_s:100.00>
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/validations/associated.rb:5:in `block in validate_each'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/validations/associated.rb:5:in `reject'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/validations/associated.rb:5:in `validate_each'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activemodel-3.2.8/lib/active_model/validator.rb:153:in `block in validate'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activemodel-3.2.8/lib/active_model/validator.rb:150:in `each'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activemodel-3.2.8/lib/active_model/validator.rb:150:in `validate'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:310:in `_callback_before_21'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:462:in `_run__74709952__validate__911291598__callbacks'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activemodel-3.2.8/lib/active_model/validations.rb:227:in `run_validations!'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activemodel-3.2.8/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:403:in `_run__74709952__validation__911291598__callbacks'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activemodel-3.2.8/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activemodel-3.2.8/lib/active_model/validations.rb:194:in `valid?'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/validations.rb:69:in `valid?'
from (irb):3
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /home/alexvs/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'

Related

rake db:migrate returns with error

I ran rake db:migrate and I came across this error in terminal
SQLite3::SQLException: no such table: admin_users: ALTER TABLE "admin_users" ADD "username" varchar(25)/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `new'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `prepare'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in `execute'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `block in execute'
/Users/IsaiahxD/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
I looked into my alter_user.rb file class AlterUsers < ActiveRecord::Migration
this is the file 20150825065823_alter_users.rb
def up
rename_table("users", "admin_users.broken")
add_column("admin_users", "username", :string, :limit => 25, :after => "email" )
change_column("admin_users", "email", :string, :limit => 100)
rename_column("admin_users", "broken", "hashed_password")
puts "*** Adding an index is next ***"
add_index("admin_users", "username")
end
def down
remove_index("admin_users", "username")
rename_column("admin_users", "hashed_password", "password")
change_column("admin_users", "email", :string, :default => "" , :null => false)
remove_column("admin_users", "username")
rename_table("admin_users", "users")
end
In your #up method, you're adding columns to admin_users but you haven't defined that table yet.
Instead of:
rename_table("users", "admin_users.broken")
try:
rename_table("users", "admin_users")

Undefined method error while running rspec test

All,
I am getting the following undefined method errors below when running my rspec tests. When I have gotten this error before I had a method misspelled or my order of execution caused it. I checked both along with some other posts on StackOverflow, but nothing helped. Can anyone offer any guidance?
Rspec Failures:
FFFF
Failures:
1) Post vote methods #up_votes counts the number of votes with value = 1
Failure/Error: expect(#post.up_votes ).to eq(3)
NoMethodError:
undefined method `up_votes' for #<Post:0x007fe92f381a38>
# ./spec/models/post_spec.rb:14:in `block (4 levels) in <top (required)>'
2) Post vote methods #down_votes counts the number of votes with values = -1
Failure/Error: expect(#post.down_votes ).to eq(2)
NoMethodError:
undefined method `down_votes' for #<Post:0x007fe92a18c228>
# ./spec/models/post_spec.rb:20:in `block (4 levels) in <top (required)>'
3) Post vote methods #points returns the sum of all down and up votes
Failure/Error: expect(#post.points ).to eq(1) # 3 - 2
NoMethodError:
undefined method `points' for #<Post:0x007fe92986c620>
# ./spec/models/post_spec.rb:26:in `block (4 levels) in <top (required)>'
4) Vote validations value validation only allows -1 or 1 as values
Failure/Error: expect(#post.up_votes).to eq((-1) || eq(1))
NoMethodError:
undefined method `up_votes' for nil:NilClass
# ./spec/models/vote_spec.rb:5:in `block (4 levels) in <top (required)>'
Post_rspec
require 'rails_helper'
describe Post do
describe "vote methods" do
before do
#post = Post.create(title: 'Post title', body: 'Post bodies must be pretty long.')
3.times { #post.votes.create(value: 1) }
2.times { #post.votes.create(value: -1) }
end
describe '#up_votes' do
it "counts the number of votes with value = 1" do
expect(#post.up_votes ).to eq(3)
end
end
describe '#down_votes' do
it "counts the number of votes with values = -1" do
expect(#post.down_votes ).to eq(2)
end
end
describe '#points' do
it "returns the sum of all down and up votes" do
expect(#post.points ).to eq(1) # 3 - 2
end
end
end
end
vote_spec file
describe Vote do
describe "validations" do
describe "value validation" do
it "only allows -1 or 1 as values" do
expect(#post.up_votes).to eq((-1) || eq(1))
end
end
end
end
Post.rb
class Post < ActiveRecord::Base
has_many :comments, dependent: :destroy
has_many :votes
has_one :summary
belongs_to :user #means the post table has the user table's primary key in it
belongs_to :topic
mount_uploader :avatar, AvatarUploader
default_scope {order('created_at DESC')}
validates :title, length: {minimum: 5}, presence: true
validates :body, length: {minimum: 20}, presence: true
def markdown_title
(render_as_markdown).render(self.title).html_safe
end
def markdown_body
(render_as_markdown).render(self.body).html_safe
end
private
def render_as_markdown
renderer = Redcarpet::Render::HTML.new
extensions = {fenced_code_blocks: true}
redcarpet = Redcarpet::Markdown.new(renderer, extensions)
#return redcarpet
end
end
For the post_spec.rb errors, check the Post model (see file app/models/post.rb) has the following methods defined in it:
up_votes
down_votes
points
Consider including the code for post.rb in your original question too.
For the vote_spec.rb errors, there is no #post variable, it will be nil. This error message hints at this:
Failure/Error: expect(#post.up_votes).to eq((-1) || eq(1))
NoMethodError: undefined method `up_votes' for nil:NilClass

Factory Girl + Rspec: ArgumentError: wrong number of arguments (0 for 2)

I have a simple restaurant class that looks like this:
module Restaurant
class Identity
attr_reader :name, :location
def initialize (name, location)
#name = name
#location = location
end
end
end
My factory looks like this:
FactoryGirl.define do
factory :restaurant, :class => Restaurant::Identity do |f|
f.name "Alfredos"
f.location "Andheri"
end
end
And my test is written like this:
describe Restaurant::Identity do
subject { build(:restaurant) }
its(:name) {should_not be_nil}
its(:location) {should_not be_nil}
end
But when I run this, I get
1) Restaurant::Identity name
Failure/Error: subject { build(:restaurant) }
ArgumentError:
wrong number of arguments (0 for 2)
# ./lib/restaurant.rb:7:in `initialize'
# ./spec/restaurant_spec.rb:9:in `block (2 levels) in <top (required)>'
# ./spec/restaurant_spec.rb:11:in `block (2 levels) in <top (required)>'
Why is this happening? What am I doing wrong?
Ok so the solution is to use initialize_with in your factory girl setup:
FactoryGirl.define do
factory :restaurant, :class => Restaurant::Identity do |f|
f.name "Alfredos"
f.location "Andheri"
initialize_with { new(name, location) } # add this line
end
end
ref: https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#custom-construction

How to migrate correctly with sequel on Access 2007

When I migrate my application to Access 2007 with sequel library of Ruby. I get the errors as follows. Does anybody know how to migrate correctly? Thanks.
C:\ContractManagement>rackup
C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapters/ado.rb:63:
in `method_missing': WIN32OLERuntimeError: (in OLE method `Execute': ) (Sequel::
DatabaseError)
OLE error code:80040E14 in Microsoft Office Access Database Engine
Syntax error (missing operator) in query expression 'LIMIT 1 1'.
HRESULT error code:0x80020009
Exception occurred.
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapte
rs/ado.rb:63:in `block (2 levels) in execute'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/databa
se/logging.rb:28:in `log_yield'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapte
rs/ado.rb:63:in `block in execute'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/connec
tion_pool/threaded.rb:84:in `hold'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/databa
se/connecting.rb:226:in `synchronize'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapte
rs/ado.rb:61:in `execute'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:541:in `execute'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapte
rs/ado.rb:97:in `fetch_rows'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:123:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:449:in `single_record'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:457:in `single_value'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:200:in `get'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:133:in `empty?'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:499:in `schema_dataset'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:381:in `initialize'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:422:in `initialize'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:332:in `new'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:332:in `run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:316:in `apply'
from C:/ContractManagement/config.ru:12:in `block in <main>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/builder.rb:
51:in `instance_eval'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/builder.rb:
51:in `initialize'
from C:/ContractManagement/config.ru:1:in `new'
from C:/ContractManagement/config.ru:1:in `<main>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/builder.rb:
40:in `eval'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/builder.rb:
40:in `parse_file'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/server.rb:2
00:in `app'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/server.rb:3
01:in `wrapped_app'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/server.rb:2
52:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/server.rb:1
37:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/bin/rackup:4:in `<to
p (required)>'
from C:/Ruby192/bin/rackup:19:in `load'
from C:/Ruby192/bin/rackup:19:in `<main>'
Here is the connection configuration.
DB = Sequel.ado(:conn_string=>'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ContractManagement1.accdb')
And here is the migration steps. All are passed on PostgreSQL 8.4.
Sequel.migration do
up do
create_table :people do
primary_key :id
String :name, :size => 20, :unique => true, :null => false
String :password, :size => 30, :null => false
String :role, :size => 20, :null => false
end
end
down do
drop_table :people
end
end
Sequel.migration do
up do
create_table :currencies do
primary_key :id
String :name, :size => 10, :null => false
end
end
down do
drop_table :currencies
end
end
Sequel.migration do
up do
create_table :statuses do
primary_key :id
String :name, :size => 10, :null => false
end
end
down do
drop_table :statuses
end
end
# encoding: utf-8
Sequel.migration do
up do
create_table :contracts do
primary_key :id
String :contract_id, :size => 36, :unique => true, :null => false
String :content, :size => 150
String :supplier, :size => 30
Date :created_on
Date :expired_on
BigDecimal :amount, :size => [10, 2], :null => false
Fixnum :debt_days
Fixnum :guarantee_period
String :order_id, :size => 50 # 订单号
String :supplier_contract_id, :size => 36
String :operator, :size => 30
foreign_key :currency_id, :currencies, :on_delete => :cascade, :on_update => :cascade, :null => false
foreign_key :status_id, :statuses, :on_delete => :cascade, :on_update => :cascade, :null => false
constraint(:min_amount) { amount >= 0.01 }
end
end
down do
drop_table :contracts
end
end
# encoding: utf-8
Sequel.migration do
up do
self[:currencies].insert(:name => "人民币")
self[:currencies].insert(:name => "欧元")
self[:currencies].insert(:name => "美元")
end
down do
self[:currencies].delete
end
end
# encoding: utf-8
Sequel.migration do
up do
self[:statuses].insert(:name => "执行中")
self[:statuses].insert(:name => "关闭")
self[:statuses].insert(:name => "作废")
end
down do
self[:statuses].delete
end
end
# encoding: utf-8
Sequel.migration do
up do
create_table :payments do
primary_key :id
BigDecimal :prepayment, :size => [10, 2], :default => 0 # 预付金额(元)
BigDecimal :offset_prepayment, :size => [10, 2], :default => 0 # 冲预付
BigDecimal :guarantee_price, :size => [10, 2], :default => 0 # 质保金
BigDecimal :request_amount, :size => [10, 2], :default => 0 # 申请付款额
foreign_key :contract_id, :contracts, :on_delete => :cascade, :on_update => :cascade
foreign_key :person_id, :people, :on_delete => :cascade, :on_update => :cascade
constraint(:offset_prepayment_is_not_greater_than_prepayment) { prepayment >= offset_prepayment } # offset_prepayment不能大于prepayment
end
end
down do
drop_table :payments
end
end
Sequel.migration do
up do
{"admin" => "Admin", "contract" => "ContractOperator", "payment" => "PaymentOperator", "report" => "ReportReviewer"}.each do |n, r|
self[:people].insert(:name => n, :password => n, :role => r)
end
self[:people].insert(:name => "payment1", :password => "payment1", :role => "PaymentOperator")
end
down do
self[:people].delete
end
end
I think you get this error message ...
OLE error code:80040E14 in Microsoft Office Access Database Engine
Syntax error (missing operator) in query expression 'LIMIT 1 1'.
... because Access SQL doesn't support LIMIT. See this reply to a related Stack Overflow question.
See whether you can use Access SQL TOP N as a substitute for LIMIT N.
SELECT TOP 1 m.id, m.paid_in_full, m.date_field
FROM MyTable AS m
ORDER BY m.date_field DESC;
This is fixed in the master branch of Sequel, version 3.24.0 (which will be released next week) will have the bugfix.

Strange problem with factory girl

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
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.

Resources