spec/cli_spec.rb in socialcast-1.1.5 vs spec/cli_spec.rb in socialcast-1.1.6
- old
+ new
@@ -8,26 +8,26 @@
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/).
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
# See expectations
end
end
-
+
context 'with a message_type message' 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 => /message\_type\"\:review\_request/).
with(:body => /please\sreview/).
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
# See expectations
end
@@ -36,11 +36,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 => /group\_id\"\:123/).
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
# See expectations
end
@@ -50,20 +50,20 @@
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/).
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
# See expectations
end
end
-
+
end
-
+
describe '#provision' do
before do
Socialcast::CLI.instance_eval do # to supress warning from stubbing load_configuration
@no_tasks = true
end
@@ -142,10 +142,41 @@
end
it 'excludes roles element' do
@result.should_not =~ %r{roles}
end
end
+ context "with a user marked for termination that shouldn't be and sanity_check option passed" do
+ before do
+ @entry = Net::LDAP::Entry.new("cn=Ryan,dc=example,dc=com")
+ @entry[:mail] = 'ryan@example.com'
+ @valid_entry = Net::LDAP::Entry.new("cn=Sean,dc=example,dc=com")
+ @valid_entry[:mail] = 'sean@example.com'
+ ldap_search_block = double("ldapsearchblock")
+ ldap_search_block.should_receive(:search).and_yield(@entry)
+ ldap_return = double("ldapreturn")
+ ldap_return.should_receive(:search).with(include(:filter=>Net::LDAP::Filter.construct("(&(mail=sean@example.com)(mail=*))"))).and_return(@valid_entry)
+
+ Socialcast::CLI.any_instance.should_receive(:create_ldap_instance).and_return(ldap_search_block, ldap_return)
+
+ @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(/ldap.yml/).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap.yml')))
+ File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
+
+ Socialcast::CLI.any_instance.should_receive(:create_socialcast_user_index_request).and_return(
+ double("request1", :get => {"users" => [{"contact_info" => {"email" => @entry[:mail][0]}}]}.to_json),
+ double("request2", :get => {"users" => [{"contact_info" => {"email" => @valid_entry[:mail][0]}}]}.to_json),
+ double("empty_request", :get => {"users" => []}.to_json)
+ )
+
+ RestClient::Resource.any_instance.should_receive(:post).never
+ end
+ it 'does not post to Socialcast and throws Kernel.abort' do
+ lambda { Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml', '--sanity_check', true] }.should raise_error SystemExit
+ end
+ end
context 'with external group member' do
before do
@entry = Net::LDAP::Entry.new("dc=example,dc=com")
@entry[:mail] = 'ryan@example.com'
@entry[:isMemberOf] = 'cn=External,dc=example,dc=com'
@@ -292,13 +323,13 @@
before do
@entry = Net::LDAP::Entry.new("dc=example,dc=com")
@entry[:mail] = 'ryan@example.com'
@entry[:manager] = 'cn=bossman,dc=example,dc=com'
@manager_email = 'bossman@example.com'
-
+
@entry.stub(:dereference_mail).with(kind_of(Net::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.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
Socialcast::CLI.any_instance.should_receive(:load_configuration).with(/ldap.yml/).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_manager_attribute.yml')))
File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)