Changeset 295

Show
Ignore:
Timestamp:
10/31/08 20:04:48 (2 months ago)
Author:
cstrom
Message:

A tool requires an author for updates.

Fixes #60

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/tools_controller.rb

    r257 r295  
    6565  def create 
    6666    @tool = Tool.new(params[:tool]) 
     67    @tool.current_user = current_user 
    6768 
    6869    respond_to do |format| 
  • trunk/app/models/tool.rb

    r240 r295  
    11##### 
    22# 
    3 # Copyright 2007 Chris Strom, Robin Strom 
     3# Copyright 2008 Chris Strom, Robin Strom 
    44# 
    55# This file is part of EEE Code. 
     
    2222  has_many :recipes, :through => :recipe_tools 
    2323 
     24  belongs_to :author, :class_name => 'User' 
     25 
     26  validates_presence_of :title, :label 
    2427  validates_uniqueness_of :label 
    2528  require_author 
     29 
     30  def before_validation 
     31    self.label = title.gsub(/\W/, "_").downcase if self.attribute_present?("title") 
     32  end 
    2633end 
  • trunk/spec/controllers/tools_controller_spec.rb

    r240 r295  
    299299  it "should create a new tool" do 
    300300    Tool.should_receive(:new).with({}).and_return(@tool) 
     301    @tool.should_receive(:current_user=) 
    301302    post_with_successful_save 
    302303  end 
    303304 
    304305  it "should redirect to the new tool on successful save" do 
     306    @tool.should_receive(:current_user=) 
    305307    post_with_successful_save 
    306308    response.should redirect_to(tools_url) 
     
    308310 
    309311  it "should re-render 'new' on failed save" do 
     312    @tool.should_receive(:current_user=) 
    310313    post_with_failed_save 
    311314    response.should render_template('new') 
  • trunk/spec/models/tool_spec.rb

    r240 r295  
    66  end 
    77 
    8   it "should be valid with a current user" do 
     8  it "should be valid with a current user and a title" do 
    99    @tool.should_not be_valid 
    1010    attach_valid_user(@tool) 
     11    @tool.title = 'Foo' 
    1112    @tool.should be_valid 
    1213  end 
     14 
     15  it "should require a current user for updates" do 
     16    @tool.should_not be_valid 
     17    @tool.title = 'Foo' 
     18    @tool.should_not be_valid 
     19  end 
     20 
     21  it "should require a title for updates" do 
     22    @tool.should_not be_valid 
     23    attach_valid_user(@tool) 
     24    @tool.should_not be_valid 
     25  end 
    1326end