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..7ba4a69 100644 --- a/lib/taskmapper/entities/task.rb +++ b/lib/taskmapper/entities/task.rb @@ -38,10 +38,13 @@ 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 create_comment(attrs) comments.create attrs end @@ -62,7 +65,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/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 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