spec/cli_spec.rb in socialcast-1.2.0 vs spec/cli_spec.rb in socialcast-1.2.1.RC1
- old
+ new
@@ -7,10 +7,11 @@
before do
Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json").
with(:body => /message\_type\"\:null/).
with(:body => /testing/).
+ with(:headers => {'Accept' => 'application/json'}).
to_return(:status => 200, :body => "", :headers => {})
Socialcast::CLI.start ['share', 'testing']
end
it 'should send a POST with a message body of "testing" and nil message-type' do
@@ -22,10 +23,11 @@
before do
Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json").
with(:body => /message\_type\"\:review\_request/).
with(:body => /please\sreview/).
+ with(:headers => {'Accept' => 'application/json'}).
to_return(:status => 200, :body => "", :headers => {})
Socialcast::CLI.start ['share', 'please review', '--message_type=review_request']
end
it 'should send a POST with a message body of "please review" and message_type of "review_request"' do
@@ -35,10 +37,11 @@
context 'with a group_id param' do
before do
Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json").
with(:body => /group\_id\"\:123/).
+ with(:headers => {'Accept' => 'application/json'}).
to_return(:status => 200, :body => "", :headers => {})
Socialcast::CLI.start ['share', 'hi', '--group_id=123']
end
it 'should send a POST with group_id param == 123' do
@@ -49,10 +52,11 @@
before do
Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials_with_proxy.yml')))
stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json").
with(:body => /message\_type\"\:null/).
with(:body => /testing/).
+ with(:headers => {'Accept' => 'application/json'}).
to_return(:status => 200, :body => "", :headers => {})
Socialcast::CLI.start ['share', 'testing']
end
it 'should send a POST with a message body of "testing" and nil message-type' do
@@ -102,9 +106,29 @@
Kernel.should_not_receive(:abort)
Socialcast::CLI.start ['provision', '-c', '/my/path/to/ldap.yml', '-f']
end
it 'does post to Socialcast and does not call Kernel.abort' do end # see expectations
+ end
+ context 'with socialcast returning 401' do
+ before do
+ Net::LDAP.any_instance.stub(:search).and_return(nil)
+
+ @result = ''
+ Zlib::GzipWriter.stub(:open).and_yield(@result)
+ Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
+ Socialcast::CLI.any_instance.should_receive(:load_configuration).with('/my/path/to/ldap.yml').and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml')))
+ File.should_receive(:exists?).with('/my/path/to/ldap.yml').and_return(true)
+
+ File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
+ rest_client_resource = double(:rest_client_resource)
+ rest_client_resource.stub(:post).and_raise(RestClient::Unauthorized.new(mock('Unauthorized HTTP Response', :code => '401')))
+ Socialcast.stub(:resource_for_path).and_return(rest_client_resource)
+ Kernel.should_receive(:abort).with("Authenticated user either does not have administration privileges or the community is not configured to allow provisioning. Please contact Socialcast support to if you need help.").once
+
+ Socialcast::CLI.start ['provision', '-c', '/my/path/to/ldap.yml', '-f']
+ end
+ it "raises Kernel abort" do end # see expectations
end
context 'with absolute path to ldap.yml file' do
before do
@entry = Net::LDAP::Entry.new("dc=example,dc=com")
@entry[:mail] = 'ryan@example.com'