Displaying 20 results from an estimated 31 matches for "method_defined".
2007 Aug 30
1
alias_method_chain stack level too deep in Rake test only
I have an odd error. I have the following module:
module ActionController
module SslSupport
def self.included(base)
raise "#{base} does not define url_for" unless
base.method_defined?(:url_for)
unless base.respond_to?(:url_for_without_ssl_supprt)
base.send :include, InstanceMethods
base.send :alias_method_chain, :url_for, :ssl_support
end
end
module InstanceMethods
def url_for_with_ssl_support(options)
new_options = options.du...
2005 Dec 31
6
habtm recursion via destroy_without_callbacks
...reloading person.rb? I''ve
added some instrumentation that shows that the
destroy_without_habtm_shim_for_teams method ends up being added twice.
This causes recursion when the record is destroyed. I''ve worked around
this by embedding this method aliasing inside an "unless
method_defined?()" to prevent the recursive situation. However, I''m
suspecting that I''m missing something else obvious.
I am using activerecord 1.13.2 and rails 1.0.0.
--
Posted via http://www.ruby-forum.com/.
2007 Jan 02
4
allow stubbing of previously defined methods such as "id"
...= method_names.is_a?(Hash) ? method_names :
{ method_names => nil }
method_names.each do |method_name, return_value|
expectations << Stub.new(self, method_name,
backtrace).returns(return_value)
+ self.metaclass.send :undef_method, method_name if
self.metaclass.method_defined? method_name
end
expectations.last
end
Index: test/mocha/auto_verify_test.rb
===================================================================
--- test/mocha/auto_verify_test.rb (revision 1114)
+++ test/mocha/auto_verify_test.rb (working copy)
@@ -155,6 +155,11 @@...
2007 Apr 06
3
Mailer method missing
...my Mailer. But I have
defined my method. What could I have missed? Here is the irb session:
>> p = Person.find(1)
=> Person data...
>> SiteMailer.request_admin_approval(p)
NoMethodError: undefined method `request_admin_approval'' for
SiteMailer:Class
>> SiteMailer.method_defined? :request_admin_approval
=> true
The method code:
class SiteMailer < ActionMailer::Base
def request_admin_approval(person)
@subject = ''Watercooler - New User Notification''
@body["person"] = person
@recipients = "me"
@from...
2008 Jun 05
2
how to add a method without coding it directly into app?
...utside the application to be shared with other
Camping apps?
module Blog::Controllers
module AuthenticationHelper
def self.included(base)
class << base
define_method :authenticate do |*a|
a.each do |meth|
if method_defined?(meth.to_s)
alias_method "__#{meth}__", meth
class_def(meth) do |*a|
@state.Back=@env.REQUEST_URI
return redirect(Login) if @state.blank?
or @state.user_id.nil?...
2009 Nov 28
1
'Are you sure?' custom dialog not exiting cleanly
...sion in 1.9.2; remove
# begin/rescue clause in later versions
rescue RuntimeError
int_id
end
end
@m_statictext1 = finder.call("m_staticText1")
@m_butexit = finder.call("m_butExit")
if self.class.method_defined? "on_init"
self.on_init()
end
end
end
# This class was automatically generated from XRC source. It is not
# recommended that this file is edited directly; instead, inherit from
# this class and extend its behaviour there.
#
# Source file: sample1.xrc
# Generated...
2007 Mar 30
7
problem with using any_instance
Hey all,
I have a question with using mocha in my tests.
In the same test file, I have two tests,
<code>
def test_a
klass.any_instance.stubs(:method_name).returns("something")
klass.new.method_name
...
end
def test_b
...
klass.new.method_name
...
end
</code>
where klass is some class
when the tests run, test _a passes, but test_b had an error like this:
2007 Mar 12
10
using mocha with rspec
...e incantation I ended up using in my equivalent of a
test_helper.rb file that I include in all my spec files:
# replace rspec''s mocks with mocha
require ''mocha''
module Spec
module Mocks
remove_method :mock
remove_method :stub
remove_method :verify_mocks if method_defined? :verify_mocks
include Mocha::AutoVerify
end
end
Now I have working mock(), stub() and verify_mocks(). Not sure what
other Mocha stuff I''m missing yet, but I''ll let you know how I get on.
I noticed that Mocha::Standalone also references
Mocha::SetupAndTeardown, but I did...
2006 Jan 19
2
Easy way to handle form input without a model class?
I have a couple forms that I''d like to be able to validate and
automatically populate, but it shouldn''t be based on AR. In fact I
often have a bunch of small forms that I can''t really justify writing
a whole new model class for anyway. I''d like to validate the form
input, and then use rails helpers to automatically populate the form
if validations fail.
2008 Jun 03
8
@@state_secret
I was having some issue getting the class variables in
Camping::Session to work with some old apps, so I''ve changed
@@state_secret to a method.
module Blog
include Camping::Session
def state_secret; "kxxxx" end
end
Also, merged some of zimbatm''s patches. And trying to revive the
Junebug wiki <http://github.com/why/junebug> since it''s still
2011 Apr 08
5
How to extend a helper using plugin?
Hello,
I''m facing this problem while trying to extend the parse_redmine_links
helper method in Redmine-1.1.0 (Rails-2.3.5) from my plugin.
My idea is to use alias_method_chain so the extended version could
call the original version and adjust the result to it''s liking.
Anything I''ve tried so far exposes this behavior: the first render of
a page uses the extended
2008 May 13
6
Testing that named_scope is defined
...ran into the issue of testing a
named_scope. I''m not actually trying to test its behavior, as it''s not
my code, but I wanted to test at least that it''s defined. I tried
doing this:
describe Post, ".most_recent" do
it "should be defined" do
Post.method_defined?(:most_recent).should be_true
end
end
But it always fails, even though it *is* defined. Any idea on how to test this?
Thanks a lot!
Cheers,
--
Helder Ribeiro
ProFUSION
Embedded Systems
http://profusion.mobi
"If I have not seen as far as others, it is because giants were
standing on my...
2006 Jun 15
4
parse only seem to understand US date format
I''ve tried Time.parse() and DateTime.parse() but they interpret the date
as US format. Is there any way to tell it to interpret as dd/mm/yyyy?
--
Posted via http://www.ruby-forum.com/.
2006 Jun 20
1
Possible to check if form field is required?
Hi list,
is it possible to check if form field will be required when form is
submitted (through validates_presence_of or some other validates_*
method)? I could do this manually but it doesn''t seems to me very DRY.
For example, I would like to be able to dynamically add asterisk with
some helper method if city is required here:
City*: <%= text_field
2005 Dec 16
2
Using logger from rails cron jobs
Hi. I''m trying to use logger from a rails cron job.
It works fine, but I''d like the standard ruby behavior of stamping each
log with date and time. How do I do this?
I''m trying:
# Set up out logging
require ''logger''
logger = Logger.new(STDERR)
logger.level = Logger::INFO
RAILS_DEFAULT_LOGGER = logger # Tell rails to log to our logger also
The
2007 Sep 06
1
any reason we can''t use the concise stubs on Object
...a'', :method2 => ''b'')
TypeError: #<Mocha::InstanceMethod:0x32f9100 @method={:foo=>"b",
:again=>"hi"}, @stubbee=#<Object:0x32fc364>> is not a symbol
from /opt/local/lib/ruby/gems/1.8/gems/mocha-0.5.4/lib/mocha/mock.rb:148:in
`method_defined?''
from /opt/local/lib/ruby/gems/1.8/gems/mocha-0.5.4/lib/mocha/mock.rb:148:in
`add_expectation''
from /opt/local/lib/ruby/gems/1.8/gems/mocha-0.5.4/lib/mocha/mock.rb:88:in
`stubs''
from /opt/local/lib/ruby/gems/1.8/gems/mocha-0.5.4/lib/mocha/auto_ver...
2005 Sep 17
0
Reloading and redefining methods: infinite recursion
...se definitions
are executed again for each request, the second time around
method_without_addition is actually the same as method_with_addition
and when called dies in an infinite recursion stack overflow.
I though something like this would help, but apparently it does not
class Klass
unless method_defined?(:method_with_addition)
alias_method :method_without_addition, :method
def method_with_addition
...
method_without_addition
...
end
alias_method :method, :method_with_addition
end
end
It gives a stack overflow just the same. How do I make this work?
Michael
--...
2010 May 11
1
Gem::Dependency#version_requirements is deprecated...
Seen when running scripts/console, Ruby version not important.
What is this telling me?
Loading development environment (Rails 2.3.5)
/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/
gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is
deprecated and will be removed on or after August 2010. Use
#requirement
Checking gem_dependency.rb shows:
118: def requirement
2005 Sep 06
1
US Date Handling in Rails
My application is built on Rails and MySQL. It will only be accepting US
formatted dates as input, however both Rails and MySQL are oriented around
ISO the format. I know I can convert a good portion of the entries using
ParseDate::parsedate but it does not appear this is how the conversion is
taking place when data is being transferred from the params hash into model
members.
Say I have a field
2007 Mar 04
4
Rails functional testing and Mocha
...ectations.each do |e|
method = stubba_method.new(stubba_object, e.method_name)
$stubba.stub(method)
e.mock = self.mocha
self.mocha.expectations << e
self.mocha.__metaclass__.send(:undef_method,
e.method_name) if self.mocha.__metaclass__.method_defined?
(e.method_name)
end
end
end
end
end
There''s also one or 2 places where i''ve made attributes writable/
readable on Expectation etc... to get this all to hold together.
Limitations:
- The big limitation is that if an instance with the required id is
no...