similar to: Testing Rails Associations

Displaying 20 results from an estimated 7000 matches similar to: "Testing Rails Associations"

2010 Apr 15
12
[PATCH] Add :touch option to has_many associations
Hi, it would be nice to have the touch option in has_many associations also. I have a scenario like this: An user has some credit (money) and some advertises. Each advertise can be enabled or disabled depending on some rules. One of the rules is that the user should have money. Each time the money of the user change, the advertises are touched, enabled/disabled and then cached, as they are much
2006 May 11
6
ActiveRecord associations
Can someone clarify this for me? Suppose I have two tables like: class Company < ActiveRecord::Base belongs_to :category end class Category < ActiveRecord::Base has_many :companies end I understand that the belongs_to causes related companies to be read from the db when I ask for a category. I suspect SQL something like select * from categories, companies where category.id
2007 Apr 06
3
How to find rows where no row in associated table exists?
Basically, how do I do this "The Rails Way(tm)" SELECT * FROM beta_users u LEFT JOIN beta_codes c ON u.id = c.beta_user_id AND c.code IS NULL At the moment I''m using find_by_sql, and that works Ok, but what would be the Rails way? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on
2009 Mar 13
1
Problem saving nested attributes for has_many associations (Rails 2.3 RC2 and Edge)
I''ve tested this on both 2.3 RC2 and Edge. This pastie contains model, helper and view: http://pastie.org/415742 When I save a vocabulary - its terms don''t save. I''m fairly sure it worked in RC1. Would appreciate any insight. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on
2007 Oct 19
11
Patch idea for rspec_on_rails
I recently wrote a matcher for testing AR associations which allows you to specify things like: Foo.should have_many(:bars).through(:bazes) I''m pretty darned proud of it and a couple of people have suggested that I should submit it to the rspec_on_rails project. Before I go to the trouble of writing out rdoc and fully spec''ing it, I just wanted to make sure this was
2006 Jan 10
5
Select Tag and Associations
Hi there, I''ve been working on this for awhile and have finally decided to ask for a little guidance.I have a slight problem trying to save a selection. I have two models: A "Posting" has_many "Categories", and a "Category" belongs_to one "Posting". With that said, in the posting model I have "has_many :categories" and within the
2009 Mar 25
11
ActiveRecord: Nested :include erroneous behavior
Hi, Found a simple example breaking on moving to 2.2 from 2.0. This example illustrates the usage of nested :include finder options. class Book < ActiveRecord::Base has_many :distributors end class Distributor < ActiveRecord::Base belongs_to :book has_many :agents end class Agent < ActiveRecord::Base belongs_to :distributor has_many :shops end class Shop <
2011 Feb 28
3
Feature: ActiveResource - Adding associations through reflections
Hello everyone, I''m new in contributing and i saw in the contributing-guides, that i have to write an email at this list. I hope, that''s the right place for this. If it''s not, i''M really sorry.. ;) Could someone please give me feedback about this lighthouse-ticket?
2006 Apr 19
2
Using Reflections to find out ActiveRecord class association
I want to find out what are the associations with another active record class. So If my class is as below: Class Component < ActiveRecord::Base has_many :branches end class Branch < ActiveRecord::Base belongs_to :component end and then I do Component.reflections[:branches].active_record I would expect that to be Branch but it is in fact Component. The inspection of
2006 Oct 24
5
Radrails and RSpec
Hi all, Does anyone know how to get radrails to use RSpec specs instead of tests? Cheers --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to
2007 Aug 12
3
Scope and specing models
Hello all, I''m currently having an issue with some specs, specifically scope issues (probably more of a scope issue than a spec issue at this point)... Here''s the error: ActiveRecord::AssociationTypeMismatch in ''A new User should know what role it has'' Role expected, got NilClass D:/ruby/projects/restful_authentication_test/config/../app/models/role.rb:5:in
2006 Jul 18
6
Replace Pound/Pens/Balance with Ruby alternative
Right now you can use either Pens/Balance/Pound to put in front of some Mongrels and it works really good (easy to setup too!). I got to thinking, would it be possible to mimic what Pens/Balance/Pound does in pure Ruby (yeah, I know the answer is yes)? I guess I''m looking for a starting point. Does one simply write an HTTP listener that then redirects the calls to Mongrel? Is
2007 Jul 18
10
Rails - Mock going out of scope?
Hello list, I think I have a rails related RSpec problem with a mock going out of scope on a recursive call to a model. The code is at: http://pastie.textmate.org/79821 if you want to see it highlighted. I have pasted it below as well. Basically, I have an acts_as_nested_set model called "Node", which works fine. I have a function which finds the language name of the node instance.
2009 Feb 27
5
Polymorphic association..explain the extra query ?
Can anyone explain to me the sql query done in the last step : http://pastie.org/402200 -- Arpit Jain --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group,
2008 Oct 17
1
How to best start from scratch implementing a ERM diagram?
Hey people, I''m starting a new project and just finished creating the ERM diagram with about 30 tables. There are quite some tables with foreign keys so I''m not sure how to start creating the controllers/models. How should I start creating controllers/models? Should I first create all tables without foreign key? Should I just start somewhere and add them radomly? I''m
2011 Mar 06
3
HABTM Association with STI model
Is there a better way to do this? It looks really ugly! http://pastie.org/1640550 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to
2007 Jul 25
5
set_default_values rocket science - continuing after_initialize/after_find misfeature
Just starting a new thread so that it''s easy to follow. I just submitted a patch at trac to add a new class method called "set_default_values" ( not a great name I think ), which lets you do all kinds of crazy stuff with setting default values. This ticket is at http://dev.rubyonrails.org/ticket/9093 and example pastie is at http://pastie.caboo.se/81925 It also lets you make
2007 Mar 22
2
Enumerable sum oddity
Hi. In this setup "account has_many :consultations". Can anyone explain the following behaviour to me? Rails 1.2.2. The "sum" method should return 0 for an empty array. >> a = Account.find(1) => #<Account:0x39c80a8 @attributes={...} >> a.consultations => [] >> a.consultations.sum(&:foo) ArgumentError: wrong number of arguments (1 for 2)
2019 Jun 11
2
Aliasing rules for const type pointer
Hi, I'm not clear with the aliasing rules for the pointer pointing to const memory. It will be great help if someone clarify my doubts. Consider below test program: int foo(int *A, int *B, const int *C, int len) { for (int i = 0; i < len; i++) A[i] = B[i] + *C; } In this test case the type for "C" is const int * type, it means the pointer is pointing to a memory which is
2006 Aug 16
3
Reflecting on associations
Is there an easy way to programatically work out the associations on a model? If not, is there a positive reason it was omitted, or is it just something that hasn''t been implemented yet? Thanks Gareth