2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2014-02-07 11:07:23 -05:00
|
|
|
|
|
|
|
describe GroupsController do
|
|
|
|
let(:group) { Fabricate(:group) }
|
|
|
|
|
|
|
|
describe 'show' do
|
|
|
|
it "ensures the group can be seen" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(false)
|
2017-08-31 00:06:56 -04:00
|
|
|
get :show, params: { id: group.name }, format: :json
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response).not_to be_success
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "responds with JSON" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
2017-08-31 00:06:56 -04:00
|
|
|
get :show, params: { id: group.name }, format: :json
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response).to be_success
|
|
|
|
expect(::JSON.parse(response.body)['basic_group']['id']).to eq(group.id)
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
2014-02-18 16:43:02 -05:00
|
|
|
|
|
|
|
it "works even with an upper case group name" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
2017-08-31 00:06:56 -04:00
|
|
|
get :show, params: { id: group.name.upcase }, format: :json
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response).to be_success
|
|
|
|
expect(::JSON.parse(response.body)['basic_group']['id']).to eq(group.id)
|
2014-02-18 16:43:02 -05:00
|
|
|
end
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "posts" do
|
|
|
|
it "ensures the group can be seen" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(false)
|
2017-08-31 00:06:56 -04:00
|
|
|
get :posts, params: { group_id: group.name }, format: :json
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response).not_to be_success
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "calls `posts_for` and responds with JSON" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
2014-02-12 14:00:45 -05:00
|
|
|
Group.any_instance.expects(:posts_for).returns(Group.none)
|
2017-08-31 00:06:56 -04:00
|
|
|
get :posts, params: { group_id: group.name }, format: :json
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response).to be_success
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "members" do
|
|
|
|
it "ensures the group can be seen" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(false)
|
2017-08-31 00:06:56 -04:00
|
|
|
get :members, params: { group_id: group.name }, format: :json
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response).not_to be_success
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "calls `posts_for` and responds with JSON" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
2017-08-31 00:06:56 -04:00
|
|
|
get :posts, params: { group_id: group.name }, format: :json
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response).to be_success
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
2014-11-24 15:12:48 -05:00
|
|
|
|
2016-12-07 04:28:43 -05:00
|
|
|
it "ensures that membership can be paginated" do
|
2014-11-24 15:12:48 -05:00
|
|
|
5.times { group.add(Fabricate(:user)) }
|
2017-07-27 21:20:09 -04:00
|
|
|
usernames = group.users.map { |m| m.username }.sort
|
2014-11-25 12:12:24 -05:00
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
get :members, params: { group_id: group.name, limit: 3 }, format: :json
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response).to be_success
|
2016-12-07 04:28:43 -05:00
|
|
|
members = JSON.parse(response.body)["members"]
|
|
|
|
expect(members.map { |m| m['username'] }).to eq(usernames[0..2])
|
2014-11-24 15:12:48 -05:00
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
get :members, params: { group_id: group.name, limit: 3, offset: 3 }, format: :json
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response).to be_success
|
2016-12-07 04:28:43 -05:00
|
|
|
members = JSON.parse(response.body)["members"]
|
|
|
|
expect(members.map { |m| m['username'] }).to eq(usernames[3..4])
|
2014-11-24 15:12:48 -05:00
|
|
|
end
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
2015-01-08 18:35:52 -05:00
|
|
|
|
2016-03-18 12:19:45 -04:00
|
|
|
describe '.posts_feed' do
|
|
|
|
it 'renders RSS' do
|
2017-08-31 00:06:56 -04:00
|
|
|
get :posts_feed, params: { group_id: group.name }, format: :rss
|
2016-03-18 12:19:45 -04:00
|
|
|
expect(response).to be_success
|
|
|
|
expect(response.content_type).to eq('application/rss+xml')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.mentions_feed' do
|
|
|
|
it 'renders RSS' do
|
2017-08-31 00:06:56 -04:00
|
|
|
get :mentions_feed, params: { group_id: group.name }, format: :rss
|
2016-03-18 12:19:45 -04:00
|
|
|
expect(response).to be_success
|
|
|
|
expect(response.content_type).to eq('application/rss+xml')
|
|
|
|
end
|
2017-12-07 16:16:53 -05:00
|
|
|
|
|
|
|
it 'fails when disabled' do
|
|
|
|
SiteSetting.enable_mentions = false
|
|
|
|
get :mentions_feed, params: { group_id: group.name }, format: :rss
|
|
|
|
expect(response).not_to be_success
|
|
|
|
end
|
2016-03-18 12:19:45 -04:00
|
|
|
end
|
|
|
|
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|