discourse_api 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +21 -21
  3. data/.travis.yml +5 -5
  4. data/CHANGELOG.md +105 -99
  5. data/Gemfile +4 -4
  6. data/Guardfile +5 -5
  7. data/LICENSE.txt +22 -22
  8. data/README.md +73 -73
  9. data/Rakefile +7 -7
  10. data/discourse_api.gemspec +35 -35
  11. data/examples/backups.rb +18 -18
  12. data/examples/category.rb +21 -21
  13. data/examples/change_topic_status.rb +33 -33
  14. data/examples/create_topic.rb +23 -23
  15. data/examples/create_user.rb +14 -14
  16. data/examples/dashboard.rb +13 -13
  17. data/examples/disposable_invite_tokens.rb +18 -18
  18. data/examples/example.rb +9 -9
  19. data/examples/groups.rb +25 -25
  20. data/examples/invite_users.rb +15 -15
  21. data/examples/post_action.rb +25 -25
  22. data/examples/search.rb +9 -9
  23. data/examples/sso.rb +14 -14
  24. data/examples/topic_lists.rb +15 -15
  25. data/examples/update_user.rb +22 -22
  26. data/lib/discourse_api.rb +5 -5
  27. data/lib/discourse_api/api/api_key.rb +31 -31
  28. data/lib/discourse_api/api/backups.rb +24 -24
  29. data/lib/discourse_api/api/badges.rb +28 -28
  30. data/lib/discourse_api/api/categories.rb +57 -57
  31. data/lib/discourse_api/api/dashboard.rb +24 -24
  32. data/lib/discourse_api/api/email.rb +15 -15
  33. data/lib/discourse_api/api/groups.rb +52 -52
  34. data/lib/discourse_api/api/invite.rb +17 -17
  35. data/lib/discourse_api/api/notifications.rb +9 -9
  36. data/lib/discourse_api/api/params.rb +55 -55
  37. data/lib/discourse_api/api/posts.rb +41 -41
  38. data/lib/discourse_api/api/private_messages.rb +10 -10
  39. data/lib/discourse_api/api/search.rb +19 -19
  40. data/lib/discourse_api/api/sso.rb +22 -22
  41. data/lib/discourse_api/api/tags.rb +10 -10
  42. data/lib/discourse_api/api/topics.rb +78 -78
  43. data/lib/discourse_api/api/users.rb +93 -85
  44. data/lib/discourse_api/client.rb +133 -133
  45. data/lib/discourse_api/error.rb +17 -17
  46. data/lib/discourse_api/single_sign_on.rb +110 -110
  47. data/lib/discourse_api/version.rb +3 -3
  48. data/routes.txt +203 -203
  49. data/spec/discourse_api/api/api_key_spec.rb +121 -121
  50. data/spec/discourse_api/api/backups_spec.rb +23 -23
  51. data/spec/discourse_api/api/badges_spec.rb +40 -40
  52. data/spec/discourse_api/api/categories_spec.rb +87 -87
  53. data/spec/discourse_api/api/email_spec.rb +39 -39
  54. data/spec/discourse_api/api/groups_spec.rb +94 -94
  55. data/spec/discourse_api/api/notifications_spec.rb +24 -24
  56. data/spec/discourse_api/api/params_spec.rb +32 -32
  57. data/spec/discourse_api/api/posts_spec.rb +41 -41
  58. data/spec/discourse_api/api/private_messages_spec.rb +22 -22
  59. data/spec/discourse_api/api/search_spec.rb +30 -30
  60. data/spec/discourse_api/api/sso_spec.rb +16 -16
  61. data/spec/discourse_api/api/topics_spec.rb +113 -113
  62. data/spec/discourse_api/api/users_spec.rb +255 -227
  63. data/spec/discourse_api/client_spec.rb +115 -115
  64. data/spec/fixtures/api.json +12 -12
  65. data/spec/fixtures/backups.json +12 -12
  66. data/spec/fixtures/badges.json +569 -569
  67. data/spec/fixtures/categories.json +72 -72
  68. data/spec/fixtures/category_latest_topics.json +92 -92
  69. data/spec/fixtures/category_topics.json +91 -91
  70. data/spec/fixtures/email_list_all.json +749 -749
  71. data/spec/fixtures/email_settings.json +13 -13
  72. data/spec/fixtures/generate_api_key.json +12 -12
  73. data/spec/fixtures/generate_master_key.json +7 -7
  74. data/spec/fixtures/groups.json +18 -18
  75. data/spec/fixtures/hot.json +113 -113
  76. data/spec/fixtures/latest.json +115 -115
  77. data/spec/fixtures/members_0.json +403 -403
  78. data/spec/fixtures/members_1.json +363 -363
  79. data/spec/fixtures/new.json +113 -113
  80. data/spec/fixtures/notifications.json +16 -16
  81. data/spec/fixtures/post.json +94 -94
  82. data/spec/fixtures/post_action_users.json +18 -18
  83. data/spec/fixtures/private_messages.json +69 -69
  84. data/spec/fixtures/regenerate_api_key.json +7 -7
  85. data/spec/fixtures/search.json +24 -24
  86. data/spec/fixtures/topic.json +739 -739
  87. data/spec/fixtures/topic_invite_user.json +3 -3
  88. data/spec/fixtures/topics_created_by.json +49 -49
  89. data/spec/fixtures/update_trust_level.json +37 -37
  90. data/spec/fixtures/upload_avatar.json +13 -13
  91. data/spec/fixtures/user.json +65 -65
  92. data/spec/fixtures/user_activate_success.json +3 -3
  93. data/spec/fixtures/user_badges.json +170 -170
  94. data/spec/fixtures/user_create_success.json +5 -5
  95. data/spec/fixtures/user_grant_admin.json +37 -37
  96. data/spec/fixtures/user_list.json +583 -583
  97. data/spec/fixtures/user_log_out_success.json +3 -3
  98. data/spec/fixtures/user_update_avatar_success.json +3 -3
  99. data/spec/fixtures/user_update_user.json +3 -3
  100. data/spec/fixtures/user_update_username.json +4 -4
  101. data/spec/spec_helper.rb +61 -61
  102. metadata +2 -2
@@ -1,121 +1,121 @@
1
- require 'spec_helper'
2
-
3
- describe DiscourseApi::API::ApiKey do
4
- subject {
5
- DiscourseApi::Client.new(
6
- "http://localhost:3000",
7
- "test_d7fd0429940",
8
- "test_user"
9
- )
10
- }
11
-
12
- describe "#api" do
13
- before do
14
- url = "http://localhost:3000/admin/api.json" +
15
- "?api_key=test_d7fd0429940&api_username=test_user"
16
- stub_get(url).to_return(body: fixture("api.json"),
17
- headers: { content_type: "application/json" })
18
- end
19
-
20
- it "requests the correct resource" do
21
- subject.api
22
- url = "http://localhost:3000/admin/api.json" +
23
- "?api_key=test_d7fd0429940&api_username=test_user"
24
- expect(a_get(url)).to have_been_made
25
- end
26
-
27
- it "returns the requested api keys" do
28
- api = subject.api
29
- expect(api).to be_an Array
30
- expect(api.first).to be_a Hash
31
- expect(api.first).to have_key('key')
32
- end
33
- end
34
-
35
- describe "#generate_user_api_key" do
36
- before do
37
- url = "http://localhost:3000/admin/users/2/generate_api_key.json" +
38
- "?api_key=test_d7fd0429940&api_username=test_user"
39
- stub_post(url).to_return(body: fixture("generate_api_key.json"),
40
- headers: { content_type: "application/json" })
41
- end
42
-
43
- it "returns the generated api key" do
44
- api_key = subject.generate_user_api_key(2)
45
- expect(api_key).to be_a Hash
46
- expect(api_key['api_key']).to have_key('key')
47
- end
48
- end
49
-
50
- describe "#revoke_user_api_key" do
51
- before do
52
- url = "http://localhost:3000/admin/users/2/revoke_api_key.json" +
53
- "?api_key=test_d7fd0429940&api_username=test_user"
54
- stub_delete(url).to_return(body: "",
55
- headers: { content_type: "application/json" })
56
- end
57
-
58
- it "returns 200" do
59
- response = subject.revoke_user_api_key(2)
60
- expect(response['status']).to eq(200)
61
- end
62
- end
63
-
64
- describe "#generate_master_key" do
65
- before do
66
- url = "http://localhost:3000/admin/api/key" +
67
- "?api_key=test_d7fd0429940&api_username=test_user"
68
- stub_post(url).to_return(body: fixture("generate_master_key.json"),
69
- headers: { content_type: "application/json" })
70
- end
71
-
72
- it "returns the generated master key" do
73
- master_key = subject.generate_master_key
74
- expect(master_key).to be_a Hash
75
- expect(master_key['api_key']).to have_key('key')
76
- expect(master_key['api_key']['user']).to eq(nil)
77
- end
78
- end
79
-
80
- describe "#revoke_api_key" do
81
- before do
82
- url = "http://localhost:3000/admin/api/key" +
83
- "?api_key=test_d7fd0429940&api_username=test_user&id=10"
84
- stub_delete(url).to_return(body: "",
85
- headers: { content_type: "application/json" })
86
- end
87
-
88
- it "requests the correct resource" do
89
- subject.revoke_api_key(10)
90
- url = "http://localhost:3000/admin/api/key" +
91
- "?api_key=test_d7fd0429940&api_username=test_user&id=10"
92
- expect(a_delete(url)).to have_been_made
93
- end
94
-
95
- it "returns 200" do
96
- response = subject.revoke_api_key(10)
97
- expect(response['status']).to eq(200)
98
- end
99
- end
100
-
101
- describe "#regenerate_api_key" do
102
- before do
103
- url = "http://localhost:3000/admin/api/key" +
104
- "?api_key=test_d7fd0429940&api_username=test_user"
105
- stub_put(url).to_return(body: fixture("regenerate_api_key.json"),
106
- headers: { content_type: "application/json" })
107
- end
108
-
109
- it "requests the correct resource" do
110
- subject.regenerate_api_key(10)
111
- url = "http://localhost:3000/admin/api/key" +
112
- "?api_key=test_d7fd0429940&api_username=test_user"
113
- expect(a_put(url)).to have_been_made
114
- end
115
-
116
- it "returns the regenerated api key" do
117
- key = subject.regenerate_api_key(10)
118
- expect(key['api_key']).to have_key('key')
119
- end
120
- end
121
- end
1
+ require 'spec_helper'
2
+
3
+ describe DiscourseApi::API::ApiKey do
4
+ subject {
5
+ DiscourseApi::Client.new(
6
+ "http://localhost:3000",
7
+ "test_d7fd0429940",
8
+ "test_user"
9
+ )
10
+ }
11
+
12
+ describe "#api" do
13
+ before do
14
+ url = "http://localhost:3000/admin/api.json" +
15
+ "?api_key=test_d7fd0429940&api_username=test_user"
16
+ stub_get(url).to_return(body: fixture("api.json"),
17
+ headers: { content_type: "application/json" })
18
+ end
19
+
20
+ it "requests the correct resource" do
21
+ subject.api
22
+ url = "http://localhost:3000/admin/api.json" +
23
+ "?api_key=test_d7fd0429940&api_username=test_user"
24
+ expect(a_get(url)).to have_been_made
25
+ end
26
+
27
+ it "returns the requested api keys" do
28
+ api = subject.api
29
+ expect(api).to be_an Array
30
+ expect(api.first).to be_a Hash
31
+ expect(api.first).to have_key('key')
32
+ end
33
+ end
34
+
35
+ describe "#generate_user_api_key" do
36
+ before do
37
+ url = "http://localhost:3000/admin/users/2/generate_api_key.json" +
38
+ "?api_key=test_d7fd0429940&api_username=test_user"
39
+ stub_post(url).to_return(body: fixture("generate_api_key.json"),
40
+ headers: { content_type: "application/json" })
41
+ end
42
+
43
+ it "returns the generated api key" do
44
+ api_key = subject.generate_user_api_key(2)
45
+ expect(api_key).to be_a Hash
46
+ expect(api_key['api_key']).to have_key('key')
47
+ end
48
+ end
49
+
50
+ describe "#revoke_user_api_key" do
51
+ before do
52
+ url = "http://localhost:3000/admin/users/2/revoke_api_key.json" +
53
+ "?api_key=test_d7fd0429940&api_username=test_user"
54
+ stub_delete(url).to_return(body: "",
55
+ headers: { content_type: "application/json" })
56
+ end
57
+
58
+ it "returns 200" do
59
+ response = subject.revoke_user_api_key(2)
60
+ expect(response['status']).to eq(200)
61
+ end
62
+ end
63
+
64
+ describe "#generate_master_key" do
65
+ before do
66
+ url = "http://localhost:3000/admin/api/key" +
67
+ "?api_key=test_d7fd0429940&api_username=test_user"
68
+ stub_post(url).to_return(body: fixture("generate_master_key.json"),
69
+ headers: { content_type: "application/json" })
70
+ end
71
+
72
+ it "returns the generated master key" do
73
+ master_key = subject.generate_master_key
74
+ expect(master_key).to be_a Hash
75
+ expect(master_key['api_key']).to have_key('key')
76
+ expect(master_key['api_key']['user']).to eq(nil)
77
+ end
78
+ end
79
+
80
+ describe "#revoke_api_key" do
81
+ before do
82
+ url = "http://localhost:3000/admin/api/key" +
83
+ "?api_key=test_d7fd0429940&api_username=test_user&id=10"
84
+ stub_delete(url).to_return(body: "",
85
+ headers: { content_type: "application/json" })
86
+ end
87
+
88
+ it "requests the correct resource" do
89
+ subject.revoke_api_key(10)
90
+ url = "http://localhost:3000/admin/api/key" +
91
+ "?api_key=test_d7fd0429940&api_username=test_user&id=10"
92
+ expect(a_delete(url)).to have_been_made
93
+ end
94
+
95
+ it "returns 200" do
96
+ response = subject.revoke_api_key(10)
97
+ expect(response['status']).to eq(200)
98
+ end
99
+ end
100
+
101
+ describe "#regenerate_api_key" do
102
+ before do
103
+ url = "http://localhost:3000/admin/api/key" +
104
+ "?api_key=test_d7fd0429940&api_username=test_user"
105
+ stub_put(url).to_return(body: fixture("regenerate_api_key.json"),
106
+ headers: { content_type: "application/json" })
107
+ end
108
+
109
+ it "requests the correct resource" do
110
+ subject.regenerate_api_key(10)
111
+ url = "http://localhost:3000/admin/api/key" +
112
+ "?api_key=test_d7fd0429940&api_username=test_user"
113
+ expect(a_put(url)).to have_been_made
114
+ end
115
+
116
+ it "returns the regenerated api key" do
117
+ key = subject.regenerate_api_key(10)
118
+ expect(key['api_key']).to have_key('key')
119
+ end
120
+ end
121
+ end
@@ -1,23 +1,23 @@
1
- require 'spec_helper'
2
-
3
- describe DiscourseApi::API::Backups do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
5
-
6
- describe "#backups" do
7
- before do
8
- stub_get("http://localhost:3000/admin/backups.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("backups.json"), headers: { content_type: "application/json" })
9
- end
10
-
11
- it "requests the correct resource" do
12
- subject.backups
13
- expect(a_get("http://localhost:3000/admin/backups.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
14
- end
15
-
16
- it "returns the requested backups" do
17
- backups = subject.backups
18
- expect(backups).to be_an Array
19
- expect(backups.first).to be_a Hash
20
- expect(backups.first).to have_key('filename')
21
- end
22
- end
23
- end
1
+ require 'spec_helper'
2
+
3
+ describe DiscourseApi::API::Backups do
4
+ subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
5
+
6
+ describe "#backups" do
7
+ before do
8
+ stub_get("http://localhost:3000/admin/backups.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("backups.json"), headers: { content_type: "application/json" })
9
+ end
10
+
11
+ it "requests the correct resource" do
12
+ subject.backups
13
+ expect(a_get("http://localhost:3000/admin/backups.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
14
+ end
15
+
16
+ it "returns the requested backups" do
17
+ backups = subject.backups
18
+ expect(backups).to be_an Array
19
+ expect(backups.first).to be_a Hash
20
+ expect(backups.first).to have_key('filename')
21
+ end
22
+ end
23
+ end
@@ -1,40 +1,40 @@
1
- require 'spec_helper'
2
-
3
- describe DiscourseApi::API::Badges do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
5
-
6
- describe "#badges" do
7
- before do
8
- stub_get("http://localhost:3000/admin/badges.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("badges.json"), headers: { content_type: "application/json" })
9
- end
10
-
11
- it "requests the correct resource" do
12
- subject.badges
13
- expect(a_get("http://localhost:3000/admin/badges.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
14
- end
15
-
16
- it "returns the requested badges" do
17
- badges = subject.badges
18
- expect(badges).to be_a Hash
19
- expect(badges['badges']).to be_an Array
20
- end
21
- end
22
-
23
- describe "#user_badges" do
24
- before do
25
- stub_get("http://localhost:3000/users/test_user/activity/badges.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_badges.json"), headers: { content_type: "application/json" })
26
- end
27
-
28
- it "requests the correct resource" do
29
- subject.user_badges('test_user')
30
- expect(a_get("http://localhost:3000/users/test_user/activity/badges.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
31
- end
32
-
33
- it "returns the requested user badges" do
34
- badges = subject.user_badges('test_user')
35
- expect(badges).to be_an Array
36
- expect(badges.first).to be_a Hash
37
- expect(badges.first).to have_key('badge_type_id')
38
- end
39
- end
40
- end
1
+ require 'spec_helper'
2
+
3
+ describe DiscourseApi::API::Badges do
4
+ subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
5
+
6
+ describe "#badges" do
7
+ before do
8
+ stub_get("http://localhost:3000/admin/badges.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("badges.json"), headers: { content_type: "application/json" })
9
+ end
10
+
11
+ it "requests the correct resource" do
12
+ subject.badges
13
+ expect(a_get("http://localhost:3000/admin/badges.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
14
+ end
15
+
16
+ it "returns the requested badges" do
17
+ badges = subject.badges
18
+ expect(badges).to be_a Hash
19
+ expect(badges['badges']).to be_an Array
20
+ end
21
+ end
22
+
23
+ describe "#user_badges" do
24
+ before do
25
+ stub_get("http://localhost:3000/users/test_user/activity/badges.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_badges.json"), headers: { content_type: "application/json" })
26
+ end
27
+
28
+ it "requests the correct resource" do
29
+ subject.user_badges('test_user')
30
+ expect(a_get("http://localhost:3000/users/test_user/activity/badges.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
31
+ end
32
+
33
+ it "returns the requested user badges" do
34
+ badges = subject.user_badges('test_user')
35
+ expect(badges).to be_an Array
36
+ expect(badges.first).to be_a Hash
37
+ expect(badges.first).to have_key('badge_type_id')
38
+ end
39
+ end
40
+ end
@@ -1,87 +1,87 @@
1
- require 'spec_helper'
2
-
3
- describe DiscourseApi::API::Categories do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
5
-
6
- describe "#categories" do
7
- before do
8
- stub_get("http://localhost:3000/categories.json?api_key=test_d7fd0429940&api_username=test_user")
9
- .to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
10
- end
11
-
12
- it "requests the correct resource" do
13
- subject.categories
14
- expect(a_get("http://localhost:3000/categories.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
15
- end
16
-
17
- it "returns the requested categories" do
18
- categories = subject.categories
19
- expect(categories).to be_an Array
20
- expect(categories.first).to be_a Hash
21
- end
22
-
23
- it "returns the requested categories with hash arg" do
24
- categories = subject.categories({})
25
- expect(categories).to be_an Array
26
- expect(categories.first).to be_a Hash
27
- end
28
- end
29
-
30
- describe '#category_latest_topics' do
31
- before do
32
- stub_get("http://localhost:3000/c/category-slug/l/latest.json?api_key=test_d7fd0429940&api_username=test_user")
33
- .to_return(body: fixture("category_latest_topics.json"), headers: { content_type: "application/json" })
34
- end
35
-
36
- it "returns the latest topics in a category" do
37
- latest_topics = subject.category_latest_topics(category_slug: 'category-slug')
38
- expect(latest_topics).to be_an Array
39
- end
40
- end
41
-
42
- describe '#category_top_topics' do
43
- before do
44
- stub_get("http://localhost:3000/c/category-slug/l/top.json?api_key=test_d7fd0429940&api_username=test_user")
45
- .to_return(
46
- body: fixture("category_topics.json"),
47
- headers: { content_type: "application/json" }
48
- )
49
- end
50
-
51
- it "returns the top topics in a category" do
52
- topics = subject.category_top_topics('category-slug')
53
- expect(topics).to be_an Array
54
- end
55
- end
56
-
57
- describe '#category_new_topics' do
58
- before do
59
- stub_get("http://localhost:3000/c/category-slug/l/new.json?api_key=test_d7fd0429940&api_username=test_user")
60
- .to_return(
61
- body: fixture("category_topics.json"),
62
- headers: { content_type: "application/json" }
63
- )
64
- end
65
-
66
- it "returns the new topics in a category" do
67
- topics = subject.category_new_topics('category-slug')
68
- expect(topics).to be_an Array
69
- end
70
- end
71
-
72
- describe '#category_new_category' do
73
- before do
74
- stub_post("http://localhost:3000/categories?api_key=test_d7fd0429940&api_username=test_user")
75
- subject.create_category(name: "test_category", color: "283890", text_color: "FFFFFF",
76
- description: "This is a description",
77
- permissions: {"group_1" => 1, "admins" => 1})
78
- end
79
-
80
- it "makes a create category request" do
81
- expect(a_post("http://localhost:3000/categories?api_key=test_d7fd0429940&api_username=test_user").with(body:
82
- "color=283890&description=This+is+a+description&name=test_category&parent_category_id&permissions%5Badmins%5D=1&permissions%5Bgroup_1%5D=1&text_color=FFFFFF")
83
- ).to have_been_made
84
- end
85
- end
86
-
87
- end
1
+ require 'spec_helper'
2
+
3
+ describe DiscourseApi::API::Categories do
4
+ subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
5
+
6
+ describe "#categories" do
7
+ before do
8
+ stub_get("http://localhost:3000/categories.json?api_key=test_d7fd0429940&api_username=test_user")
9
+ .to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
10
+ end
11
+
12
+ it "requests the correct resource" do
13
+ subject.categories
14
+ expect(a_get("http://localhost:3000/categories.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
15
+ end
16
+
17
+ it "returns the requested categories" do
18
+ categories = subject.categories
19
+ expect(categories).to be_an Array
20
+ expect(categories.first).to be_a Hash
21
+ end
22
+
23
+ it "returns the requested categories with hash arg" do
24
+ categories = subject.categories({})
25
+ expect(categories).to be_an Array
26
+ expect(categories.first).to be_a Hash
27
+ end
28
+ end
29
+
30
+ describe '#category_latest_topics' do
31
+ before do
32
+ stub_get("http://localhost:3000/c/category-slug/l/latest.json?api_key=test_d7fd0429940&api_username=test_user")
33
+ .to_return(body: fixture("category_latest_topics.json"), headers: { content_type: "application/json" })
34
+ end
35
+
36
+ it "returns the latest topics in a category" do
37
+ latest_topics = subject.category_latest_topics(category_slug: 'category-slug')
38
+ expect(latest_topics).to be_an Array
39
+ end
40
+ end
41
+
42
+ describe '#category_top_topics' do
43
+ before do
44
+ stub_get("http://localhost:3000/c/category-slug/l/top.json?api_key=test_d7fd0429940&api_username=test_user")
45
+ .to_return(
46
+ body: fixture("category_topics.json"),
47
+ headers: { content_type: "application/json" }
48
+ )
49
+ end
50
+
51
+ it "returns the top topics in a category" do
52
+ topics = subject.category_top_topics('category-slug')
53
+ expect(topics).to be_an Array
54
+ end
55
+ end
56
+
57
+ describe '#category_new_topics' do
58
+ before do
59
+ stub_get("http://localhost:3000/c/category-slug/l/new.json?api_key=test_d7fd0429940&api_username=test_user")
60
+ .to_return(
61
+ body: fixture("category_topics.json"),
62
+ headers: { content_type: "application/json" }
63
+ )
64
+ end
65
+
66
+ it "returns the new topics in a category" do
67
+ topics = subject.category_new_topics('category-slug')
68
+ expect(topics).to be_an Array
69
+ end
70
+ end
71
+
72
+ describe '#category_new_category' do
73
+ before do
74
+ stub_post("http://localhost:3000/categories?api_key=test_d7fd0429940&api_username=test_user")
75
+ subject.create_category(name: "test_category", color: "283890", text_color: "FFFFFF",
76
+ description: "This is a description",
77
+ permissions: {"group_1" => 1, "admins" => 1})
78
+ end
79
+
80
+ it "makes a create category request" do
81
+ expect(a_post("http://localhost:3000/categories?api_key=test_d7fd0429940&api_username=test_user").with(body:
82
+ "color=283890&description=This+is+a+description&name=test_category&parent_category_id&permissions%5Badmins%5D=1&permissions%5Bgroup_1%5D=1&text_color=FFFFFF")
83
+ ).to have_been_made
84
+ end
85
+ end
86
+
87
+ end