search for: method_name

Displaying 20 results from an estimated 61 matches for "method_name".

2007 Jan 02
4
allow stubbing of previously defined methods such as "id"
...to the id message. Here''s the change I put into my copy of head. Index: lib/mocha/mock_methods.rb =================================================================== --- lib/mocha/mock_methods.rb (revision 1114) +++ lib/mocha/mock_methods.rb (working copy) @@ -68,6 +68,7 @@ method_names = 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...
2007 Mar 04
4
Rails functional testing and Mocha
...gs. It looks very much like Mocha::Mock (there''s some refactoring to be done here), except that it doesn''t actually do anything in terms of undefining methods. class AnyInstanceWithID attr_reader :expectations def initialize @expectations = [] end def stubs(method_names) method_names = method_names.is_a?(Hash) ? method_names : { method_names => nil } method_names.each do |method_name, return_value| expectations << Mocha::Stub.new(nil, method_name, caller).returns(return_value) end expectations.last end def expects(...
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: test_b NoMethodError: undefined method `method_name'' for #...
2006 Aug 09
2
How do you define a method
Hi all, I was wondering if anybody could help me figure why a view cannot find a method that I defined in another class. I do this in the view: (let''s say index.rhtml) <%= check_box("item_search_page", "method_name") Here, item_search_page is a variable in the view''s controller, which creates a new ItemSearchPage object. And I defined "method_name" in the class: class ItemSearchPage def method_name end end So, although I defined the method and it''s public, the view s...
2006 Aug 06
2
help with method_missing in ActiveRecord
...ss but I''m not sure how to go about doing that. In my example below, I get Stack Level too deep errors. class Foo < ActiveRecord::Base serialize :data, FooData def after_initialize self.data = eval("#{self.class}Data.new") unless self.data end def method_missing(method_name, *args) self.data.send "#{method_name}(#{args})" super end end class FooData attr_accessor item1, item2 end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060806/88f376b0/attachment.ht...
2006 Apr 20
11
dynamic mock object anyone?
Hi guys, got this problem with creating such a thing... hope anyone could help.. the problem: ok, now i have this mock object that would simulate a external rpc call. eg require ''models/xmlrpc_agent'' class XmlrpcAgent def create(params) 200 end end but the value of the value returned is fixed. which is quite hard for me to test the controller when different
2006 Apr 10
0
Inheriting data from one model to another
...= false # turn off generating read_methods otherwise method_missing won''t get called more than once # intercept calls to read attributes. If this instance has # a value return it, otherwise escalate the call to the parent_product def method_missing(method_id, *args, &block) method_name = method_id.to_s if @attributes.include?(method_name) if !read_attribute(method_name).nil? puts "Returning #{method_name}" return read_attribute(method_name) elsif @parent_product puts "Escalating #{method_name}" return @parent_pro...
2006 Jun 26
4
why can''t I call this without parentheses?
I have a little helper that lets me add legacy fields to models where they have common prefixes, suffixes, or something else weird. Here is the method signature: def legacy_fields(options = {}, *attributes) ..... end options is a hash containing things like :prefix => "post_" - and attributes is a list of attribute names. This gets mixed into the class with extend, so I call
2007 Dec 08
6
Rails 2.0 ActionMailer breaks my redmine render_message
...(v 0.6) as my major project manager, seems running fine w Rails 2.0 (slight modifs for paginations..) but I am stuck with a major error when sending a confirmation email : mailer.rb class Mailer < ActionMailer::Base .... # Renders a message with the corresponding layout def render_message(method_name, body) layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? ''layout.text.html.rhtml'' : ''layout.text.plain.rhtml'' body[:content_for_layout] = render(:file => method_name, :body => body) ActionView::Base.new(File.join(template_root, '...
2009 Apr 13
4
Creating Methods in the Model?
...siness logic into the model as possible. I want to do some data manipulation before I things are submitted to the database IE (Create a variable out of two submitted via form, as well as some other things.) Should this all be done in the model? If so how do I declare and call these methods? def method_name def self.method_name def class_name.method_name don''t seem to work for me? should I define them in the model and call them in controller? This doesn''t seem right to me? Any Help would be appropriated. -N -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~----...
2006 Sep 22
2
foo.expects(:blah).returns(10).then(11) syntax
...tation = Expectation.new(:expected_method) assert_nil expectation.invoke Index: lib/mocha/expectation.rb =================================================================== --- lib/mocha/expectation.rb (revision 854) +++ lib/mocha/expectation.rb (working copy) @@ -21,7 +21,7 @@ @method_name = method_name @count = 1 @parameters, @parameter_block = AlwaysEqual.new, nil - @invoked, @return_value = 0, nil + @invoked = 0 @backtrace = backtrace || caller end @@ -69,19 +69,29 @@ end def returns(value) - @return_value = value + re...
2007 Aug 08
1
Mocking Time, delegating to original object
...ssing around with the teardown order, I decided to modify the Expectation with a new method, .stops_mocking. Here are the changes I use, including a few monkey patches to push relevant objects down to where I want them, all wrapped up in a big ugly file. module Mocha class Mock def expects(method_name_or_hash, backtrace = nil, stub_method = nil) @stub_method = stub_method if method_name_or_hash.is_a?(Hash) then method_name_or_hash.each do |method_name, return_value| add_expectation(Expectation.new(self, method_name, backtrace).returns(return_value)) end...
2006 Aug 19
5
Form helpers don''t work with facade columns?
Hello all, I''ve been trying to use a facade column but I notice that the form helpers don''t seem to respect the facade. In the following example I''m trying to story the prices as Integer values but present them to the user as decimals. class Product < ActiveRecord::Base def price=(new_price) write_attribute(:price, Float(new_price)*100) end def price
2006 May 18
3
populating array of text_fields from an array of model objects
I have in my view the following: <% 0.upto(@num_performances) do |idx| -%> <%= text_field ''performance'', ''city'', :index => idx, %> <%= text_field ''performance'', ''venue'', :index => idx, %> <% end -%> and in my controller I have: @performance = [Performance.new("city" =>
2009 May 06
1
How to extend ActionMailer
I wish to extend ActionMailer::Base by method chaining a class instance variable: module ActionMailer class Base class << self def method_name ... What is the magic incantation to accomplish this? I cannot get this to work with action mailer: module MyMethods def self.include(base) base.alias_method_chain :method_name, :my_method def method_name_with_my_method ... stuff method_name_without_my_method end ......
2006 Aug 06
0
view cannot see the method...:(
Hi all, I just can''t figure why the view cannot find a method that I defined in another class. I do this in the view: <%= check_box("item_search_page", "method_name") Here, item_search_page is a variable in the controller, which creates a new ItemSearchPage object. class ItemSearchPage def method_name end end So, although I defined it and it''s public, the view says "undefined method ''method_name''. Thanks for your he...
2006 Feb 16
10
Confused over Model attrbutes and @ prefix
I''m confused about how attributes work in models. For example: class Page < ActiveRecord::Base attr_accessor :body def foo id # works @id # won''t work IIRC body # won''t work @body #works end end Why doesn''t everything work the same? Joe -- Posted via http://www.ruby-forum.com/.
2008 Aug 20
2
Re: Stubbing out ThinkingSphinx for Rspec
Thanks Wolas! Sorry if this seems like a newbie question, what am I supposed replace the stubbed_method_name with? Also, I came across the only thread on the Interwebs which seems to cover this topic - it''s over a year old, but I think they have a solution which could work around the issues you pointed out. However, I couldn''t work out how to get their subbing approach to work with t...
2006 Mar 01
3
Form helpers and overloaded methods - help!
Can someone explain why form helpers appear to bypass any model methods I override for fields that are bound to database fields? It would be great if someone could tell me how to force the form field, etc to call the method instead of looking at the database / attributes collection. Let''s say I have a column called ''price'' in my database table "books"
2005 Dec 18
0
Extending AR::B to provide translations
...ltitude of reasons (the educational value probably being most important). My table for the objects has columns named like en_name, de_name, fr_name, en_description, de_description, fr_description and so on. I plan to write method_missing for AR::B like this: class AR::B def method_missing(method_name) self.send((current_lang + method_name.to_s).to_sym) end end so that when I call obj.name it will return de_name or en_name or whatever based on the current language setting. The language will be set as part of the request url. I can write a before_filter for the ApplicationController...