Displaying 20 results from an estimated 3000 matches similar to: "Shouldn't this spec fail?"
2006 May 24
1
Observer behavior differences between DEV and TEST environments ?
Hi all !
I''m having an issue and I can''t seem to make heads or tails of it.
I am attempting to add an observer to a model object. I created
app/models/greenback_transaction_observer.rb, inherited from
AR::Observer, defined methods, registered in config/environment.rb,
but things don''t work...
So, I took a step back and put in the following code:
class
2007 Mar 24
0
Using spec fixtures with integration tests
Hi all,
How can I use spec fixtures with rails integration tests ?
I''ve tried adding {{ fixtures "../../spec/fixtures/myfixture" }}
to the integration test but the fixtures are not loaded when I run the
rake task.
Rails doesn''t load symlinked fixtures either so I copied the files from
spec/fixtures for the time being. Not very DRY.
Any ideas ?
Keith
2007 May 30
2
should_eql etc?
Hi, I''m trying the specs for restful_authentication I found here
http://jonathan.tron.name/articles/2007/01/02/rspec-on-rails-restful-
authentication
It seems to use custom .should methods: should_eql,
should_be_an_instance_of, should_redirect_to, should_be_success,
should_not_be_nil, should_be_nil, should_not_be_nil, should_be_empty,
should_be_success, should_not_change, and
2010 Jun 11
2
AR after_initialize quandry
I have a case where I am abstracting the creation of models. After a
fair bit of indirection, I eventually get around to making a .new call.
I need to be able to pass params to that .new call.
I know I can''t use def initialize() in an AR model (rather frustrating).
So, I have found some references to after_initialize, but that doesn''t
work either.
I see several threads on
2006 Oct 27
5
Purpose of after_initialize in ActiveRecord?
All,
I have a quick question - is the purpose of implementing
after_initialize to allow custom attribute initialization for AR
descendants?
I have been overriding initialize whenever I require custom setup of my
model classes, like so:
def initialize(attributes = nil)
super
self.Status = ''G''
end
So I have a couple of questions:
1) Could I achieve the same
2006 Aug 11
1
after_initialize and after_save
Hello,
I am still reading Agile Web Developer pdf, it says about
after_initialize and after_find. There is a Joe asks part when I read
that they are special, however I didn''t really get the idea, why they are.
On rubyonrails.org in the manual there is some sort description about
their speciality, however their full descriptions are missing.
What are the difference between
2007 Jun 16
1
extending activerecord base with after_initialize
hi,
i am having problems getting after_initialize for activerecord
subclasses. basically, i am trying to use the guid plugin by andy
singleton. i am having problems extending the class to the plugins i
installed, so i figured i will just apply this to all the models in my
project. i trled to add the following to my lib/ folder. my goal is
to extended the activerecord class so that it uses
2006 Jul 06
2
Custom init. of ActiveRecord objects - best practices
All,
I''m wanting to initialize an ActiveRecord object.
I understand that there is a method called after_initialize that appears
to get called right after the ActiveRecord object is instantiated.
Is after_initialize a Ruby thing or a Rails thing?
Where is after_initialize documented?
Can I pass parameters to it? If so, how?
I want to initialize the "belongs_to" attribute of
2010 Jan 12
1
Rails after_initialize block doesn't seem to be run in the backgroundrb context
Hi all,
Just had an interesting production failure while updating my Rails
application - a bunch of code previously in config/environment.rb was
put into config/initializers. That resulted in me having to wrap some
code in config/environments/production.rb into an after_initialize
do ... end block
When backgroundrb was run against that code, the setup done in that
after_initialize block
2008 Aug 24
2
config.after_initialize and development mode
Hi,
I''m using activemerchant and setting up a class variable using
config.after_initialize. It works great for the first request, but
then the variable is nil.
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
OrderTransaction.gateway =
ActiveMerchant::Billing::PaypalGateway.new(...)
end
I''m assuming this is is due to the model reloading after each
2012 May 26
2
before_create is after_validatation :on => :create , when it should be before_validation :on => :create
In ActiveRecord''s callbacks, methods within a before_create callback
are called after the validation, but before the model is created.
This was an intentional design decision, but I think it was the wrong
one. What do you think?
When I think of before_create, I think of before_validation :foo, :on
=> :create, but, by default, before_create is synonymous with
after_validation :foo,
2006 Feb 15
1
self in before_create
Hi, I am having a small problem concernig how to access local variables in
before_create. I am not sure how to really form this question but here goes:
I am wondering why this works
def before_create
self.last_logged_in = Time.now
self.created = Time.now
end
but this doesn''t
def before_create
@last_logged_in = Time.now
@created = Time.now
end
The latter fails
2007 May 05
3
DB trigger vs before_create
Hello everyone,
I''m having trouble figuring out which approach is better.
I have the following tables: products, orders and line_items.
Every time an Order is placed, the quantity field in the products
table has to be updated for each LineItem in the Order. One option is
to use DB triggers which is not as portable as using before_create in
the Order model. But with before_create I cannot
2006 Dec 13
3
Testing has_many :through
I''m working with a has_many :through association, where a Member
has_many Projects through ProjectViewers. The problem I''m running
into is that Rails doesn''t load the association so line (3) fails
until I explicitly access a member of the collection (in this case, I
iterated it). Is there a better way?
Thanks,
Steve
1. assigns[:member].should_not_be_nil
2.
2006 Apr 21
2
Using before_create and conflicting setter method...
Hi,
I am having trouble using before_create when I have an specialized
setter method:
before_save :set_campaign_start
#-----------------------------------------------------------------------
-------
def set_campaign_start
self.campaign_start = Time.now
end
# We want the date to always start at midnight
2006 Jun 26
1
ActiveRecord, instance_eval, and PStore
I''m trying to add some per-object behaviors to objects descended from
ActiveRecord, by using after_initialize() and instance_eval(), like this:
def after_initialize
self.instance_eval(File.read(''customers/default.rb''))
end
(Ultimately the file path will be dynamic, this is just proof of concept.)
default.rb just contains a few method definitions like this one:
def
2007 Jan 01
5
Validations based on associations
My model is very simple, it''s mostly just a join table that represents
which tournaments a user has registered for.
class Registration < ActiveRecord::Base
belongs_to :user
belongs_to :tournament
validates_presence_of :user_id, :tournament_id
validates_uniqueness_of :user_id, :scope => :tournament_id
end
the validates_uniqueness checks to make sure there''s no
2007 Jan 08
2
before_create firing twice on a save - RC2
I have a unit test which fails using Rails 1.2RC2, because a method marked
by the before_create filter is firing twice when my ActiveRecord is saved.
Is a before_create filter supposed to cause multiple invocations? We have
assumed it is called once, and only once, when the object is created, in our
code (but we unit tested it to make certain).
This is one of three issues I have with my unit
2006 May 10
2
Exploring ActiveRecord::Base#serialize
Hi
I was recently taught about the useful ActiveRecord::Base#serialize.
It''s very useful for persisting arbitrary objects through the regular
database. For example, say you want to store a Set of all the years a
Convention took place. You do:
class Convention < ActiveRecord::Base
serialize :years, Set
end
This effectively creates a Convention#years attribute, which is a set:
you
2006 Jul 25
1
How do I validate using associated objects?
This doesn''t make any sense to me anymore. I have an Upload that
belongs_to a Comment. Within my Upload model I expect to be able to
access the associated comment with comment.foo. I can only seem to do
this AFTER validation. I''m assuming before_create takes place between
validation and updating the database, because when I try to access
comment.foo within the validate