spacialdb 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ require "spacialdb"
2
+
3
+ module Spacialdb::Deprecated
4
+ end
@@ -0,0 +1,38 @@
1
+ require "spacialdb/deprecated"
2
+
3
+ module Spacialdb::Deprecated::Help
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ class HelpGroup < Array
9
+ attr_reader :title
10
+
11
+ def initialize(title)
12
+ @title = title
13
+ end
14
+
15
+ def command(name, description)
16
+ self << [name, description]
17
+ end
18
+
19
+ def space
20
+ self << ['', '']
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+ def groups
26
+ @groups ||= []
27
+ end
28
+
29
+ def group(title, &block)
30
+ groups << begin
31
+ group = HelpGroup.new(title)
32
+ yield group
33
+ group
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -63,7 +63,7 @@ module Spacialdb
63
63
  end
64
64
 
65
65
  def longest(items)
66
- items.map(&:to_s).map(&:length).sort.last
66
+ items.map { |i| i.to_s.length }.sort.last
67
67
  end
68
68
 
69
69
  def json_encode(object)
@@ -1,3 +1,3 @@
1
1
  module Spacialdb
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+ require "spacialdb/auth"
3
+
4
+ module Spacialdb
5
+ describe Auth do
6
+ before do
7
+ @cli = Spacialdb::Auth
8
+ @cli.stub!(:set_credentials_permissions)
9
+ FakeFS.activate!
10
+
11
+ File.open(@cli.credentials_file, "w") do |file|
12
+ file.puts "email\nkey"
13
+ end
14
+ end
15
+
16
+ after do
17
+ FakeFS.deactivate!
18
+ end
19
+
20
+ it "reads credentials from the credentials file" do
21
+ @cli.read_credentials.should == %w(email key)
22
+ end
23
+
24
+ it "takes the email from the first line and the key from the second line" do
25
+ @cli.read_credentials
26
+ @cli.email.should == 'email'
27
+ @cli.private_api_key.should == 'key'
28
+ end
29
+
30
+ it "asks for credentials when the file doesn't exist" do
31
+ @cli.delete_credentials
32
+ @cli.should_receive(:ask_for_credentials).and_return(["e", "k"])
33
+ @cli.email.should == 'e'
34
+ @cli.private_api_key.should == 'k'
35
+ end
36
+ end
37
+ end
@@ -11,7 +11,7 @@ describe Spacialdb::Client do
11
11
 
12
12
  it 'Client.auth -> get user details' do
13
13
  user_info = {"private_api_key"=>"abc", "email"=>"abc@de.com"}
14
- stub_request(:get, 'http://foo:bar@beta.spacialdb.com/api/users/credentials').to_return(:body => json_encode(user_info))
14
+ stub_request(:get, 'https://foo:bar@beta.spacialdb.com/api/users/credentials').to_return(:body => json_encode(user_info))
15
15
  Spacialdb::Client.auth('foo', 'bar').should == user_info
16
16
  end
17
17
 
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+ require "spacialdb/command/help"
3
+
4
+ describe Spacialdb::Command::Help do
5
+ describe "help" do
6
+ it "should show root help with no args" do
7
+ execute "help"
8
+ output.should include "Usage: spacialdb COMMAND [command-specific-options]"
9
+ output.should include "help"
10
+ end
11
+ end
12
+
13
+ it "should show command help and namespace help when ambiguous" do
14
+ execute "help db"
15
+ output.should include "spacialdb db"
16
+ output.should include "list your databases"
17
+ output.should include "Additional commands"
18
+ output.should include "db:create"
19
+ end
20
+
21
+ it "should show only command help when not ambiguous" do
22
+ execute "help db:create"
23
+ output.should include "spacialdb db:create"
24
+ output.should include "create a new database"
25
+ output.should_not include "Additional commands"
26
+ end
27
+
28
+ it "should show command help with --help" do
29
+ output = run "db:create --help"
30
+ output.should include "spacialdb db:create"
31
+ output.should include "create a new database"
32
+ output.should_not include "Additional commands"
33
+ end
34
+ end
@@ -2,12 +2,14 @@ require 'rubygems'
2
2
  require "bundler/setup"
3
3
 
4
4
  require 'rspec'
5
+ require 'rr'
6
+ require "fakefs/safe"
5
7
  require "webmock/rspec"
6
8
 
7
9
  include WebMock::API
8
10
 
9
11
  def stub_api_request(method, path)
10
- stub_request(method, "http://beta.spacialdb.com#{path}")
12
+ stub_request(method, "https://beta.spacialdb.com#{path}")
11
13
  end
12
14
 
13
15
  def prepare_command(klass)
@@ -18,6 +20,54 @@ def prepare_command(klass)
18
20
  command
19
21
  end
20
22
 
23
+ def execute(command_line)
24
+ extend RR::Adapters::RRMethods
25
+
26
+ args = command_line.split(" ")
27
+ command = args.shift
28
+
29
+ Spacialdb::Command.load
30
+ object, method = Spacialdb::Command.prepare_run(command, args)
31
+
32
+ $command_output = []
33
+
34
+ def object.print(line=nil)
35
+ last_line = $command_output.pop || ""
36
+ last_line.concat(line)
37
+ $command_output.push last_line
38
+ end
39
+
40
+ def object.puts(line=nil)
41
+ $command_output << line
42
+ end
43
+
44
+ def object.error(line=nil)
45
+ $command_output << line
46
+ end
47
+
48
+ object.send(method)
49
+ end
50
+
51
+ def output
52
+ ($command_output || []).join("\n")
53
+ end
54
+
55
+ def run(command_line)
56
+ cmd, *args = command_line.split(" ")
57
+ capture_stdout { Spacialdb::Command.run(cmd, args) }
58
+ end
59
+
60
+ def capture_stdout(&block)
61
+ original_stdout = $stdout
62
+ $stdout = fake = StringIO.new
63
+ begin
64
+ yield
65
+ ensure
66
+ $stdout = original_stdout
67
+ end
68
+ fake.string
69
+ end
70
+
21
71
  module Spacialdb::Helpers
22
72
  def display(msg, newline=true)
23
73
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: spacialdb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Shoaib Burq
@@ -11,8 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-05 00:00:00 +02:00
15
- default_executable:
14
+ date: 2011-06-11 00:00:00 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: rest-client
@@ -37,6 +36,7 @@ extra_rdoc_files: []
37
36
 
38
37
  files:
39
38
  - bin/spacialdb
39
+ - data/cacert.pem
40
40
  - lib/spacialdb/auth.rb
41
41
  - lib/spacialdb/client.rb
42
42
  - lib/spacialdb/command/auth.rb
@@ -45,17 +45,20 @@ files:
45
45
  - lib/spacialdb/command/help.rb
46
46
  - lib/spacialdb/command/version.rb
47
47
  - lib/spacialdb/command.rb
48
+ - lib/spacialdb/deprecated/help.rb
49
+ - lib/spacialdb/deprecated.rb
48
50
  - lib/spacialdb/helpers.rb
49
51
  - lib/spacialdb/version.rb
50
52
  - lib/spacialdb.rb
51
53
  - lib/vendor/okjson.rb
52
54
  - README.md
55
+ - spec/auth_spec.rb
53
56
  - spec/client_spec.rb
54
57
  - spec/command/db_spec.rb
58
+ - spec/command/help_spec.rb
55
59
  - spec/command/version_spec.rb
56
60
  - spec/commmad_spec.rb
57
61
  - spec/spec_helper.rb
58
- has_rdoc: true
59
62
  homepage: http://spacialdb.com
60
63
  licenses: []
61
64
 
@@ -79,13 +82,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
82
  requirements: []
80
83
 
81
84
  rubyforge_project:
82
- rubygems_version: 1.6.2
85
+ rubygems_version: 1.8.5
83
86
  signing_key:
84
87
  specification_version: 3
85
88
  summary: Client gem for SpacialDB cloud hosting
86
89
  test_files:
90
+ - spec/auth_spec.rb
87
91
  - spec/client_spec.rb
88
92
  - spec/command/db_spec.rb
93
+ - spec/command/help_spec.rb
89
94
  - spec/command/version_spec.rb
90
95
  - spec/commmad_spec.rb
91
96
  - spec/spec_helper.rb