similar to: Easy AR association stubbing

Displaying 20 results from an estimated 120 matches similar to: "Easy AR association stubbing"

2007 Oct 08
6
spec''in controllers request for nested routes
describe PlayersController, "handling GET /saltmines/games/1/players" do before do @game = mock_model(Game, :to_param => "1") @game.stub_association!(:players, :find => mock_model(Player)) end def do_get get :index, :game_id => @game end it "should be successful" do do_get response.should be_success end it "should
2007 Oct 26
3
Specing with Subdomains as Account Keys
How do you go about implementing and rspecing subdomains as account keys? I''m sure that this must be an issues for others as well. So I have an app using subdomains as account keys. The Application Controller sets up @current_company in a before filter. Everything is done within the context of the @current_company. After reading about Demeter''s Revenge
2007 Jul 24
6
Mocking Access Control
I''m trying to jump on the TDD/BDD bandwagon, but am having trouble understanding how i should mock my user. The user has a habtm relationship to a roles model (acl_system2 plugin), but I''m not sure how to tell rspec about a model. My code: describe UsersController do integrate_views before(:each) do @user = mock_model(User)
2009 Dec 07
1
Cucumber and general Ruby question
Hello, I have this cucumber step definition: Given /^the site has pages "(.+)" and "(.+)"$/ do | page_1, page_2 | Page.create :title => page_1 if Page.find_by_title(page_1).nil? Page.create :title => page_2 if Page.find_by_title(page_2).nil? end This works, but obviously I would like to DRY it up. I was thinking along the lines. Given /^the site has pages
2007 Oct 05
13
spec''ing view render partial collection, local variable not found
I''m trying to spec out a render partial collection but I get the following error 2) NoMethodError in ''/games/_game.rhtml should show game name'' undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in `matches?''
2008 Apr 07
5
Associations errors
undefined method `each'' for 0:Fixnum at line @school = School.find_by_title(params[:school_id].gsub(''-'', " ")) for team in @school.teams ........ end @school does exist cause i tried with .find(:first) and it gave the same error. Also I''m getting undefined method `reject'' for #<Game:0x24ca1c4> From @home.game_ids = @game
2009 May 12
4
has_many :through and scopes: how to mutate the set of associated objects?
I have a model layer containing Movie, Person, Role, and RoleType, making it possible to express facts such as "Clint Easterbunny is director of the movie Gran Milano". The relevant model and associations look like this class Movie < ActiveRecord::Base has_many :roles, :include => :role_type, :dependent => :destroy has_many :participants, :through => :roles, :source
2005 Dec 28
1
making has_and_belongs_to_many save more elegant
When a user creates a post I also want to save all the tags associated with it. I do that in the post_controller like this presently: def save @post = Post.new(@params[:post]) @tags = Tag.new(@params[:tags]) @post.user_id = session[:id] if @post.save @tags.title.split('','').each do |tag| present_tag = Tag.find_by_title(tag.strip) present_tag =
2005 Nov 04
0
habtm's collection_remove deprecated
Hi, I''m new to Rails and I have a question about the collection_remove method added to models with has_and_belongs_to_many associations. This function is not listed in the documentation, but is still there in Rails 0.14. I noticed this in the source for has_and_belongs_to_many: # deprecated api . . . deprecated_remove_association_relation(association_name) What does it mean for a
2007 Aug 26
4
howto regressions on environment.rb in Rails projects
How would one write a spec on environment.rb in a rails app? I was requiring a gem in environment.rb, but received a "MissingSourceError". Generally, ruby raises a LoadError when it can''t find a gem, but rails overrides this to raise a MissingSourceError (since rails is expecting a required file to be in lib/...). How would I write a spec to override this behavior,
2006 Jan 04
5
routing title in url
I''ve set up my app to display a post by retrieving its title instead of id, which works fine, except it looks like this "/post/the+title+of+post%3F" and I want it to be "the_title_of_post?" with underscores instead of plusses. Can anyone shed light? -- Posted via http://www.ruby-forum.com/.
2007 Mar 29
21
a better "should have valid associations"
This is pretty much the same as last time around, if you recall. Thanks to Wilson for converting to the new form. I''ve added a few lines. Basically, it iterates over your model associations and does two things. - First, just try to call the association. Usually fixes speeling erors or other such silliness. - Second, try to find a record with an :include on the association. This
2006 Dec 29
4
Strange HABTM behavior against SQL Server (AR 1.14.4)
All, Win XP SQL Server 2000 Rails 1.1.6 (AR 1.14.4) I have two objects (Job and Warning) in a HABTM relationship. Below are the pertinent sections of the model files and the schema for the join table. job.rb: class Job < ActiveRecord::Base has_and_belongs_to_many :warnings, :foreign_key => ''JobReferenceNumber'' set_table_name :JobData set_primary_key
2008 Aug 27
6
Restful routes
Hi, I''m pretty new to the concept of restful routing and am struggling to find any rails 2 info that helps with what I''m looking for. I have a regular scaffold setup and the routes are setup as default map.resources :pages I would like to be able to use titles in the url rather than relying on the id. Eg localhost:3000/pages/sometitle instead of just localhost:3000/pages/1
2005 Dec 31
6
habtm recursion via destroy_without_callbacks
I am having a problem with two models that each have a HABTM relationship to the other. For example: CREATE TABLE people (id INT, name TEXT); CREATE TABLE teams (id INT, name TEXT); CREATE TABLE people_teams (person_id INT, team_id INT); The person model has: has_and_belongs_to_many :teams And the team model has: has_and_belongs_to_many :people The trouble comes when trying to destroy
2006 May 11
0
creating variables on the fly with a loop
I''m trying to clean up some of my sloppy code, and one of the things I''m working on is trying to make this huge group of variables a bit more elegant. My variables look like this: @business_core_courses = Category.find_by_title(''business_core_courses'').courses @written_communication = Category.find_by_title(''written_communication'').courses
2006 Jul 12
10
Rails: Good for everything?
My department is in a battle right now. We have some very por PHP people and very pro Rails people. The php guys make a good argument that Rails is good for new applications where we dictate the DB schema. PHP shines where we go into an existing application, or a new one where multiple databases or possibly legacy systems are involved. The PHP guys basically say Rails is good for Web 2.0
2009 Jan 31
0
save after delete returns true but actually fails
Hi, I''m using Rails 2.2.2. I noticed that creating two references to the same database ActiveRecord object, then deleting with one of them, followed by saving with the other, true is returned, but no new record is actually saved. e.g.: doc=Document.new(:title => "sam''s speciality") doc.save doc.id # ==> 23 doc2=Document.find_by_title("sam''s
2010 Mar 08
0
Nested Resources + Namespace + Friendly URL
Hi, all In my rails app I have a controller called Dashboard::MenusController with a namespace dashboard. I have a model Company too, where its has_many :menus So, I have the code above in my route.rb map.namespace (:dashboard) do |dashboard| dashboard.resources :companies, :has_many => :menus end With this route I can create a new menu by: dashboard/companies/1/
2006 Mar 20
24
Newbie Question about Custom Classes
Sorry if this is a complete newbish question, but I''m trying to wrap my head around creating custom classes in my rails webapp. I''m normally a Java developer, but I figured I''d give RoR a try and see how I like it, and whether it would be useful for production use with a new client. Anyways, what are the best practices for custom classes? Where and/or how do I create