From 88663f4ae91403b2806d4048c1a5ca01b4971802 Mon Sep 17 00:00:00 2001 From: Rafael George Date: Fri, 10 Aug 2012 08:09:21 -0400 Subject: [PATCH 1/6] Add pending specs for the feature --- spec/tasks/create_spec.rb | 43 +++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/spec/tasks/create_spec.rb b/spec/tasks/create_spec.rb index 1311f61..8b83dd4 100644 --- a/spec/tasks/create_spec.rb +++ b/spec/tasks/create_spec.rb @@ -3,10 +3,10 @@ describe "Create Task" do context "Given Project X" do let(:tm) { TaskMapper.new :in_memory, - :user => 'chuck', :password => 'norris' } - + :user => 'chuck', :password => 'norris' } + let(:project) { tm.create_project :name => 'Project X' } - + let(:task) { project.create_task attributes } describe :task! do @@ -14,17 +14,17 @@ it { should respond_to :task! } end + let(:attributes) {{ + :title => 'Test Task', + :description => 'This is a test', + :requestor => 'Ron Evans', + :assignee => 'Omar Rodriguez', + }} + context "When I create a task for Project X" do - let(:attributes) {{ - :title => 'Test Task', - :description => 'This is a test', - :requestor => 'Ron Evans', - :assignee => 'Omar Rodriguez', - }} - describe :task do subject { task } - + its(:id) { should == 1 } its(:title) { should == 'Test Task' } its(:description) { should == 'This is a test'; } @@ -33,22 +33,35 @@ its(:project_id) { should == 1 } end end - + + pending "When create a project passing priority and status" do + let(:attributes_with_status_priority) do + attributes.merge! :status => :open, :priority => :low + end + + describe :task do + subject { project.create_task attributes_with_status_priority } + + its(:status) { should == :open } + its(:priority) { should == :low } + end + end + context "When I create a project with nil name" do let(:attributes) {{ :title => nil, :requestor => 'Ron' }} let(:error) { catch_error(TaskMapper::Exceptions::RequiredAttribute) { task } } - + describe :error do subject { error } it { should_not be_nil } its(:message) { should match /Task title is required/ } end end - + context "When I create a project with nil requestor" do let(:attributes) {{ :title => "test" }} let(:error) { catch_error(TaskMapper::Exceptions::RequiredAttribute) { task } } - + describe :error do subject { error } it { should_not be_nil } From affa46cf299224b8485077629af35626c1875a01 Mon Sep 17 00:00:00 2001 From: Rafael George Date: Fri, 10 Aug 2012 08:10:22 -0400 Subject: [PATCH 2/6] Add spec for testing creation of task with status and priority --- spec/tasks/create_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/tasks/create_spec.rb b/spec/tasks/create_spec.rb index 8b83dd4..1244b02 100644 --- a/spec/tasks/create_spec.rb +++ b/spec/tasks/create_spec.rb @@ -34,7 +34,7 @@ end end - pending "When create a project passing priority and status" do + context "When create a project passing priority and status" do let(:attributes_with_status_priority) do attributes.merge! :status => :open, :priority => :low end From 273899d5c2c3ab1dbcd1b986511824f84d42e88d Mon Sep 17 00:00:00 2001 From: Rafael George Date: Fri, 10 Aug 2012 10:06:36 -0400 Subject: [PATCH 3/6] Refactor: Move example of validation of status and priority --- spec/tasks/create_spec.rb | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/spec/tasks/create_spec.rb b/spec/tasks/create_spec.rb index 1244b02..ef14e3e 100644 --- a/spec/tasks/create_spec.rb +++ b/spec/tasks/create_spec.rb @@ -19,6 +19,8 @@ :description => 'This is a test', :requestor => 'Ron Evans', :assignee => 'Omar Rodriguez', + :status => :open, + :priority => :low }} context "When I create a task for Project X" do @@ -31,19 +33,8 @@ its(:requestor) { should == 'Ron Evans' } its(:assignee) { should == 'Omar Rodriguez' } its(:project_id) { should == 1 } - end - end - - context "When create a project passing priority and status" do - let(:attributes_with_status_priority) do - attributes.merge! :status => :open, :priority => :low - end - - describe :task do - subject { project.create_task attributes_with_status_priority } - - its(:status) { should == :open } - its(:priority) { should == :low } + its(:status) { should == :open } + its(:priority) { should == :low } end end From 26611ce70ac2224353b531daaee6e405f2b87d9a Mon Sep 17 00:00:00 2001 From: Rafael George Date: Fri, 10 Aug 2012 11:02:28 -0400 Subject: [PATCH 4/6] Add initial implementation for validating status --- lib/taskmapper/entities/task.rb | 9 +++++++-- lib/taskmapper/exceptions.rb | 6 ++++++ spec/tasks/create_spec.rb | 15 +++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/taskmapper/entities/task.rb b/lib/taskmapper/entities/task.rb index 11bf4d0..80c0541 100644 --- a/lib/taskmapper/entities/task.rb +++ b/lib/taskmapper/entities/task.rb @@ -38,9 +38,14 @@ def delete end def validate - validate_presence_of :title - validate_presence_of :requestor + validate_presence_of :title + validate_presence_of :requestor + validate_inclusion_of :status, :in => [:open, :close] end + + def validate_inclusion_of(*args) + + end def create_comment(attrs) comments.create attrs diff --git a/lib/taskmapper/exceptions.rb b/lib/taskmapper/exceptions.rb index 57950b3..4f7feef 100644 --- a/lib/taskmapper/exceptions.rb +++ b/lib/taskmapper/exceptions.rb @@ -21,5 +21,11 @@ def initialize(provider, entities, method, args) super "Provider #{provider} does not define #{entities}##{method}#{args}" end end + + class InvalidStatus < TaskMapperException + def initialize(*values) + super "Status should has the following values #{values.join(',')}" + end + end end end diff --git a/spec/tasks/create_spec.rb b/spec/tasks/create_spec.rb index ef14e3e..e3e36ca 100644 --- a/spec/tasks/create_spec.rb +++ b/spec/tasks/create_spec.rb @@ -38,7 +38,18 @@ end end - context "When I create a project with nil name" do + pending "When I create a task with nil status" do + let(:attributes_without_status) {{ :status => nil }} + let(:error) { catch_error(TaskMapper::Exceptions::InvalidStatus) { task } } + + describe :error do + subject { error } + it { should_not be_nil } + its(:message) { should match /Task status should be :open or :close/ } + end + end + + context "When I create a task with nil title" do let(:attributes) {{ :title => nil, :requestor => 'Ron' }} let(:error) { catch_error(TaskMapper::Exceptions::RequiredAttribute) { task } } @@ -49,7 +60,7 @@ end end - context "When I create a project with nil requestor" do + context "When I create a task with nil requestor" do let(:attributes) {{ :title => "test" }} let(:error) { catch_error(TaskMapper::Exceptions::RequiredAttribute) { task } } From aad0118479649f6df276abe6d3de155c4a21dc7d Mon Sep 17 00:00:00 2001 From: Rafael George Date: Fri, 10 Aug 2012 08:09:21 -0400 Subject: [PATCH 5/6] Task #26: Create a Task, Scenario: Passing priority and status, Scenario: Invalid priority, Scenario: Invalid status * Add pending specs for the feature * Add spec for testing creation of task with status and priority * Refactor: Move example of validation of status and priority * Add initial implementation for validating status * Add valid values for task status field * Refactor: Move validate_inclusion_of to entity --- lib/taskmapper/entities/entity.rb | 7 ++++ lib/taskmapper/entities/task.rb | 17 ++++++-- lib/taskmapper/exceptions.rb | 6 +++ spec/task_comments/create_spec.rb | 2 +- spec/task_comments/search_spec.rb | 2 +- spec/task_comments/update_spec.rb | 1 + spec/tasks/create_spec.rb | 41 ++++++++++++++------ spec/tasks/delete_spec.rb | 4 +- spec/tasks/search_spec.rb | 64 +++++++++++++++---------------- spec/tasks/update_spec.rb | 7 ++-- 10 files changed, 98 insertions(+), 53 deletions(-) diff --git a/lib/taskmapper/entities/entity.rb b/lib/taskmapper/entities/entity.rb index 772003f..24676f0 100644 --- a/lib/taskmapper/entities/entity.rb +++ b/lib/taskmapper/entities/entity.rb @@ -18,6 +18,13 @@ def validate_presence_of(attribute) end end + def validate_inclusion_of(validation_criteria) + attr = validation_criteria[:attr] + in_values = validation_criteria[:in] + msg = validation_criteria[:msg] + raise Exceptions::InvalidRangeValue.new(msg, in_values) unless in_values.include? self.__send__ attr + end + def update_attributes(attrs) attrs.each do |key, value| self.send("#{key}=".to_sym, value) diff --git a/lib/taskmapper/entities/task.rb b/lib/taskmapper/entities/task.rb index 7e9be9f..fa9859e 100644 --- a/lib/taskmapper/entities/task.rb +++ b/lib/taskmapper/entities/task.rb @@ -38,9 +38,19 @@ def delete end def validate - validate_presence_of :title - validate_presence_of :requestor + validate_presence_of :title + validate_presence_of :requestor + validate_inclusion_of :attr => :status, + :in => [:open, :close], + :msg => "Status has to be" end + + def validate_inclusion_of(validation_criteria) + attr = validation_criteria[:attr] + in_values = validation_criteria[:in] + msg = validation_criteria[:msg] + raise Exceptions::InvalidRangeValue.new(msg, in_values) unless in_values.include? self.__send__ attr + end def create_comment(attrs) comments.create attrs @@ -62,7 +72,8 @@ def to_hash :description => self.description, :requestor => self.requestor, :assignee => self.assignee, - :project_id => self.project_id + :project_id => self.project_id, + :status => self.status }) end diff --git a/lib/taskmapper/exceptions.rb b/lib/taskmapper/exceptions.rb index 57950b3..9dd6122 100644 --- a/lib/taskmapper/exceptions.rb +++ b/lib/taskmapper/exceptions.rb @@ -21,5 +21,11 @@ def initialize(provider, entities, method, args) super "Provider #{provider} does not define #{entities}##{method}#{args}" end end + + class InvalidRangeValue < TaskMapperException + def initialize(msg, *values) + super "#{msg} #{values.join(',')}" + end + end end end diff --git a/spec/task_comments/create_spec.rb b/spec/task_comments/create_spec.rb index e70807f..c54a637 100644 --- a/spec/task_comments/create_spec.rb +++ b/spec/task_comments/create_spec.rb @@ -9,7 +9,7 @@ context "Given Task X" do let(:task_x) { project_x.create_task :title => "Task X", - :requestor => "Omar" } + :requestor => "Omar", :status => :open } context "Given valid attributes" do context "When I create a task comment on Task X" do before :all do diff --git a/spec/task_comments/search_spec.rb b/spec/task_comments/search_spec.rb index c4f216e..e526109 100644 --- a/spec/task_comments/search_spec.rb +++ b/spec/task_comments/search_spec.rb @@ -11,7 +11,7 @@ context "And 'learn ukulele' have the 'buy ukulele' task" do let(:buy_ukulele) do learn_ukulele.create_task :title => "Buy Ukulele", - :requestor => "Me" + :requestor => "Me", :status => :open end context "And 'buy ukulele' have the following comments" do diff --git a/spec/task_comments/update_spec.rb b/spec/task_comments/update_spec.rb index 01bdc78..468d1a6 100644 --- a/spec/task_comments/update_spec.rb +++ b/spec/task_comments/update_spec.rb @@ -13,6 +13,7 @@ :priority => 1, :assignee => "Omar", :requestor => "Ron", + :status => :open end context "And 'Task X' have a comment" do diff --git a/spec/tasks/create_spec.rb b/spec/tasks/create_spec.rb index 1311f61..47d90c1 100644 --- a/spec/tasks/create_spec.rb +++ b/spec/tasks/create_spec.rb @@ -3,10 +3,10 @@ describe "Create Task" do context "Given Project X" do let(:tm) { TaskMapper.new :in_memory, - :user => 'chuck', :password => 'norris' } - + :user => 'chuck', :password => 'norris' } + let(:project) { tm.create_project :name => 'Project X' } - + let(:task) { project.create_task attributes } describe :task! do @@ -14,41 +14,60 @@ it { should respond_to :task! } end + context "When I create a task for Project X" do let(:attributes) {{ :title => 'Test Task', :description => 'This is a test', :requestor => 'Ron Evans', :assignee => 'Omar Rodriguez', + :status => :open, + :priority => :low }} - + describe :task do subject { task } - + its(:id) { should == 1 } its(:title) { should == 'Test Task' } its(:description) { should == 'This is a test'; } its(:requestor) { should == 'Ron Evans' } its(:assignee) { should == 'Omar Rodriguez' } its(:project_id) { should == 1 } + its(:status) { should == :open } + its(:priority) { should == :low } + end + end + + context "When I create a task with nil status" do + let(:attributes) { {:title => 'Test Task', :requestor => 'Ron Evans', :status => nil} } + let(:task_without_status) { project.create_task attributes } + let(:error) do + catch_error(TaskMapper::Exceptions::InvalidRangeValue) { task_without_status } + end + + describe :error do + subject { error } + it { should_not be_nil } + its(:message) { should match /Status has to be/ } end end - - context "When I create a project with nil name" do + + context "When I create a task with nil title" do let(:attributes) {{ :title => nil, :requestor => 'Ron' }} let(:error) { catch_error(TaskMapper::Exceptions::RequiredAttribute) { task } } - + describe :error do subject { error } it { should_not be_nil } its(:message) { should match /Task title is required/ } end end - - context "When I create a project with nil requestor" do + + context "When I create a task with nil requestor" do let(:attributes) {{ :title => "test" }} let(:error) { catch_error(TaskMapper::Exceptions::RequiredAttribute) { task } } - + describe :error do subject { error } it { should_not be_nil } diff --git a/spec/tasks/delete_spec.rb b/spec/tasks/delete_spec.rb index be63630..d7cfbd5 100644 --- a/spec/tasks/delete_spec.rb +++ b/spec/tasks/delete_spec.rb @@ -10,10 +10,10 @@ context "And Project X have Tasks X and Y" do before :all do project_x.task! :title => "Task X", - :requestor => "Me" + :requestor => "Me", :status => :open project_x.task! :title => "Task Y", - :requestor => "Me" + :requestor => "Me", :status => :open end context "When I delete Task X" do diff --git a/spec/tasks/search_spec.rb b/spec/tasks/search_spec.rb index 5517713..855c601 100644 --- a/spec/tasks/search_spec.rb +++ b/spec/tasks/search_spec.rb @@ -4,58 +4,58 @@ let(:tm) do TaskMapper.new :in_memory, :user => 'mark', :password => 'twain' end - + context "Given the following projects" do let(:secret_project) { tm.project! :name => 'Plan to kill Justin Bieber' } - + let(:learn_ukulele) { tm.project! :name => 'Leard to play ukulele' } - + context "Given the following tasks" do before do - secret_project.create_task :title => "Buy bomb materias", - :description => "Go to hardware store", - :requestor => "Ludwig van Beethoven" - - secret_project.create_task :title => "Contruct a bomb", - :description => "Visit howstuffworks.com", - :requestor => "Ludwig van Beethoven" - - secret_project.create_task :title => "Install the bomb in Justin Bieber's house", - :description => "Go there and do it", - :requestor => "Ludwig van Beethoven" - - secret_project.create_task :title => "Detonate bomb with remote controller", - :description => "Save the world", - :requestor => "Ludwig van Beethoven" - - learn_ukulele.create_task :title => "Buy Ukulele", + secret_project.create_task :title => "Buy bomb materias", + :description => "Go to hardware store", + :requestor => "Ludwig van Beethoven", :status => :open + + secret_project.create_task :title => "Contruct a bomb", + :description => "Visit howstuffworks.com", + :requestor => "Ludwig van Beethoven", :status => :open + + secret_project.create_task :title => "Install the bomb in Justin Bieber's house", + :description => "Go there and do it", + :requestor => "Ludwig van Beethoven", :status => :open + + secret_project.create_task :title => "Detonate bomb with remote controller", + :description => "Save the world", + :requestor => "Ludwig van Beethoven", :status => :open + + learn_ukulele.create_task :title => "Buy Ukulele", + :requestor => "Me", :status => :open - :requestor => "Me" - - learn_ukulele.create_task :title => "Buy Ukulele book", - :requestor => "Me" - - learn_ukulele.create_task :title => "Practice hard", - :requestor => "Me" + learn_ukulele.create_task :title => "Buy Ukulele book", + :requestor => "Me", :status => :open + + learn_ukulele.create_task :title => "Practice hard", + :requestor => "Me", :status => :open end - + context "Retrieve all tasks" do subject { tm.tasks } - + its(:count) { should == 7 } end - + context "Retrieve Plan to kill Justin Bieber' project tasks" do subject { secret_project.tasks } its(:count) { should == 4 } - + describe :second do subject { secret_project.tasks[1] } its(:id) { should == 2 } its(:title) { should == "Contruct a bomb" } its(:description) { should == "Visit howstuffworks.com" } + its(:status) { should == :open } end - + describe :fourth do subject { secret_project.tasks[3] } its(:id) { should == 4 } diff --git a/spec/tasks/update_spec.rb b/spec/tasks/update_spec.rb index 2cd2ccf..ece89ef 100644 --- a/spec/tasks/update_spec.rb +++ b/spec/tasks/update_spec.rb @@ -8,7 +8,7 @@ let(:task) do project.create_task :title => "Task X", :description => "This is task X", - :status => :new, + :status => :open, :priority => 1, :assignee => "Omar", :requestor => "Ron", @@ -21,7 +21,8 @@ :description => "This is task X.1", :status => :in_progress, :priority => 2, - :assignee => "Rafa" + :assignee => "Rafa", + :status => :open end describe :update? do @@ -36,7 +37,7 @@ subject { task } its(:title) { should == "Task X.1" } its(:description) { should == "This is task X.1" } - its(:status) { should == :in_progress } + its(:status) { should == :open } its(:priority) { should == 2 } its(:assignee) { should == "Rafa" } end From a4c2580c9acef26971d04f873e8591f7881c10d9 Mon Sep 17 00:00:00 2001 From: Rafael George Date: Fri, 10 Aug 2012 17:42:53 -0400 Subject: [PATCH 6/6] Fix conflicts with merge --- lib/taskmapper/entities/task.rb | 2 +- spec/task_comments/delete_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/taskmapper/entities/task.rb b/lib/taskmapper/entities/task.rb index 4fdada6..7ba4a69 100644 --- a/lib/taskmapper/entities/task.rb +++ b/lib/taskmapper/entities/task.rb @@ -52,7 +52,7 @@ def create_comment(attrs) alias :comment! :create_comment def comments - factory.task_comments.where(:task_id => id) + factory.task_comments.where(:task => self) end def comments_count diff --git a/spec/task_comments/delete_spec.rb b/spec/task_comments/delete_spec.rb index 35aebd1..983a24e 100644 --- a/spec/task_comments/delete_spec.rb +++ b/spec/task_comments/delete_spec.rb @@ -9,10 +9,10 @@ let(:task) do project.create_task :title => "Task X", :description => "This is task X", - :status => :new, + :status => :open, :priority => 1, :assignee => "Omar", - :requestor => "Ron", + :requestor => "Ron" end context "And 'Task X' have 3 comments" do