kippt 3.0.1 → 3.1.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.
- checksums.yaml +5 -13
- data/CHANGELOG.md +6 -0
- data/kippt.gemspec +1 -1
- data/lib/kippt/collection.rb +4 -4
- data/lib/kippt/read_collection_resource.rb +0 -6
- data/lib/kippt/version.rb +1 -1
- data/spec/kippt/client_spec.rb +16 -16
- data/spec/kippt/clip_collection_spec.rb +2 -1
- data/spec/kippt/clip_spec.rb +31 -31
- data/spec/kippt/clips_spec.rb +13 -13
- data/spec/kippt/comment_spec.rb +2 -2
- data/spec/kippt/comments_spec.rb +18 -38
- data/spec/kippt/favorite_spec.rb +10 -10
- data/spec/kippt/favorites_spec.rb +3 -3
- data/spec/kippt/follow_relationship_spec.rb +7 -7
- data/spec/kippt/like_spec.rb +10 -10
- data/spec/kippt/likes_spec.rb +3 -3
- data/spec/kippt/list_collection_spec.rb +2 -1
- data/spec/kippt/list_spec.rb +20 -20
- data/spec/kippt/lists_spec.rb +2 -2
- data/spec/kippt/saves_spec.rb +2 -2
- data/spec/kippt/user_clips_spec.rb +4 -4
- data/spec/kippt/user_collection_spec.rb +2 -1
- data/spec/kippt/user_lists_spec.rb +2 -2
- data/spec/kippt/user_spec.rb +14 -14
- data/spec/kippt/users_spec.rb +4 -4
- data/spec/shared_examples/collection.rb +26 -26
- data/spec/shared_examples/collection_resource.rb +2 -2
- data/spec/shared_examples/read_collection_resource.rb +8 -28
- data/spec/shared_examples/resource.rb +20 -20
- metadata +22 -22
@@ -14,11 +14,11 @@ describe Kippt::UserClips do
|
|
14
14
|
|
15
15
|
describe "#build" do
|
16
16
|
it "returns new resource" do
|
17
|
-
subject.build.
|
17
|
+
expect(subject.build).to be_a(resource_class)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "accepts parameters" do
|
21
|
-
subject.object_class.
|
21
|
+
expect(subject.object_class).to receive(:new).with({:an => "attribute"}, client)
|
22
22
|
subject.build(:an => "attribute")
|
23
23
|
end
|
24
24
|
end
|
@@ -27,7 +27,7 @@ describe Kippt::UserClips do
|
|
27
27
|
it "returns ClipCollection" do
|
28
28
|
stub_get("/#{base_uri}/favorites").
|
29
29
|
to_return(:status => 200, :body => fixture("clips.json"))
|
30
|
-
subject.favorites.
|
30
|
+
expect(subject.favorites).to be_a Kippt::Clips
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,7 @@ describe Kippt::UserClips do
|
|
35
35
|
it "returns ClipCollection" do
|
36
36
|
stub_get("/#{base_uri}/likes").
|
37
37
|
to_return(:status => 200, :body => fixture("clips.json"))
|
38
|
-
subject.likes.
|
38
|
+
expect(subject.likes).to be_a Kippt::Clips
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -6,9 +6,10 @@ describe Kippt::UserCollection do
|
|
6
6
|
let(:data_with_multiple_pages) {
|
7
7
|
MultiJson.load(fixture("users_with_multiple_pages.json").read)
|
8
8
|
}
|
9
|
-
let(:client) {
|
9
|
+
let(:client) { double(:client) }
|
10
10
|
subject { Kippt::UserCollection.new(data, client) }
|
11
11
|
let(:subject_with_multiple_pages) { Kippt::UserCollection.new(data_with_multiple_pages, client) }
|
12
|
+
let(:collection_resource_class) { Kippt::Users }
|
12
13
|
|
13
14
|
it_behaves_like "collection"
|
14
15
|
end
|
@@ -14,11 +14,11 @@ describe Kippt::UserLists do
|
|
14
14
|
|
15
15
|
describe "#build" do
|
16
16
|
it "returns new resource" do
|
17
|
-
subject.build.
|
17
|
+
expect(subject.build).to be_a(resource_class)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "accepts parameters" do
|
21
|
-
subject.object_class.
|
21
|
+
expect(subject.object_class).to receive(:new).with({:an => "attribute"}, client)
|
22
22
|
subject.build(:an => "attribute")
|
23
23
|
end
|
24
24
|
end
|
data/spec/kippt/user_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe Kippt::User do
|
|
21
21
|
describe "#pro?" do
|
22
22
|
it "gets data from is_pro" do
|
23
23
|
user = Kippt::User.new({:is_pro => true}, nil)
|
24
|
-
user.pro
|
24
|
+
expect(user.pro?).to be_truthy
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -31,52 +31,52 @@ describe Kippt::User do
|
|
31
31
|
user = Kippt::User.new(nil, client)
|
32
32
|
|
33
33
|
likes = user.likes
|
34
|
-
likes.
|
35
|
-
likes.user.
|
34
|
+
expect(likes).to be_a(Kippt::UserLikes)
|
35
|
+
expect(likes.user).to eq user
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "#following?" do
|
40
40
|
it "uses Kippt::FollowRelationship to get the information" do
|
41
|
-
follow_relationship =
|
41
|
+
follow_relationship = double(:follow_relationship,
|
42
42
|
:following? => true)
|
43
|
-
Kippt::FollowRelationship.
|
43
|
+
allow(Kippt::FollowRelationship).to receive(:new).and_return(follow_relationship)
|
44
44
|
user = Kippt::User.new({:is_pro => true}, nil)
|
45
|
-
user.following
|
45
|
+
expect(user.following?).to be_truthy
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "#follower_count" do
|
50
50
|
it "returns the count from the fetched data" do
|
51
51
|
user = Kippt::User.new({:counts => {"follows" => 11}})
|
52
|
-
user.follower_count.
|
52
|
+
expect(user.follower_count).to eq 11
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "#following_count" do
|
57
57
|
it "returns the count from the fetched data" do
|
58
58
|
user = Kippt::User.new({:counts => {"followed_by" => 111}})
|
59
|
-
user.following_count.
|
59
|
+
expect(user.following_count).to eq 111
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "#follow" do
|
64
64
|
it "sets up a Kippt::FollowRelationship and calls it" do
|
65
|
-
follow_relationship =
|
65
|
+
follow_relationship = double(:follow_relationship,
|
66
66
|
:follow => true)
|
67
|
-
Kippt::FollowRelationship.
|
67
|
+
allow(Kippt::FollowRelationship).to receive(:new).and_return(follow_relationship)
|
68
68
|
user = Kippt::User.new
|
69
|
-
user.follow.
|
69
|
+
expect(user.follow).to be_truthy
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
describe "#unfollow" do
|
74
74
|
it "sets up a Kippt::FollowRelationship and calls it" do
|
75
|
-
follow_relationship =
|
75
|
+
follow_relationship = double(:follow_relationship,
|
76
76
|
:unfollow => true)
|
77
|
-
Kippt::FollowRelationship.
|
77
|
+
allow(Kippt::FollowRelationship).to receive(:new).and_return(follow_relationship)
|
78
78
|
user = Kippt::User.new
|
79
|
-
user.unfollow.
|
79
|
+
expect(user.unfollow).to be_truthy
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
data/spec/kippt/users_spec.rb
CHANGED
@@ -35,9 +35,9 @@ describe Kippt::Users do
|
|
35
35
|
|
36
36
|
context "with invalid keys" do
|
37
37
|
it "raises ArgumentError" do
|
38
|
-
|
38
|
+
expect {
|
39
39
|
subject.search(:q => "bunny", :stuff => true)
|
40
|
-
}.
|
40
|
+
}.to raise_error(ArgumentError, "'stuff' is not a valid search parameter")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -47,13 +47,13 @@ describe Kippt::Users do
|
|
47
47
|
stub_get("/users/search?q=bunny").
|
48
48
|
to_return(:status => 200, :body => fixture("users_with_multiple_pages.json"))
|
49
49
|
users = subject.search("bunny")
|
50
|
-
users.
|
50
|
+
expect(users).to be_a Kippt::UserCollection
|
51
51
|
end
|
52
52
|
|
53
53
|
it "sets UserCollection client" do
|
54
54
|
stub_get("/users/search?q=bunny").
|
55
55
|
to_return(:status => 200, :body => fixture("users_with_multiple_pages.json"))
|
56
|
-
Kippt::UserCollection.
|
56
|
+
expect(Kippt::UserCollection).to receive(:new).with(kind_of(Hash), kind_of(Kippt::Client))
|
57
57
|
users = subject.search("bunny")
|
58
58
|
end
|
59
59
|
end
|
@@ -1,31 +1,31 @@
|
|
1
1
|
shared_examples_for "collection" do
|
2
2
|
it "is Enumberable" do
|
3
|
-
subject.
|
3
|
+
expect(subject).to be_a(Enumerable)
|
4
4
|
end
|
5
5
|
|
6
6
|
describe "#offset" do
|
7
7
|
it "returns offset of the results" do
|
8
|
-
subject.offset.
|
8
|
+
expect(subject.offset).to eq 0
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#limit" do
|
13
13
|
it "returns limit of the results" do
|
14
|
-
subject.limit.
|
14
|
+
expect(subject.limit).to eq 20
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#objects" do
|
19
19
|
it "returns the objects generated from the data" do
|
20
20
|
subject.objects.each do |object|
|
21
|
-
object.
|
21
|
+
expect(object).to be_a(subject.object_class)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "#[]" do
|
27
27
|
it "returns a object by index" do
|
28
|
-
subject[0].id.
|
28
|
+
expect(subject[0].id).to eq data["objects"][0]["id"]
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,45 +33,44 @@ shared_examples_for "collection" do
|
|
33
33
|
it "loops through the objects" do
|
34
34
|
ids = []
|
35
35
|
subject.each {|object| ids << object.id }
|
36
|
-
ids.
|
36
|
+
expect(ids).to eq data["objects"].map { |node| node["id"] }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "#next_page?" do
|
41
41
|
context "there is a next page" do
|
42
42
|
it "returns url of the page" do
|
43
|
-
subject_with_multiple_pages.next_page
|
43
|
+
expect(subject_with_multiple_pages.next_page?).to eq data_with_multiple_pages["meta"]["next"]
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
context "there is no next page" do
|
48
48
|
it "returns nil" do
|
49
|
-
subject.next_page
|
49
|
+
expect(subject.next_page?).to eq nil
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "#next_page" do
|
55
55
|
context "if there is a next page" do
|
56
|
-
let(:collection_resource) {
|
56
|
+
let(:collection_resource) { double(:collection_resource) }
|
57
57
|
|
58
58
|
it "gets the next page of results from the collection resource" do
|
59
|
-
client.
|
59
|
+
expect(client).to receive(:collection_resource_for).with(collection_resource_class, data_with_multiple_pages["meta"]["next"]).and_return(collection_resource)
|
60
60
|
|
61
|
-
results =
|
62
|
-
collection_resource.
|
63
|
-
with(data_with_multiple_pages["meta"]["next"]).
|
61
|
+
results = double :results
|
62
|
+
expect(collection_resource).to receive(:fetch).
|
64
63
|
and_return(results)
|
65
64
|
|
66
|
-
subject_with_multiple_pages.next_page.
|
65
|
+
expect(subject_with_multiple_pages.next_page).to eq results
|
67
66
|
end
|
68
67
|
end
|
69
68
|
|
70
69
|
context "if there is no next page" do
|
71
70
|
it "raises an error" do
|
72
|
-
|
71
|
+
expect {
|
73
72
|
subject.next_page
|
74
|
-
}.
|
73
|
+
}.to raise_error(Kippt::APIError, "There is no next page")
|
75
74
|
end
|
76
75
|
end
|
77
76
|
end
|
@@ -79,38 +78,39 @@ shared_examples_for "collection" do
|
|
79
78
|
describe "#previous_page?" do
|
80
79
|
context "there is a previous page" do
|
81
80
|
it "returns url of the page" do
|
82
|
-
subject_with_multiple_pages.previous_page
|
81
|
+
expect(subject_with_multiple_pages.previous_page?).to eq data_with_multiple_pages["meta"]["previous"]
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
86
85
|
context "there is no previous page" do
|
87
86
|
it "returns nil" do
|
88
|
-
subject.previous_page
|
87
|
+
expect(subject.previous_page?).to be_nil
|
89
88
|
end
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
92
|
describe "#previous_page" do
|
94
93
|
context "if there is a previous page" do
|
95
|
-
let(:collection_resource) {
|
94
|
+
let(:collection_resource) { double(:collection_resource) }
|
96
95
|
|
97
96
|
it "gets the previous page of results from the collection resource" do
|
98
|
-
client.
|
97
|
+
expect(client).to receive(:collection_resource_for)
|
98
|
+
.with(collection_resource_class, data_with_multiple_pages["meta"]["previous"])
|
99
|
+
.and_return(collection_resource)
|
99
100
|
|
100
|
-
results =
|
101
|
-
collection_resource.
|
102
|
-
with(data_with_multiple_pages["meta"]["previous"]).
|
101
|
+
results = double :results
|
102
|
+
expect(collection_resource).to receive(:fetch).
|
103
103
|
and_return(results)
|
104
104
|
|
105
|
-
subject_with_multiple_pages.previous_page.
|
105
|
+
expect(subject_with_multiple_pages.previous_page).to eq results
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
context "if there is no previous page" do
|
110
110
|
it "raises an error" do
|
111
|
-
|
111
|
+
expect {
|
112
112
|
subject.previous_page
|
113
|
-
}.
|
113
|
+
}.to raise_error(Kippt::APIError, "There is no previous page")
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
@@ -5,8 +5,8 @@ shared_examples_for "collection resource" do
|
|
5
5
|
let(:resource) { double :resource }
|
6
6
|
|
7
7
|
it "builds and saves a resource" do
|
8
|
-
resource.
|
9
|
-
subject.
|
8
|
+
expect(resource).to receive :save
|
9
|
+
expect(subject).to receive(:build).with(:an => "attribute").and_return(resource)
|
10
10
|
subject.create(:an => "attribute")
|
11
11
|
end
|
12
12
|
end
|
@@ -16,9 +16,9 @@ shared_examples_for "read collection resource" do
|
|
16
16
|
|
17
17
|
context "when passed unrecognized arguments" do
|
18
18
|
it "raises error" do
|
19
|
-
|
19
|
+
expect {
|
20
20
|
subject.fetch(:foobar => true)
|
21
|
-
}.
|
21
|
+
}.to raise_error(
|
22
22
|
ArgumentError, "Unrecognized argument: foobar")
|
23
23
|
end
|
24
24
|
end
|
@@ -28,22 +28,22 @@ shared_examples_for "read collection resource" do
|
|
28
28
|
it "fetches single resource" do
|
29
29
|
stub_get("/#{base_uri}/10").
|
30
30
|
to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
|
31
|
-
subject[10].id.
|
31
|
+
expect(subject[10].id).to eq 10
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns resource" do
|
35
35
|
stub_get("/#{base_uri}/10").
|
36
36
|
to_return(:status => 200, :body => fixture("#{singular_fixture}.json"))
|
37
|
-
subject[10].
|
37
|
+
expect(subject[10]).to be_a(resource_class)
|
38
38
|
end
|
39
39
|
|
40
40
|
context "when resource is not found" do
|
41
41
|
it "raises exception" do
|
42
42
|
stub_get("/#{base_uri}/10").
|
43
|
-
to_return(:status => 404, :body => {"message" => "Resource not found."})
|
44
|
-
|
43
|
+
to_return(:status => 404, :body => {"message" => "Resource not found."}.to_json)
|
44
|
+
expect {
|
45
45
|
subject[10]
|
46
|
-
}.
|
46
|
+
}.to raise_error(
|
47
47
|
Kippt::APIError, "Resource could not be loaded: Resource not found.")
|
48
48
|
end
|
49
49
|
end
|
@@ -51,27 +51,7 @@ shared_examples_for "read collection resource" do
|
|
51
51
|
|
52
52
|
describe "#find" do
|
53
53
|
it "exists" do
|
54
|
-
subject.respond_to?(:find).
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#collection_from_url" do
|
59
|
-
it "returns a new collection" do
|
60
|
-
stub_get("/#{base_uri}/?limit=20&offset=20").
|
61
|
-
to_return(:status => 200, :body => fixture("#{collection_fixture}.json"))
|
62
|
-
collection = subject.collection_from_url("/api/#{base_uri}/?limit=20&offset=20")
|
63
|
-
collection.should be_a(collection_class)
|
64
|
-
end
|
65
|
-
|
66
|
-
context "when passed URL is blank" do
|
67
|
-
it "raises ArgumentError" do
|
68
|
-
lambda {
|
69
|
-
subject.collection_from_url("")
|
70
|
-
}.should raise_error(ArgumentError, "The parameter URL can't be blank")
|
71
|
-
lambda {
|
72
|
-
subject.collection_from_url(nil)
|
73
|
-
}.should raise_error(ArgumentError, "The parameter URL can't be blank")
|
74
|
-
end
|
54
|
+
expect(subject.respond_to?(:find)).to be_truthy
|
75
55
|
end
|
76
56
|
end
|
77
57
|
end
|
@@ -2,7 +2,7 @@ shared_examples_for "resource" do
|
|
2
2
|
describe "attribute accessors" do
|
3
3
|
it "delegates to attributes" do
|
4
4
|
attributes.each do |attribute_name|
|
5
|
-
subject.send(attribute_name).
|
5
|
+
expect(subject.send(attribute_name)).to eq data[attribute_name.to_s]
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -10,70 +10,70 @@ shared_examples_for "resource" do
|
|
10
10
|
describe "mapped attribute accessors" do
|
11
11
|
it "delegates to attributes and wraps with to a object" do
|
12
12
|
mapped_attributes.each do |attribute_name, attribute_class|
|
13
|
-
subject.send(attribute_name).class.to_s.
|
13
|
+
expect(subject.send(attribute_name).class.to_s).to eq attribute_class
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#destroy" do
|
19
|
-
let(:collection_resource) {
|
19
|
+
let(:collection_resource) { double(:collection_resource) }
|
20
20
|
|
21
21
|
it "sends delete request to the server" do
|
22
|
-
client.
|
23
|
-
collection_resource.
|
24
|
-
subject.destroy.
|
22
|
+
allow(client).to receive(:collection_resource_for).and_return(collection_resource)
|
23
|
+
expect(collection_resource).to receive(:destroy_resource).with(subject).and_return(true)
|
24
|
+
expect(subject.destroy).to be_truthy
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "#save" do
|
29
29
|
context "with valid parameters" do
|
30
|
-
let(:collection_resource) {
|
30
|
+
let(:collection_resource) { double(:collection_resource) }
|
31
31
|
|
32
32
|
before do
|
33
|
-
client.
|
33
|
+
allow(client).to receive(:collection_resource_for).and_return(collection_resource)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "sends POST request to server" do
|
37
|
-
collection_resource.
|
37
|
+
expect(collection_resource).to receive(:save_resource).with(subject).and_return({})
|
38
38
|
subject.save
|
39
39
|
end
|
40
40
|
|
41
41
|
it "returns true" do
|
42
|
-
collection_resource.
|
42
|
+
allow(collection_resource).to receive(:save_resource).and_return(
|
43
43
|
{:success => true})
|
44
|
-
subject.save.
|
44
|
+
expect(subject.save).to be_truthy
|
45
45
|
end
|
46
46
|
|
47
47
|
it "sets the updated attributes received from the server" do
|
48
|
-
collection_resource.
|
48
|
+
allow(collection_resource).to receive(:save_resource).and_return(
|
49
49
|
{:success => true, :resource => {:id => 9999}})
|
50
50
|
subject.save
|
51
|
-
subject.id.
|
51
|
+
expect(subject.id).to eq 9999
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
context "with invalid parameters" do
|
56
|
-
let(:collection_resource) {
|
56
|
+
let(:collection_resource) { double(:collection_resource) }
|
57
57
|
|
58
58
|
before do
|
59
|
-
client.
|
60
|
-
collection_resource.
|
59
|
+
allow(client).to receive(:collection_resource_for).and_return(collection_resource)
|
60
|
+
allow(collection_resource).to receive(:save_resource).and_return({:success => false, :error_message => "No url."})
|
61
61
|
end
|
62
62
|
|
63
63
|
it "sets an error messages" do
|
64
64
|
subject.save
|
65
|
-
subject.errors.
|
65
|
+
expect(subject.errors).to eq ["No url."]
|
66
66
|
end
|
67
67
|
|
68
68
|
it "returns false" do
|
69
|
-
subject.save.
|
69
|
+
expect(subject.save).to be_falsey
|
70
70
|
end
|
71
71
|
|
72
72
|
it "clears previous errors" do
|
73
73
|
subject.save
|
74
|
-
subject.errors.
|
74
|
+
expect(subject.errors).to eq ["No url."]
|
75
75
|
subject.save
|
76
|
-
subject.errors.
|
76
|
+
expect(subject.errors).to eq ["No url."]
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|