Changeset 295
- Timestamp:
- 10/31/08 20:04:48 (2 months ago)
- Files:
-
- trunk/app/controllers/tools_controller.rb (modified) (1 diff)
- trunk/app/models/tool.rb (modified) (2 diffs)
- trunk/db/migrate/20081031011805_add_tool_author.rb (added)
- trunk/spec/controllers/tools_controller_spec.rb (modified) (2 diffs)
- trunk/spec/models/tool_spec.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/tools_controller.rb
r257 r295 65 65 def create 66 66 @tool = Tool.new(params[:tool]) 67 @tool.current_user = current_user 67 68 68 69 respond_to do |format| trunk/app/models/tool.rb
r240 r295 1 1 ##### 2 2 # 3 # Copyright 200 7Chris Strom, Robin Strom3 # Copyright 2008 Chris Strom, Robin Strom 4 4 # 5 5 # This file is part of EEE Code. … … 22 22 has_many :recipes, :through => :recipe_tools 23 23 24 belongs_to :author, :class_name => 'User' 25 26 validates_presence_of :title, :label 24 27 validates_uniqueness_of :label 25 28 require_author 29 30 def before_validation 31 self.label = title.gsub(/\W/, "_").downcase if self.attribute_present?("title") 32 end 26 33 end trunk/spec/controllers/tools_controller_spec.rb
r240 r295 299 299 it "should create a new tool" do 300 300 Tool.should_receive(:new).with({}).and_return(@tool) 301 @tool.should_receive(:current_user=) 301 302 post_with_successful_save 302 303 end 303 304 304 305 it "should redirect to the new tool on successful save" do 306 @tool.should_receive(:current_user=) 305 307 post_with_successful_save 306 308 response.should redirect_to(tools_url) … … 308 310 309 311 it "should re-render 'new' on failed save" do 312 @tool.should_receive(:current_user=) 310 313 post_with_failed_save 311 314 response.should render_template('new') trunk/spec/models/tool_spec.rb
r240 r295 6 6 end 7 7 8 it "should be valid with a current user " do8 it "should be valid with a current user and a title" do 9 9 @tool.should_not be_valid 10 10 attach_valid_user(@tool) 11 @tool.title = 'Foo' 11 12 @tool.should be_valid 12 13 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 13 26 end
