Permalink
Browse files

Made projects_controller tests green. Removed last useless test case,…

… we only need functional ones for demo purposes.
  • Loading branch information...
1 parent 347bcef commit 1cf18211d0cafd4bcf271ed41aae74be00d335cb @alloy committed Mar 9, 2009
Showing with 14 additions and 67 deletions.
  1. +14 −10 test/functional/projects_controller_test.rb
  2. +0 −57 test/unit/project_test.rb
@@ -10,10 +10,10 @@
@project.tasks.create(:name => 'Try with our plugin')
@tasks = @project.tasks
- @valid_update_params = { :name => 'Dinner', :tasks_attributes => {
- @tasks.first.id => { :name => "Buy food" },
- @tasks.last.id => { :name => "Cook" }
- }}
+ @valid_update_params = { :name => 'Dinner', :tasks_attributes => [
+ { :id => @tasks.first.id, :name => "Buy food" },
+ { :id => @tasks.last.id, :name => "Cook" }
+ ]}
end
it "should update the name of the author" do
@@ -30,23 +30,23 @@
end
it "should destroy a missing task" do
- @valid_update_params[:tasks_attributes][@tasks.first.id]['_delete'] = '1'
+ @valid_update_params[:tasks_attributes].first['_delete'] = '1'
lambda {
put :update, :id => @project.id, :project => @valid_update_params
}.should.differ('Task.count', -1)
end
it "should add a new task" do
- @valid_update_params[:tasks_attributes]['new_12345'] = { :name => 'Take out' }
+ @valid_update_params[:tasks_attributes] << { :name => 'Take out' }
lambda {
put :update, :id => @project.id, :project => @valid_update_params
}.should.differ('Task.count', +1)
end
it "should reject any new task where the name is empty" do
- @valid_update_params[:tasks_attributes]['new_12345'] = { 'name' => '', :due_at => nil }
+ @valid_update_params[:tasks_attributes] << { 'name' => '', :due_at => nil }
lambda {
put :update, :id => @project.id, :project => @valid_update_params
@@ -56,16 +56,20 @@
end
it "should destroy a task and add a new one" do
- @valid_update_params[:tasks_attributes][@tasks.first.id]['_delete'] = '1'
- @valid_update_params[:tasks_attributes]['new_12345'] = { :name => 'Take out' }
+ @valid_update_params[:tasks_attributes].first['_delete'] = '1'
+ @valid_update_params[:tasks_attributes] << { :name => 'Take out' }
lambda {
put :update, :id => @project.id, :project => @valid_update_params
}.should.not.differ('Task.count')
end
it "should not be valid if a task is invalid" do
- put :update, :id => @project.id, :project => { :name => 'Nothing', :tasks_attributes => { @tasks.first.id => { :name => '' }, @tasks.last.id => { :name => '' }}}
+ put :update, :id => @project.id, :project => { :name => 'Nothing', :tasks_attributes =>[
+ { :id => @tasks.first.id, :name => '' },
+ { :id => @tasks.last.id, :name => '' }
+ ]}
+
project = assigns(:project)
project.should.not.be.valid
@@ -1,57 +0,0 @@
-require File.expand_path('../../test_helper', __FILE__)
-
-describe "Project" do
- before do
- @valid_params = {
- :name => 'NestedParams',
- :author_attributes => { :name => 'Eloy' },
- :tasks_attributes => {
- 'new_1' => { :name => 'Check other implementations' },
- 'new_2' => { :name => 'Try with our plugin' }
- }.with_indifferent_access
- }
-
- @project = Project.create(@valid_params)
- @author = @project.author
- @tasks = @project.tasks
-
- @valid_update_params = {
- :name => 'Dinner',
- :author_attributes => { :name => 'Mighty Mo' },
- :tasks_attributes => {
- @tasks.first.id.to_s => { :name => "Buy food" },
- @tasks.last.id.to_s => { :name => "Cook" }
- }
- }
- end
-
- it "should take a hash with an author hash and update the author" do
- @project.attributes = @valid_update_params
- @project.author.name.should == 'Mighty Mo'
- end
-
- it "should take a hash with tasks hashes and create Task records for them" do
- lambda do
- Project.create(@valid_params)
- end.should.differ('Project.count + Task.count', +3)
-
- @project.name.should == 'NestedParams'
- @project.tasks.map(&:name).sort.should == ['Check other implementations', 'Try with our plugin']
- end
-
- it "should update it's own attributes and the attributes of the child tasks" do
- @project.attributes = @valid_update_params
-
- @project.name.should == 'Dinner'
- @project.tasks.map(&:name).sort.should == ['Buy food', 'Cook']
- end
-
- it "should automatically save the tasks when the project is saved" do
- @project.name = 'NestedParams and AutosaveAssociation'
- @project.tasks.first.name = 'Just start!'
- @project.save; @project.reload
-
- @project.name.should == 'NestedParams and AutosaveAssociation'
- @project.tasks.first.name.should == 'Just start!'
- end
-end

0 comments on commit 1cf1821

Please sign in to comment.