spec/cli_spec.rb in socialcast-1.0.8 vs spec/cli_spec.rb in socialcast-1.1.0
- old
+ new
@@ -4,12 +4,14 @@
describe '#share' do
# Expects -u=emily@socialcast.com -p=demo --domain=demo.socialcast.com
context 'with a basic message' do
before do
- stub_request(:post, "https://emily%40socialcast.com:demo@demo.socialcast.com/api/messages.xml").
- with(:body => /<message-type.*nil="true">.*testing/m).
+ File.stub(:open).with(/credentials.yml/).and_yield(File.read(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
@@ -17,12 +19,14 @@
end
end
context 'with a message_type message' do
before do
- stub_request(:post, "https://emily%40socialcast.com:demo@demo.socialcast.com/api/messages.xml").
- with(:body => /<message-type>review_request<\/message-type>.*please review/m).
+ File.stub(:open).with(/credentials.yml/).and_yield(File.read(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
@@ -31,10 +35,48 @@
end
end
describe '#provision' do
+ context 'with 0 users found in ldap' do
+ before do
+ Net::LDAP.any_instance.stub(:search).and_return(nil)
+
+ @result = ''
+ Zlib::GzipWriter.stub(:open).and_yield(@result)
+
+ File.should_receive(:open).with('/my/path/to/ldap.yml').and_yield(File.read(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)
+ File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
+
+ RestClient::Resource.any_instance.should_not_receive(:post)
+ Kernel.should_receive(:abort).once
+
+ Socialcast::CLI.start ['provision', '-c', '/my/path/to/ldap.yml']
+ end
+ it 'does not post to Socialcast and throws Kernel.abort' do end # see expectations
+ end
+ context 'with 0 users found in ldap and force option passed' do
+ before do
+ Net::LDAP.any_instance.stub(:search).and_return(nil)
+
+ @result = ''
+ Zlib::GzipWriter.stub(:open).and_yield(@result)
+
+ File.should_receive(:open).with('/my/path/to/ldap.yml').and_yield(File.read(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)
+ File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
+
+ RestClient::Resource.any_instance.should_receive(:post).once
+ 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 absolute path to ldap.yml file' do
before do
@entry = Net::LDAP::Entry.new("dc=example,dc=com")
@entry[:mail] = 'ryan@example.com'
Net::LDAP.any_instance.stub(:search).and_yield(@entry)
@@ -190,8 +232,31 @@
@result.should =~ %r{<account-type>member</account-type>}
end
it 'adds sbi_admin role' do
@result.should =~ %r{<role>sbi_admin</role>}
end
+ end
+ end
+ context 'with ldap.yml configuration including template value' do
+ before do
+ @entry = Net::LDAP::Entry.new("dc=example,dc=com")
+ @entry[:mail] = 'ryan@example.com'
+ @entry[:l] = 'San Francisco'
+ @entry[:co] = 'USA'
+
+ Net::LDAP.any_instance.stub(:search).and_yield(@entry)
+
+ @result = ''
+ Zlib::GzipWriter.stub(:open).and_yield(@result)
+ File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_interpolated_values.yml')))
+ File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result)
+ File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml')))
+
+ RestClient::Resource.any_instance.stub(:post)
+
+ Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml']
+ end
+ it 'formats l and co according to template' do
+ @result.should =~ %r{<location>San Francisco, USA</location>}
end
end
end