spec/mavenlink/client_spec.rb in mavenlink-0.2.4 vs spec/mavenlink/client_spec.rb in mavenlink-0.2.6

- old
+ new

@@ -4,103 +4,119 @@ before do @client = Mavenlink::Client.new("user_id", "token") end describe "time entries" do - before do - @time_entries_json = <<-JSON - [ - { - "workspace_id":1601, - "story_id":1581, - "creator_id":2, - "currency":"USD", - "created_at":"2010/08/02 09:39:01 -0700", - "date_performed":"2010/08/02", - "billable":false, - "notes":"", - "time_in_minutes":120, - "rate_in_cents":0, - "id":35 - }, - { - "workspace_id":11746, - "story_id":null, - "creator_id":2, - "currency":"GBP", - "created_at":"2010/11/15 12:16:10 -0800", - "date_performed":"2010/11/15", - "billable":true, - "notes":"", - "time_in_minutes":60, - "rate_in_cents":2000, - "id":2060 - } - ] - JSON - - - @story_json = <<-JSON - { - "workspace_id":1601, - "state": "not started", - "description": "", - "story_type": "task", - "created_at": "2001/03/11 15:01:04 -0800", - "archived":false, - "assignee": + context "with mock data" do + before do + @time_entries_json = <<-JSON + [ { - "full_name": "Some User", - "id": 4000 + "workspace_id":1601, + "story_id":1581, + "creator_id":2, + "currency":"USD", + "created_at":"2010/08/02 09:39:01 -0700", + "date_performed":"2010/08/02", + "billable":false, + "notes":"", + "time_in_minutes":120, + "rate_in_cents":0, + "id":35 }, - "due_date":null, - "position":1, - "id":1581, - "title": "Some Story", - "creator": { - "full_name": "Some Other User", - "id": 4001 + "workspace_id":11746, + "story_id":null, + "creator_id":2, + "currency":"GBP", + "created_at":"2010/11/15 12:16:10 -0800", + "date_performed":"2010/11/15", + "billable":true, + "notes":"", + "time_in_minutes":60, + "rate_in_cents":2000, + "id":2060 } - } - JSON + ] + JSON - stub_request(:get, "https://user_id:token@mavenlink.local/api/v0/time_entries?per_page=5"). - with(:headers => {'Accept'=>'application/json'}). - to_return(:status => 200, :body => @time_entries_json, :headers => {}) - stub_request(:get, "https://user_id:token@mavenlink.local/api/v0/workspaces/1601/stories/1581?"). - with(:headers => {'Accept'=>'application/json'}). - to_return(:status => 200, :body => @story_json, :headers => {}) + @story_json = <<-JSON + { + "workspace_id":1601, + "state": "not started", + "description": "", + "story_type": "task", + "created_at": "2001/03/11 15:01:04 -0800", + "archived":false, + "assignee": + { + "full_name": "Some User", + "id": 4000 + }, + "due_date":null, + "position":1, + "id":1581, + "title": "Some Story", + "creator": + { + "full_name": "Some Other User", + "id": 4001 + } + } + JSON - @time_entries = @client.time_entries(:per_page => 5) - end + stub_request(:get, "https://user_id:token@mavenlink.local/api/v0/time_entries?per_page=5"). + with(:headers => {'Accept'=>'application/json'}). + to_return(:status => 200, :body => @time_entries_json, :headers => {}) - it "should do basic auth" do - WebMock.should have_requested(:get, "https://user_id:token@mavenlink.local/api/v0/time_entries?per_page=5") - end + stub_request(:get, "https://user_id:token@mavenlink.local/api/v0/workspaces/1601/stories/1581?"). + with(:headers => {'Accept'=>'application/json'}). + to_return(:status => 200, :body => @story_json, :headers => {}) - it "should have many time_entries" do - @time_entries.length.should == 2 - @time_entries.first.should be_a(Mavenlink::TimeEntry) - @time_entries.first.request_path.should == "/workspaces/1601/time_entries/35" - end + @time_entries = @client.time_entries(:per_page => 5) + end - describe "the story on a time entry" do - it "is a working story object" do - story = @time_entries.first.story - story.should be_a(Mavenlink::Story) - story.title.should == "Some Story" - story.request_path.should == "/workspaces/1601/stories/1581" + it "should do basic auth" do + WebMock.should have_requested(:get, "https://user_id:token@mavenlink.local/api/v0/time_entries?per_page=5") end - it "has a nested creator and assignee" do - story = @time_entries.first.story - story.creator.should be_a(Mavenlink::User) - story.creator.full_name.should == "Some Other User" - story.assignee.should be_a(Mavenlink::User) - story.assignee.full_name.should == "Some User" + it "should have many time_entries" do + @time_entries.length.should == 2 + @time_entries.first.should be_a(Mavenlink::TimeEntry) + @time_entries.first.request_path.should == "/workspaces/1601/time_entries/35" end + + describe "the story on a time entry" do + it "is a working story object" do + story = @time_entries.first.story + story.should be_a(Mavenlink::Story) + story.title.should == "Some Story" + story.request_path.should == "/workspaces/1601/stories/1581" + end + + it "has a nested creator and assignee" do + story = @time_entries.first.story + story.creator.should be_a(Mavenlink::User) + story.creator.full_name.should == "Some Other User" + story.assignee.should be_a(Mavenlink::User) + story.assignee.full_name.should == "Some User" + end + end + end + + it "should be reasonable fast" do + json_data = File.read(File.join(File.dirname(__FILE__), "..", "fixtures", "time_entries.json")) + + stub_request(:get, "https://user_id:token@mavenlink.local/api/v0/time_entries?per_page=1000"). + with(:headers => {'Accept'=>'application/json'}). + to_return(:status => 200, :body => json_data, :headers => {}) + + time_entries = @client.time_entries(:per_page => 1000) + start = Time.now.to_f + time_entries.length.should > 50 + time_entries.first.should be_a(Mavenlink::TimeEntry) + (Time.now.to_f - start).should < 1 end end describe "events" do before do