ketchup 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,125 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Ketchup::ItemArray do
4
+ before :each do
5
+ @api = stub('api', :get => [])
6
+ @meeting = Ketchup::Meeting.new @api, 'shortcode_url' => 'bar'
7
+ end
8
+
9
+ it "should be a subclass of Array" do
10
+ Ketchup::ItemArray.superclass.should == Array
11
+ end
12
+
13
+ describe '#initialize' do
14
+ it "should instantiate items from the provided array" do
15
+ time = Time.now
16
+ items = Ketchup::ItemArray.new @api, @meeting, [{
17
+ 'updated_at' => time,
18
+ 'shortcode_url' => 'ZCTYXAeDb_rQ3IkRq9nutcwfxUpNPLBOsHM28Ela',
19
+ 'notes' => [],
20
+ 'content' => 'Foo',
21
+ 'position' => 1,
22
+ 'meeting_id' => 4321,
23
+ 'created_at' => time
24
+ }]
25
+ items.first.should be_a(Ketchup::Item)
26
+ end
27
+ end
28
+
29
+ describe '#build' do
30
+ before :each do
31
+ @items = Ketchup::ItemArray.new @api, @meeting
32
+ end
33
+
34
+ it "should set the item's API object" do
35
+ item = @items.build 'content' => 'foo'
36
+ item.api.should == @api
37
+ end
38
+
39
+ it "should pass on the options to the new item" do
40
+ item = @items.build 'content' => 'foo'
41
+ item.content.should == 'foo'
42
+ end
43
+
44
+ it "should add the item to the array" do
45
+ item = @items.build 'content' => 'foo'
46
+ @items.should include(item)
47
+ end
48
+ end
49
+
50
+ describe '#create' do
51
+ before :each do
52
+ @api.stub!(:post => {'content' => 'foo'})
53
+ @items = Ketchup::ItemArray.new @api, @meeting
54
+ end
55
+
56
+ it "should set the item's API object" do
57
+ item = @items.create 'content' => 'foo'
58
+ item.api.should == @api
59
+ end
60
+
61
+ it "should pass on the options to the new item" do
62
+ item = @items.create 'content' => 'foo'
63
+ item.content.should == 'foo'
64
+ end
65
+
66
+ it "should add the item to the array" do
67
+ item = @items.create 'content' => 'foo'
68
+ @items.should include(item)
69
+ end
70
+
71
+ it "should have already saved the item" do
72
+ @api.should_receive(:post)
73
+
74
+ item = @items.create 'content' => 'foo'
75
+ end
76
+ end
77
+
78
+ describe '#reorder' do
79
+ before :each do
80
+ @api.stub!(:put => [])
81
+ @items = Ketchup::ItemArray.new @api, @meeting, [
82
+ {'shortcode_url' => 'alpha', 'content' => 'Alpha'},
83
+ {'shortcode_url' => 'beta', 'content' => 'Beta' },
84
+ {'shortcode_url' => 'gamma', 'content' => 'Gamma'}
85
+ ]
86
+ @alpha, @beta, @gamma = @items
87
+ end
88
+
89
+ it "should send a put request to the correct url" do
90
+ @api.should_receive(:put) do |query, options|
91
+ query.should == '/meetings/bar/sort_items.json'
92
+ end
93
+
94
+ @items.reorder @beta, @gamma, @alpha
95
+ end
96
+
97
+ it "should send the shortcode urls in the given order" do
98
+ @api.should_receive(:put) do |query, options|
99
+ options['items'].should == ['beta', 'gamma', 'alpha']
100
+ end
101
+
102
+ @items.reorder @beta, @gamma, @alpha
103
+ end
104
+
105
+ it "should change the order of the array" do
106
+ @items.reorder @beta, @gamma, @alpha
107
+ @items[0].should == @beta
108
+ @items[1].should == @gamma
109
+ @items[2].should == @alpha
110
+ end
111
+
112
+ it "should raise an error if not the same items" do
113
+ item = Ketchup::Item.new @api, @meeting, 'shortcode_url' => 'delta'
114
+ lambda {
115
+ @items.reorder item, @beta, @alpha
116
+ }.should raise_error(ArgumentError)
117
+ end
118
+
119
+ it "should raise an error if not all the items" do
120
+ lambda {
121
+ @items.reorder @alpha, @gamma
122
+ }.should raise_error(ArgumentError)
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,127 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Ketchup::Item do
4
+ before :each do
5
+ @api = stub('api')
6
+ @meeting = Ketchup::Meeting.new @api
7
+ end
8
+
9
+ describe '#initialize' do
10
+ it "should initialize all the attributes" do
11
+ time = Time.now
12
+ item = Ketchup::Item.new(@api, @meeting,
13
+ 'updated_at' => time,
14
+ 'shortcode_url' => 'ZCTYXAeDb_rQ3IkRq9nutcwfxUpNPLBOsHM28Ela',
15
+ 'notes' => [],
16
+ 'content' => 'Foo',
17
+ 'position' => 1,
18
+ 'meeting_id' => 4321,
19
+ 'created_at' => time
20
+ )
21
+
22
+ item.updated_at.should == time
23
+ item.shortcode_url.should == 'ZCTYXAeDb_rQ3IkRq9nutcwfxUpNPLBOsHM28Ela'
24
+ item.notes.should == []
25
+ item.content.should == 'Foo'
26
+ item.position.should == 1
27
+ item.meeting_id.should == 4321
28
+ item.created_at.should == time
29
+ end
30
+ end
31
+
32
+ describe '#new_record?' do
33
+ it "should return true if item has no shortcode_url" do
34
+ item = Ketchup::Item.new @api, @meeting
35
+ item.should be_new_record
36
+ end
37
+
38
+ it "should return false if item has a shortcode_url" do
39
+ item = Ketchup::Item.new @api, @meeting, 'shortcode_url' => 'foo'
40
+ item.should_not be_new_record
41
+ end
42
+ end
43
+
44
+ describe '#save' do
45
+ it "should send a post if creating" do
46
+ @api.should_receive(:post).and_return({})
47
+
48
+ item = Ketchup::Item.new @api, @meeting, 'content' => 'foo'
49
+ item.save
50
+ end
51
+
52
+ it "should include writeable attributes in the post" do
53
+ @api.should_receive(:post) do |query, options|
54
+ options['content'].should == 'foo'
55
+ {}
56
+ end
57
+
58
+ item = Ketchup::Item.new @api, @meeting, 'content' => 'foo'
59
+ item.save
60
+ end
61
+
62
+ it "should not include read-only attributes in the post" do
63
+ @api.should_receive(:post) do |query, options|
64
+ options.keys.should_not include('created_at')
65
+ {}
66
+ end
67
+
68
+ item = Ketchup::Item.new @api, @meeting, 'created_at' => Time.now
69
+ item.save
70
+ end
71
+
72
+ it "should update the object with the response" do
73
+ @api.stub!(:post => {'shortcode_url' => 'foo'})
74
+
75
+ item = Ketchup::Item.new @api, @meeting, 'content' => 'Foo'
76
+ item.save
77
+ item.shortcode_url.should == 'foo'
78
+ end
79
+
80
+ it "should send a put if updating" do
81
+ @api.should_receive(:put).and_return({})
82
+
83
+ item = Ketchup::Item.new @api, @meeting, 'shortcode_url' => 'foo'
84
+ item.save
85
+ end
86
+
87
+ it "should include writeable attributes in the put" do
88
+ @api.should_receive(:put) do |query, options|
89
+ options['content'].should == 'foo'
90
+ {}
91
+ end
92
+
93
+ item = Ketchup::Item.new @api, @meeting,
94
+ 'shortcode_url' => 'foo', 'content' => 'foo'
95
+ item.save
96
+ end
97
+
98
+ it "should not include read-only attributes in the put" do
99
+ @api.should_receive(:put) do |query, options|
100
+ options.keys.should_not include('created_at')
101
+ {}
102
+ end
103
+
104
+ item = Ketchup::Item.new @api, @meeting,
105
+ 'shortcode_url' => 'foo', 'created_at' => Time.now
106
+ item.save
107
+ end
108
+ end
109
+
110
+ describe '#destroy' do
111
+ it "should delete the item" do
112
+ @api.should_receive(:delete) do |query, options|
113
+ query.should == '/items/foo.json'
114
+ end
115
+
116
+ item = Ketchup::Item.new @api, @meeting, 'shortcode_url' => 'foo'
117
+ item.destroy
118
+ end
119
+
120
+ it "should do nothing if the record isn't already saved" do
121
+ @api.should_not_receive(:delete)
122
+
123
+ item = Ketchup::Item.new @api, @meeting
124
+ item.destroy
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,141 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Ketchup::MeetingArray do
4
+ before :each do
5
+ @api = stub('api', :get => [])
6
+ end
7
+
8
+ it "should be a subclass of Array" do
9
+ Ketchup::MeetingArray.superclass.should == Array
10
+ end
11
+
12
+ describe '#initialize' do
13
+ it "should load meetings from the api" do
14
+ @api.stub!(:get => [{
15
+ "updated_at" => Time.now,
16
+ "project_id" => nil,
17
+ "title" => "Another Meeting",
18
+ "quick" => nil,
19
+ "public" => false,
20
+ "items" => [],
21
+ "shortcode_url" => "Bmq58b",
22
+ "date" => Time.now,
23
+ "attendees" => "",
24
+ "description" => nil,
25
+ "public_url" => "bm5aTN",
26
+ "project_name" => nil,
27
+ "user_id" => 6542,
28
+ "location" => nil,
29
+ "created_at" => Time.now
30
+ }])
31
+ meetings = Ketchup::MeetingArray.new @api
32
+ meetings.first.should be_a(Ketchup::Meeting)
33
+ end
34
+ end
35
+
36
+ describe '#build' do
37
+ before :each do
38
+ @meetings = Ketchup::MeetingArray.new @api
39
+ end
40
+
41
+ it "should set the meeting's API object" do
42
+ meeting = @meetings.build 'title' => 'foo'
43
+ meeting.api.should == @api
44
+ end
45
+
46
+ it "should pass on the options to the new meeting" do
47
+ meeting = @meetings.build 'title' => 'foo'
48
+ meeting.title.should == 'foo'
49
+ end
50
+
51
+ it "should add the meeting to the array" do
52
+ meeting = @meetings.build 'title' => 'foo'
53
+ @meetings.should include(meeting)
54
+ end
55
+ end
56
+
57
+ describe '#create' do
58
+ before :each do
59
+ @api.stub!(:post => {'title' => 'foo'})
60
+ @meetings = Ketchup::MeetingArray.new @api
61
+ end
62
+
63
+ it "should set the meeting's API object" do
64
+ meeting = @meetings.create 'title' => 'foo'
65
+ meeting.api.should == @api
66
+ end
67
+
68
+ it "should pass on the options to the new meeting" do
69
+ meeting = @meetings.create 'title' => 'foo'
70
+ meeting.title.should == 'foo'
71
+ end
72
+
73
+ it "should add the meeting to the array" do
74
+ meeting = @meetings.create 'title' => 'foo'
75
+ @meetings.should include(meeting)
76
+ end
77
+
78
+ it "should have already saved the meeting" do
79
+ @api.should_receive(:post)
80
+
81
+ meeting = @meetings.create 'title' => 'foo'
82
+ end
83
+ end
84
+
85
+ describe '#upcoming' do
86
+ before :each do
87
+ @meetings = Ketchup::MeetingArray.new @api
88
+ end
89
+
90
+ it "should load the upcoming meetings from the API" do
91
+ @api.should_receive(:get) do |query, options|
92
+ query.should == '/meetings/upcoming.json'
93
+ []
94
+ end
95
+
96
+ @meetings.upcoming
97
+ end
98
+
99
+ it "should return an array of meetings" do
100
+ @meetings.upcoming.should be_an(Array)
101
+ end
102
+ end
103
+
104
+ describe '#previous' do
105
+ before :each do
106
+ @meetings = Ketchup::MeetingArray.new @api
107
+ end
108
+
109
+ it "should load the previous meetings from the API" do
110
+ @api.should_receive(:get) do |query, options|
111
+ query.should == '/meetings/previous.json'
112
+ []
113
+ end
114
+
115
+ @meetings.previous
116
+ end
117
+
118
+ it "should return an array of meetings" do
119
+ @meetings.previous.should be_an(Array)
120
+ end
121
+ end
122
+
123
+ describe '#today' do
124
+ before :each do
125
+ @meetings = Ketchup::MeetingArray.new @api
126
+ end
127
+
128
+ it "should load today's meetings from the API" do
129
+ @api.should_receive(:get) do |query, options|
130
+ query.should == '/meetings/todays.json'
131
+ []
132
+ end
133
+
134
+ @meetings.today
135
+ end
136
+
137
+ it "should return an array of meetings" do
138
+ @meetings.today.should be_an(Array)
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,142 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Ketchup::Meeting do
4
+ before :each do
5
+ @api = stub('api')
6
+ end
7
+
8
+ describe '#initialize' do
9
+ it "should initialize all the attributes" do
10
+ time = Time.now
11
+ meeting = Ketchup::Meeting.new(@api,
12
+ "updated_at" => time,
13
+ "project_id" => nil,
14
+ "title" => "Another Meeting",
15
+ "quick" => nil,
16
+ "public" => false,
17
+ "items" => [],
18
+ "shortcode_url" => "Bmq58b",
19
+ "date" => time,
20
+ "attendees" => "Me, You, Them",
21
+ "description" => "Just a meeting",
22
+ "public_url" => "bm5aTN",
23
+ "project_name" => "Top Secret",
24
+ "user_id" => 6542,
25
+ "location" => "Somewhere",
26
+ "created_at" => time
27
+ )
28
+
29
+ meeting.updated_at.should == time
30
+ meeting.project_id.should be_nil
31
+ meeting.title.should == 'Another Meeting'
32
+ meeting.quick.should be_nil
33
+ meeting.public.should be_false
34
+ meeting.items.should be_an(Ketchup::ItemArray)
35
+ meeting.shortcode_url.should == 'Bmq58b'
36
+ meeting.date.should == time
37
+ meeting.attendees.should == 'Me, You, Them'
38
+ meeting.description.should == 'Just a meeting'
39
+ meeting.public_url.should == 'bm5aTN'
40
+ meeting.project_name.should == 'Top Secret'
41
+ meeting.user_id.should == 6542
42
+ meeting.location.should == 'Somewhere'
43
+ meeting.created_at.should == time
44
+ end
45
+ end
46
+
47
+ describe '#new_record?' do
48
+ it "should return true if meeting has no shortcode_url" do
49
+ meeting = Ketchup::Meeting.new @api
50
+ meeting.should be_new_record
51
+ end
52
+
53
+ it "should return false if meeting has a shortcode_url" do
54
+ meeting = Ketchup::Meeting.new @api, 'shortcode_url' => 'foo'
55
+ meeting.should_not be_new_record
56
+ end
57
+ end
58
+
59
+ describe '#save' do
60
+ it "should send a post if creating" do
61
+ @api.should_receive(:post).and_return({})
62
+
63
+ meeting = Ketchup::Meeting.new @api, 'title' => 'foo'
64
+ meeting.save
65
+ end
66
+
67
+ it "should include writeable attributes in the post" do
68
+ @api.should_receive(:post) do |query, options|
69
+ options['title'].should == 'foo'
70
+ {}
71
+ end
72
+
73
+ meeting = Ketchup::Meeting.new @api, 'title' => 'foo'
74
+ meeting.save
75
+ end
76
+
77
+ it "should not include read-only attributes in the post" do
78
+ @api.should_receive(:post) do |query, options|
79
+ options.keys.should_not include('created_at')
80
+ {}
81
+ end
82
+
83
+ meeting = Ketchup::Meeting.new @api, 'created_at' => Time.now
84
+ meeting.save
85
+ end
86
+
87
+ it "should update the object with the response" do
88
+ @api.stub!(:post => {'shortcode_url' => 'foo'})
89
+
90
+ meeting = Ketchup::Meeting.new @api, 'title' => 'Foo'
91
+ meeting.save
92
+ meeting.shortcode_url.should == 'foo'
93
+ end
94
+
95
+ it "should send a put if updating" do
96
+ @api.should_receive(:put).and_return({})
97
+
98
+ meeting = Ketchup::Meeting.new @api, 'shortcode_url' => 'foo'
99
+ meeting.save
100
+ end
101
+
102
+ it "should include writeable attributes in the put" do
103
+ @api.should_receive(:put) do |query, options|
104
+ options['title'].should == 'foo'
105
+ {}
106
+ end
107
+
108
+ meeting = Ketchup::Meeting.new @api,
109
+ 'shortcode_url' => 'foo', 'title' => 'foo'
110
+ meeting.save
111
+ end
112
+
113
+ it "should not include read-only attributes in the put" do
114
+ @api.should_receive(:put) do |query, options|
115
+ options.keys.should_not include('created_at')
116
+ {}
117
+ end
118
+
119
+ meeting = Ketchup::Meeting.new @api,
120
+ 'shortcode_url' => 'foo', 'created_at' => Time.now
121
+ meeting.save
122
+ end
123
+ end
124
+
125
+ describe '#destroy' do
126
+ it "should delete the meeting" do
127
+ @api.should_receive(:delete) do |query, options|
128
+ query.should == '/meetings/foo.json'
129
+ end
130
+
131
+ meeting = Ketchup::Meeting.new @api, 'shortcode_url' => 'foo'
132
+ meeting.destroy
133
+ end
134
+
135
+ it "should do nothing if the record isn't already saved" do
136
+ @api.should_not_receive(:delete)
137
+
138
+ meeting = Ketchup::Meeting.new @api
139
+ meeting.destroy
140
+ end
141
+ end
142
+ end