From c9e457ed907dea398f18aaffe6c5d59c11104919 Mon Sep 17 00:00:00 2001 From: Greg Signal Date: Wed, 11 Jan 2012 11:41:40 +1300 Subject: [PATCH] Refactor relationship specs --- spec/jira/resource/issue_spec.rb | 81 ++++++++++++++---------------- spec/jira/resource/project_spec.rb | 23 +++++---- spec/support/matchers/have_one.rb | 5 ++ 3 files changed, 56 insertions(+), 53 deletions(-) create mode 100644 spec/support/matchers/have_one.rb diff --git a/spec/jira/resource/issue_spec.rb b/spec/jira/resource/issue_spec.rb index 1e4bb4d8..af4c873c 100644 --- a/spec/jira/resource/issue_spec.rb +++ b/spec/jira/resource/issue_spec.rb @@ -25,57 +25,50 @@ subject.foo.should == 'bar' end - it "returns the reporter" do - subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'reporter' => {'foo' => 'bar'}}}) - subject.reporter.class.should == JIRA::Resource::User - subject.reporter.foo.should == 'bar' - end + describe "relationships" do + subject { + JIRA::Resource::Issue.new(client, :attrs => { + 'fields' => { + 'reporter' => {'foo' => 'bar'}, + 'assignee' => {'foo' => 'bar'}, + 'project' => {'foo' => 'bar'}, + 'priority' => {'foo' => 'bar'}, + 'issuetype' => {'foo' => 'bar'}, + 'status' => {'foo' => 'bar'}, + 'components' => [{'foo' => 'bar'}, {'baz' => 'flum'}], + 'comment' => { 'comments' => [{'foo' => 'bar'}, {'baz' => 'flum'}]}, + 'attachment' => [{'foo' => 'bar'}, {'baz' => 'flum'}] + } + }) + } - it "returns the assignee" do - subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'assignee' => {'foo' => 'bar'}}}) - subject.assignee.class.should == JIRA::Resource::User - subject.assignee.foo.should == 'bar' - end + it "has the correct relationships" do + subject.should have_one(:reporter, JIRA::Resource::User) + subject.reporter.foo.should == 'bar' - it "returns the project" do - subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'project' => {'foo' => 'bar'}}}) - subject.project.class.should == JIRA::Resource::Project - subject.project.foo.should == 'bar' - end + subject.should have_one(:assignee, JIRA::Resource::User) + subject.assignee.foo.should == 'bar' - it "returns the issuetype" do - subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'issuetype' => {'foo' => 'bar'}}}) - subject.issuetype.class.should == JIRA::Resource::Issuetype - subject.issuetype.foo.should == 'bar' - end + subject.should have_one(:project, JIRA::Resource::Project) + subject.project.foo.should == 'bar' - it "has one priority" do - subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'priority' => {'foo' => 'bar'}}}) - subject.priority.class.should == JIRA::Resource::Priority - subject.priority.foo.should == 'bar' - end + subject.should have_one(:issuetype, JIRA::Resource::Issuetype) + subject.issuetype.foo.should == 'bar' - it "has one status" do - subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'status' => {'foo' => 'bar'}}}) - subject.status.class.should == JIRA::Resource::Status - subject.status.foo.should == 'bar' - end + subject.should have_one(:priority, JIRA::Resource::Priority) + subject.priority.foo.should == 'bar' - it "has many components" do - subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'components' => [{'foo' => 'bar'}, {'baz' => 'flum'}]}}) - subject.should have_many(:components, JIRA::Resource::Component) - subject.components.length.should == 2 - end + subject.should have_one(:status, JIRA::Resource::Status) + subject.status.foo.should == 'bar' - it "has many comments" do - subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'comment' => { 'comments' => [{'foo' => 'bar'}, {'baz' => 'flum'}]}}}) - subject.should have_many(:comments, JIRA::Resource::Comment) - subject.comments.length.should == 2 - end + subject.should have_many(:components, JIRA::Resource::Component) + subject.components.length.should == 2 + + subject.should have_many(:comments, JIRA::Resource::Comment) + subject.comments.length.should == 2 - it "has many attachments" do - subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'attachment' => [{'foo' => 'bar'}, {'baz' => 'flum'}]}}) - subject.should have_many(:attachments, JIRA::Resource::Attachment) - subject.attachments.length.should == 2 + subject.should have_many(:attachments, JIRA::Resource::Attachment) + subject.attachments.length.should == 2 + end end end diff --git a/spec/jira/resource/project_spec.rb b/spec/jira/resource/project_spec.rb index b48e392f..efcba1e1 100644 --- a/spec/jira/resource/project_spec.rb +++ b/spec/jira/resource/project_spec.rb @@ -4,16 +4,21 @@ let(:client) { mock() } - it "has one lead" do - subject = JIRA::Resource::Project.new(client, :attrs => {'lead' => {'foo' =>'bar'}}) - subject.lead.class.should == JIRA::Resource::User - subject.lead.foo.should == 'bar' - end + describe "relationships" do + subject { + JIRA::Resource::Project.new(client, :attrs => { + 'lead' => {'foo' => 'bar'}, + 'issueTypes' => [{'foo' =>'bar'},{'baz' => 'flum'}] + }) + } + + it "has the correct relationships" do + subject.should have_one(:lead, JIRA::Resource::User) + subject.lead.foo.should == 'bar' - it "has many issuetypes" do - subject = JIRA::Resource::Project.new(client, :attrs => {'issueTypes' => [{'foo' =>'bar'},{'baz' => 'flum'}]}) - subject.should have_many(:issuetypes, JIRA::Resource::Issuetype) - subject.issuetypes.length.should == 2 + subject.should have_many(:issuetypes, JIRA::Resource::Issuetype) + subject.issuetypes.length.should == 2 + end end end diff --git a/spec/support/matchers/have_one.rb b/spec/support/matchers/have_one.rb new file mode 100644 index 00000000..278eb1f8 --- /dev/null +++ b/spec/support/matchers/have_one.rb @@ -0,0 +1,5 @@ +RSpec::Matchers.define :have_one do |resource, klass| + match do |actual| + actual.send(resource).class.should == klass + end +end