2014-02-07 11:07:23 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
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)
|
|
|
|
xhr :get, :show, id: group.name
|
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it "responds with JSON" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
|
|
|
xhr :get, :show, id: group.name
|
|
|
|
response.should be_success
|
|
|
|
::JSON.parse(response.body)['basic_group']['id'].should == group.id
|
|
|
|
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)
|
|
|
|
xhr :get, :show, id: group.name.upcase
|
|
|
|
response.should be_success
|
|
|
|
::JSON.parse(response.body)['basic_group']['id'].should == group.id
|
|
|
|
end
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
|
|
|
|
2014-02-18 16:17:04 -05:00
|
|
|
describe "counts" do
|
2014-02-12 14:00:45 -05:00
|
|
|
it "ensures the group can be seen" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(false)
|
2014-02-18 16:17:04 -05:00
|
|
|
xhr :get, :counts, group_id: group.name
|
2014-02-12 14:00:45 -05:00
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it "performs the query and responds with JSON" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
|
|
|
Group.any_instance.expects(:posts_for).returns(Group.none)
|
2014-02-18 16:17:04 -05:00
|
|
|
xhr :get, :counts, group_id: group.name
|
2014-02-12 14:00:45 -05:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-07 11:07:23 -05:00
|
|
|
describe "posts" do
|
|
|
|
it "ensures the group can be seen" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(false)
|
|
|
|
xhr :get, :posts, group_id: group.name
|
|
|
|
response.should_not be_success
|
|
|
|
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)
|
2014-02-07 11:07:23 -05:00
|
|
|
xhr :get, :posts, group_id: group.name
|
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "members" do
|
|
|
|
it "ensures the group can be seen" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(false)
|
|
|
|
xhr :get, :members, group_id: group.name
|
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it "calls `posts_for` and responds with JSON" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
|
|
|
xhr :get, :posts, group_id: group.name
|
|
|
|
response.should be_success
|
|
|
|
end
|
2014-11-24 15:12:48 -05:00
|
|
|
|
|
|
|
it "ensures that membership can be paginated" do
|
|
|
|
5.times { group.add(Fabricate(:user)) }
|
2014-11-25 12:12:24 -05:00
|
|
|
usernames = group.users.map{ |m| m['username'] }.sort
|
|
|
|
|
2014-11-24 15:12:48 -05:00
|
|
|
xhr :get, :members, group_id: group.name, limit: 3
|
|
|
|
response.should be_success
|
|
|
|
members = JSON.parse(response.body)
|
2014-11-25 12:12:24 -05:00
|
|
|
members.map{ |m| m['username'] }.should eq(usernames[0..2])
|
2014-11-24 15:12:48 -05:00
|
|
|
|
|
|
|
xhr :get, :members, group_id: group.name, limit: 3, offset: 3
|
|
|
|
response.should be_success
|
|
|
|
members = JSON.parse(response.body)
|
2014-11-25 12:12:24 -05:00
|
|
|
members.map{ |m| m['username'] }.should eq(usernames[3..4])
|
2014-11-24 15:12:48 -05:00
|
|
|
end
|
2014-02-07 11:07:23 -05:00
|
|
|
end
|
|
|
|
end
|