Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/taskmapper/entities/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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::InvalidStatus.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)
Expand Down
24 changes: 19 additions & 5 deletions lib/taskmapper/entities/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Task
protected :requestor=,
:project_id=,
:factory=

def initialize(attrs)
super attrs
self.title = attrs[:title]
Expand All @@ -38,10 +38,22 @@ def delete
end

def validate
validate_presence_of :title
validate_presence_of :requestor
validate_presence_of :title
validate_presence_of :requestor
validate_status :in => [:open, :close]
validate_priority
end


def validate_status(criteria)
in_values = criteria[:in]
raise Exceptions::InvalidStatus.new(in_values) unless in_values.include? self.status
end

def validate_priority
raise Exceptions::InvalidPriority.new if self.priority.nil? || self.priority < 0
end


def create_comment(attrs)
comments.create attrs
end
Expand All @@ -62,7 +74,9 @@ 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,
:priority => self.priority
})
end

Expand Down
13 changes: 13 additions & 0 deletions lib/taskmapper/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,18 @@ 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 has to be #{values.join(',')}"
end
end

class InvalidPriority < TaskMapperException
def initialize
super "Priority has to be a positive number"
end
end

end
end
4 changes: 3 additions & 1 deletion spec/task_comments/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

context "Given Task X" do
let(:task_x) { project_x.create_task :title => "Task X",
:requestor => "Omar" }
:requestor => "Omar",
:status => :open,
:priority => 1 }
context "Given valid attributes" do
context "When I create a task comment on Task X" do
before :all do
Expand Down
4 changes: 2 additions & 2 deletions spec/task_comments/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion spec/task_comments/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
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,
:priority => 1

end

context "And 'buy ukulele' have the following comments" do
Expand Down
1 change: 1 addition & 0 deletions spec/task_comments/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:priority => 1,
:assignee => "Omar",
:requestor => "Ron",
:status => :open
end

context "And 'Task X' have a comment" do
Expand Down
56 changes: 45 additions & 11 deletions spec/tasks/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,86 @@
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
subject { project }
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 => 1
}}

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 == 1 }
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::InvalidStatus) { 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 priority" do
let(:attributes) { { :title => 'Test Task', :requestor => 'Ron Evans', :status => :open,
:priority => nil } }
let(:task_without_priority) { project.create_task attributes }
let(:error) do
catch_error(TaskMapper::Exceptions::InvalidPriority) { task_without_priority }
end

describe :error do
subject { error }
it { should_not be_nil }
its(:message) { should match /Priority has to be/ }
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 } }

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 }
Expand Down
8 changes: 4 additions & 4 deletions spec/tasks/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

context "And Project X have Tasks X and Y" do
before :all do
project_x.task! :title => "Task X",
:requestor => "Me"
project_x.task! :title => "Task X", :priority => 1,
:requestor => "Me", :status => :open

project_x.task! :title => "Task Y",
:requestor => "Me"
project_x.task! :title => "Task Y", :priority => 1,
:requestor => "Me", :status => :open
end

context "When I delete Task X" do
Expand Down
65 changes: 33 additions & 32 deletions spec/tasks/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,59 @@
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", :priority => 1,
:requestor => "Ludwig van Beethoven", :status => :open

secret_project.create_task :title => "Contruct a bomb",
:description => "Visit howstuffworks.com", :priority => 1,
: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", :priority => 1,
:requestor => "Ludwig van Beethoven", :status => :open

secret_project.create_task :title => "Detonate bomb with remote controller",
:description => "Save the world", :priority => 1,
:requestor => "Ludwig van Beethoven", :status => :open

learn_ukulele.create_task :title => "Buy Ukulele", :priority => 1,
: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", :priority => 1,
:requestor => "Me", :status => :open

learn_ukulele.create_task :title => "Practice hard", :priority => 1,
: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 }
its(:priority) { should == 1 }
end

describe :fourth do
subject { secret_project.tasks[3] }
its(:id) { should == 4 }
Expand Down
7 changes: 4 additions & 3 deletions spec/tasks/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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
Expand Down