spec/socialcast/command_line/cli_spec.rb in socialcast-1.3.0 vs spec/socialcast/command_line/cli_spec.rb in socialcast-1.3.1
- old
+ new
@@ -10,15 +10,18 @@
let(:ldap_with_manager_attribute_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_with_manager_attribute.yml')) }
let(:ldap_with_plugin_mapping_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_with_plugin_mapping.yml')) }
let(:ldap_with_profile_photo_config) { YAML.load_file(ldap_with_profile_photo_config_file) }
let(:ldap_without_permission_mappings_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_without_permission_mappings.yml')) }
+ before do
+ Socialcast::CommandLine.stub(:credentials).and_return(credentials)
+ end
+
describe '#share' do
# Expects -u=emily@socialcast.com -p=demo --domain=demo.socialcast.com
context 'with a basic message' do
before do
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json").
with(:body => { "message" => { "body" => "testing", "url" => nil, "message_type" => nil, "attachment_ids" => [], "group_id" => nil }}).
with(:headers => {'Accept' => 'application/json'}).
to_return(:status => 200, :body => "", :headers => {})
@@ -29,11 +32,10 @@
end
end
context 'with a message_type message' do
before do
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
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 => {})
@@ -44,11 +46,10 @@
# See expectations
end
end
context 'with a group_id param' do
before do
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
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 => {})
@@ -58,11 +59,10 @@
# See expectations
end
end
context "with a proxy" do
before do
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
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 => {})
@@ -91,11 +91,10 @@
@entry = Net::LDAP::Entry.new("dc=example,dc=com")
@entry[:mail] = 'ryan@example.com'
@entry[:jpegPhoto] = photo_data
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
user_search_resource = double(:user_search_resource)
search_api_response = {
'users' => [
{
'id' => 7,
@@ -129,11 +128,10 @@
@entry = Net::LDAP::Entry.new("dc=example,dc=com")
@entry[:mail] = 'ryan@example.com'
@entry[:jpegPhoto] = photo_data
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
user_search_resource = double(:user_search_resource)
search_api_response = {
'users' => [
{
'id' => 7,
@@ -163,11 +161,10 @@
@entry = Net::LDAP::Entry.new("dc=example,dc=com")
@entry[:mail] = 'ryan@example.com'
@entry[:jpegPhoto] = "\x89PNGabc"
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
user_search_resource = double(:user_search_resource)
search_api_response = {
'users' => [
{
'id' => 7,
@@ -200,11 +197,10 @@
before do
Net::LDAP.any_instance.stub(:search).and_return(nil)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_without_permission_mappings_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.should_not_receive(:post)
end
@@ -216,11 +212,10 @@
before do
Net::LDAP.any_instance.stub(:search).and_return(nil)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_without_permission_mappings_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.should_receive(:post).once
@@ -233,11 +228,10 @@
before do
Net::LDAP.any_instance.stub(:search).and_return(nil)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_without_permission_mappings_config)
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')))
@@ -254,11 +248,10 @@
@entry[:mail] = 'ryan@example.com'
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).with(hash_including('config' => '/my/path/to/ldap.yml')).and_return(ldap_without_permission_mappings_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
Socialcast::CommandLine::CLI.start ['provision', '-c', '/my/path/to/ldap.yml']
@@ -271,11 +264,10 @@
@entry[:mail] = 'ryan@example.com'
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_without_permission_mappings_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
end
@@ -290,11 +282,10 @@
@entry[:plugin_attr] = 'some value'
Net::LDAP.any_instance.should_receive(:search).with(hash_including(:attributes => ['plugin_attr', 'sn', 'mail', 'memberof'])).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_with_plugin_mapping_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
Socialcast::CommandLine::CLI.start ['provision', '--plugins', [File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'fake_attribute_map')]]
@@ -310,11 +301,10 @@
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_without_permission_mappings_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
@@ -332,11 +322,10 @@
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_default_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
@@ -354,11 +343,10 @@
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_with_array_permission_mapping_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
@@ -377,11 +365,10 @@
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_default_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
@@ -402,11 +389,10 @@
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_with_array_permission_mapping_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
@@ -427,11 +413,10 @@
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_with_array_permission_mapping_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
@@ -454,11 +439,10 @@
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_with_interpolated_values_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
@@ -480,11 +464,10 @@
Socialcast::CommandLine::Provision.any_instance.stub(:dereference_mail).with(kind_of(Net::LDAP::Entry), kind_of(Net::LDAP), "ldap_manager", "mail").and_return(@manager_email)
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_with_manager_attribute_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
RestClient::Resource.any_instance.stub(:post)
@@ -510,10 +493,9 @@
Socialcast::CommandLine::Provision.any_instance.should_receive(:create_ldap_instance).and_return(ldap_search_block, ldap_return)
@result = ''
Zlib::GzipWriter.stub(:open).and_yield(@result)
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
Socialcast::CommandLine::CLI.any_instance.should_receive(:ldap_config).and_return(ldap_default_config)
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
Socialcast::CommandLine::Provision.any_instance.should_receive(:create_socialcast_user_index_request).and_return(
double("request1", :get => {"users" => [{"contact_info" => {"email" => @entry[:mail][0]}}]}.to_json),