rhoconnect-rb 0.3.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,16 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
- describe Rhoconnect::EndpointHelpers do
3
+ describe Rhoconnectrb::EndpointHelpers do
4
4
 
5
5
  # Auth stub class
6
6
  class AuthTest; end
7
7
  class BrokenResource < ActiveRecord::Base
8
- include Rhoconnect::Resource
8
+ include Rhoconnectrb::Resource
9
9
  end
10
10
 
11
11
  # Query stub class
12
12
  class Product < ActiveRecord::Base
13
- include Rhoconnect::Resource
13
+ include Rhoconnectrb::Resource
14
14
  def self.rhoconnect_query(partition, attributes = nil)
15
15
  [self.new]
16
16
  end
@@ -20,7 +20,7 @@ describe Rhoconnect::EndpointHelpers do
20
20
  AuthTest.stub!(:do_auth).and_return(success)
21
21
  AuthTest.should_receive(:do_auth).with(@creds)
22
22
 
23
- Rhoconnect.configure do |config|
23
+ Rhoconnectrb.configure do |config|
24
24
  config.uri = "http://test.rhoconnect.com"
25
25
  config.token = "token"
26
26
  config.authenticate = lambda {|credentials|
@@ -46,31 +46,31 @@ describe Rhoconnect::EndpointHelpers do
46
46
 
47
47
  it "should call configured authenticate block" do
48
48
  setup_auth_test(true)
49
- Rhoconnect::Authenticate.call(@env).should == [
49
+ Rhoconnectrb::Authenticate.call(@env).should == [
50
50
  200, {'Content-Type' => 'text/plain'}, [nil]
51
51
  ]
52
52
  end
53
53
 
54
54
  it "should call configured authenticate block with 401" do
55
55
  setup_auth_test(false)
56
- Rhoconnect::Authenticate.call(@env).should == [
56
+ Rhoconnectrb::Authenticate.call(@env).should == [
57
57
  401, {'Content-Type' => 'text/plain'}, [""]
58
58
  ]
59
59
  end
60
60
 
61
61
  it "should return true if no authenticate block exists" do
62
- Rhoconnect.configure do |config|
62
+ Rhoconnectrb.configure do |config|
63
63
  config.uri = "http://test.rhoconnect.com"
64
64
  config.token = "token"
65
65
  end
66
- Rhoconnect.configuration.authenticate.should be_nil
67
- Rhoconnect::Authenticate.call(@env).should == [
66
+ Rhoconnectrb.configuration.authenticate.should be_nil
67
+ Rhoconnectrb::Authenticate.call(@env).should == [
68
68
  200, {'Content-Type' => 'text/plain'}, [nil]
69
69
  ]
70
70
  end
71
71
 
72
72
  it "should call authenticate block with empty params" do
73
- Rhoconnect::EndpointHelpers.authenticate('text/plain', '').should == [
73
+ Rhoconnectrb::EndpointHelpers.authenticate('text/plain', '').should == [
74
74
  200, {"Content-Type"=>"text/plain"}, [nil]
75
75
  ]
76
76
  end
@@ -89,22 +89,22 @@ describe Rhoconnect::EndpointHelpers do
89
89
  )
90
90
  @env.stub!(:body).and_return(@strio)
91
91
  Rack::Request.stub!(:new).and_return(@env)
92
- code, content_type, body = Rhoconnect::Query.call(@env)
92
+ code, content_type, body = Rhoconnectrb::Query.call(@env)
93
93
  code.should == 200
94
94
  content_type.should == { "Content-Type" => "application/json" }
95
95
  JSON.parse(body[0]).should == { '1' => Product.new.normalized_attributes }
96
96
  end
97
97
 
98
- it "should fail on missing Rhoconnect::Resource" do
98
+ it "should fail on missing Rhoconnectrb::Resource" do
99
99
  @strio.stub!(:read).and_return(
100
100
  {'partition' => 'testuser', 'resource' => 'Broken'}.to_json
101
101
  )
102
102
  @env.stub!(:body).and_return(@strio)
103
103
  Rack::Request.stub!(:new).and_return(@env)
104
- code, content_type, body = Rhoconnect::Query.call(@env)
104
+ code, content_type, body = Rhoconnectrb::Query.call(@env)
105
105
  code.should == 404
106
106
  content_type.should == { "Content-Type" => "text/plain" }
107
- body[0].should == "Missing Rhoconnect::Resource Broken"
107
+ body[0].should == "Missing Rhoconnectrb::Resource Broken"
108
108
  end
109
109
 
110
110
  it "should fail on undefined rhoconnect_query method" do
@@ -113,7 +113,7 @@ describe Rhoconnect::EndpointHelpers do
113
113
  )
114
114
  @env.stub!(:body).and_return(@strio)
115
115
  Rack::Request.stub!(:new).and_return(@env)
116
- code, content_type, body = Rhoconnect::Query.call(@env)
116
+ code, content_type, body = Rhoconnectrb::Query.call(@env)
117
117
  code.should == 404
118
118
  content_type.should == { "Content-Type" => "text/plain" }
119
119
  body[0].should == "error on method `rhoconnect_query` for BrokenResource: undefined method `rhoconnect_query' for BrokenResource:Class"
@@ -126,7 +126,7 @@ describe Rhoconnect::EndpointHelpers do
126
126
  @env.stub!(:body).and_return(@strio)
127
127
  Rack::Request.stub!(:new).and_return(@env)
128
128
  Product.stub!(:rhoconnect_receive_create).and_return { raise "error in create" }
129
- code, content_type, body = Rhoconnect::Create.call(@env)
129
+ code, content_type, body = Rhoconnectrb::Create.call(@env)
130
130
  code.should == 500
131
131
  content_type.should == { "Content-Type" => "text/plain" }
132
132
  body[0].should == "error in create"
@@ -144,7 +144,7 @@ describe Rhoconnect::EndpointHelpers do
144
144
  @strio.stub!(:read).and_return(params.to_json)
145
145
  @env.stub!(:body).and_return(@strio)
146
146
  Rack::Request.stub!(:new).and_return(@env)
147
- code, content_type, body = Rhoconnect::Create.call(@env)
147
+ code, content_type, body = Rhoconnectrb::Create.call(@env)
148
148
  code.should == 200
149
149
  content_type.should == { "Content-Type" => "text/plain" }
150
150
  body.should == ['1']
@@ -163,7 +163,7 @@ describe Rhoconnect::EndpointHelpers do
163
163
  @strio.stub!(:read).and_return(params.to_json)
164
164
  @env.stub!(:body).and_return(@strio)
165
165
  Rack::Request.stub!(:new).and_return(@env)
166
- code, content_type, body = Rhoconnect::Update.call(@env)
166
+ code, content_type, body = Rhoconnectrb::Update.call(@env)
167
167
  code.should == 200
168
168
  content_type.should == { "Content-Type" => "text/plain" }
169
169
  body.should == ["123"]
@@ -182,7 +182,7 @@ describe Rhoconnect::EndpointHelpers do
182
182
  @strio.stub!(:read).and_return(params.to_json)
183
183
  @env.stub!(:body).and_return(@strio)
184
184
  Rack::Request.stub!(:new).and_return(@env)
185
- code, content_type, body = Rhoconnect::Delete.call(@env)
185
+ code, content_type, body = Rhoconnectrb::Delete.call(@env)
186
186
  code.should == 200
187
187
  content_type.should == { "Content-Type" => "text/plain" }
188
188
  body.should == ["123"]
@@ -203,7 +203,7 @@ describe Rhoconnect::EndpointHelpers do
203
203
  req.stub!(:env).and_return('CONTENT_TYPE' => 'application/json')
204
204
  Sinatra::RhoconnectEndpoints.stub!(:request).and_return(req)
205
205
  Sinatra::RhoconnectEndpoints.stub!(:params).and_return(@params)
206
- Rhoconnect::EndpointHelpers.stub!(:query)
206
+ Rhoconnectrb::EndpointHelpers.stub!(:query)
207
207
  app = mock("app")
208
208
  app.stub!(:post).and_yield
209
209
  app.should_receive(:post).exactly(5).times
@@ -1,11 +1,11 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
- describe Rhoconnect::Resource do
3
+ describe Rhoconnectrb::Resource do
4
4
 
5
5
  context "on set partition" do
6
6
  it "should set resource partition to :app" do
7
7
  class TestModel1 < ActiveRecord::Base
8
- include Rhoconnect::Resource
8
+ include Rhoconnectrb::Resource
9
9
 
10
10
  def partition
11
11
  :app
@@ -17,7 +17,7 @@ describe Rhoconnect::Resource do
17
17
 
18
18
  it "should set resource partition with lambda" do
19
19
  class TestModel2 < ActiveRecord::Base
20
- include Rhoconnect::Resource
20
+ include Rhoconnectrb::Resource
21
21
 
22
22
  def partition
23
23
  lambda{ 'helloworld' }
@@ -31,14 +31,14 @@ describe Rhoconnect::Resource do
31
31
  context "on initialize" do
32
32
  it "should raise exception if DataMapper or ActiveRecord::Base are missing" do
33
33
  lambda { class TestModel3
34
- include Rhoconnect::Resource
34
+ include Rhoconnectrb::Resource
35
35
  end
36
- }.should raise_error("Rhoconnect::Resource only supports ActiveRecord or DataMapper at this time.")
36
+ }.should raise_error("Rhoconnectrb::Resource only supports ActiveRecord or DataMapper at this time.")
37
37
  end
38
38
 
39
39
  it "should register callbacks for ActiveRecord::Base" do
40
40
  class TestModel4 < ActiveRecord::Base
41
- include Rhoconnect::Resource
41
+ include Rhoconnectrb::Resource
42
42
  end
43
43
 
44
44
  TestModel4.create_callback.should == :rhoconnect_create
@@ -49,7 +49,7 @@ describe Rhoconnect::Resource do
49
49
  it "should register callbacks for DataMapper::Resource" do
50
50
  class TestModel5
51
51
  include DataMapper::Resource
52
- include Rhoconnect::Resource
52
+ include Rhoconnectrb::Resource
53
53
  end
54
54
 
55
55
  TestModel5.rhoconnect_callbacks[:create].should == :rhoconnect_create
@@ -60,12 +60,12 @@ describe Rhoconnect::Resource do
60
60
  it "should raise exception if dm-serializer is missing" do
61
61
  class TestModel6
62
62
  include DataMapper::Resource
63
- include Rhoconnect::Resource
63
+ include Rhoconnectrb::Resource
64
64
  end
65
65
  TestModel6.stub!(:is_defined?).and_return(false)
66
66
  lambda {
67
67
  TestModel6.install_callbacks
68
- }.should raise_error("Rhoconnect::Resource requires dm-serializer to work with DataMapper. Install with `gem install dm-serializer` and add to your application.")
68
+ }.should raise_error("Rhoconnectrb::Resource requires dm-serializer to work with DataMapper. Install with `gem install dm-serializer` and add to your application.")
69
69
  end
70
70
  end
71
71
 
@@ -73,14 +73,14 @@ describe Rhoconnect::Resource do
73
73
 
74
74
  it "should call create update delete hook" do
75
75
  class TestModel7 < ActiveRecord::Base
76
- include Rhoconnect::Resource
76
+ include Rhoconnectrb::Resource
77
77
  def partition
78
78
  :app
79
79
  end
80
80
  end
81
- client = mock('Rhoconnect::Client')
81
+ client = mock('Rhoconnectrb::Client')
82
82
  client.stub!(:send)
83
- Rhoconnect::Client.stub!(:new).and_return(client)
83
+ Rhoconnectrb::Client.stub!(:new).and_return(client)
84
84
  [:create, :update, :destroy].each do |action|
85
85
  client.should_receive(:send).with(
86
86
  action, "TestModel7", :app, {"name"=>"John", "created_at"=>"1299636666", "updated_at"=>"1299636666", "id"=>1}
@@ -91,18 +91,18 @@ describe Rhoconnect::Resource do
91
91
 
92
92
  it "should warn on RestClient::Exception" do
93
93
  class TestModel8 < ActiveRecord::Base
94
- include Rhoconnect::Resource
94
+ include Rhoconnectrb::Resource
95
95
  def partition
96
96
  :app
97
97
  end
98
98
  end
99
- client = mock('Rhoconnect::Client')
99
+ client = mock('Rhoconnectrb::Client')
100
100
  exception = RestClient::Exception.new(
101
101
  RestClient::Response.create("error connecting to server", nil, nil), 500
102
102
  )
103
103
  exception.message = "Internal Server Error"
104
104
  client.stub!(:send).and_return { raise exception }
105
- Rhoconnect::Client.stub!(:new).and_return(client)
105
+ Rhoconnectrb::Client.stub!(:new).and_return(client)
106
106
  tm = TestModel8.new
107
107
  tm.should_receive(:warn).with(
108
108
  "TestModel8: rhoconnect_create returned error: Internal Server Error - error connecting to server"
@@ -112,14 +112,14 @@ describe Rhoconnect::Resource do
112
112
 
113
113
  it "should warn on Exception" do
114
114
  class TestModel8 < ActiveRecord::Base
115
- include Rhoconnect::Resource
115
+ include Rhoconnectrb::Resource
116
116
  def partition
117
117
  :app
118
118
  end
119
119
  end
120
- client = mock('Rhoconnect::Client')
120
+ client = mock('Rhoconnectrb::Client')
121
121
  client.stub!(:send).and_return { raise Exception.new("error connecting to server") }
122
- Rhoconnect::Client.stub!(:new).and_return(client)
122
+ Rhoconnectrb::Client.stub!(:new).and_return(client)
123
123
  tm = TestModel8.new
124
124
  tm.should_receive(:warn).with("TestModel8: rhoconnect_create returned unexpected error: error connecting to server")
125
125
  tm.rhoconnect_create
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,34 @@
1
1
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  require 'rspec'
3
3
  require 'webmock/rspec'
4
-
4
+ require 'active_resource/http_mock'
5
+ ENV["RAILS_ENV"] = "test"
5
6
  include WebMock::API
6
7
 
8
+ if RUBY_VERSION =~ /1.9/ || defined?(JRUBY_VERSION)
9
+ require 'simplecov'
10
+ SimpleCov.start do
11
+ add_filter '/spec/'
12
+ end
13
+ end
14
+
15
+ class String
16
+ def underscore
17
+ self.gsub(/::/, '/').
18
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
19
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
20
+ tr("-", "_").
21
+ downcase
22
+ end
23
+ end
24
+
7
25
  # stub for rack
8
26
  module Rack
9
27
  class Request; end
10
28
  end
11
29
 
12
30
  # stubs for rails engine
13
- module Rails
31
+ module Rails
14
32
  class Engine; end
15
33
  end
16
34
 
@@ -35,43 +53,43 @@ require 'rhoconnect-rb'
35
53
  # define ActiveRecord and DM here for testing
36
54
  module ActiveRecord
37
55
  class Base
38
-
56
+
39
57
  def attributes
40
58
  {
41
- "name" => "John",
59
+ "name" => "John",
42
60
  "created_at" => Time.parse("Wed Mar 09 02:11:06 UTC 2011"),
43
- "updated_at" => Time.parse("Wed Mar 09 02:11:06 UTC 2011"),
61
+ "updated_at" => Time.parse("Wed Mar 09 02:11:06 UTC 2011"),
44
62
  "id" => 1
45
63
  }
46
64
  end
47
-
65
+
48
66
  def attributes=(attribs); end
49
-
67
+
50
68
  def id; 1 end
51
-
69
+
52
70
  def warn(*args)
53
71
  Kernel.warn(args)
54
72
  end
55
-
73
+
56
74
  def save; end
57
-
75
+
58
76
  def self.find(object_id)
59
77
  self.new
60
78
  end
61
-
79
+
62
80
  def destroy; end
63
-
81
+
64
82
  class << self
65
83
  attr_accessor :create_callback,:destroy_callback,:update_callback
66
-
84
+
67
85
  def after_create(callback)
68
86
  @create_callback = callback
69
87
  end
70
-
88
+
71
89
  def after_destroy(callback)
72
90
  @destroy_callback = callback
73
91
  end
74
-
92
+
75
93
  def after_update(callback)
76
94
  @update_callback = callback
77
95
  end
@@ -81,29 +99,29 @@ end
81
99
 
82
100
  module DataMapper
83
101
  module Resource
84
-
102
+
85
103
  def attributes
86
104
  {
87
- :created_at => DateTime.parse("Wed Mar 09 02:11:06 UTC 2011"),
105
+ :created_at => DateTime.parse("Wed Mar 09 02:11:06 UTC 2011"),
88
106
  :updated_at => DateTime.parse("Wed Mar 09 02:11:06 UTC 2011"),
89
- :name => "John",
107
+ :name => "John",
90
108
  :id => 1
91
109
  }
92
110
  end
93
-
111
+
94
112
  def self.included(model)
95
113
  model.extend(ClassMethods)
96
114
  end
97
-
115
+
98
116
  module ClassMethods
99
117
  attr_accessor :rhoconnect_callbacks
100
-
118
+
101
119
  def after(action, callback)
102
120
  @rhoconnect_callbacks ||= {}
103
121
  @rhoconnect_callbacks[action] = callback
104
122
  end
105
123
  end
106
124
  end
107
-
125
+
108
126
  module Serialize; end
109
127
  end
@@ -1,19 +1,27 @@
1
- Rhoconnect.configure do |config|
2
- # Rhconnect.configure is used to set the url and token to your rhoconnect instance.
3
- # If you are connecting to a rhconnect instance provisioned from Heroku the uri and token are already defined. Just leave commented out.
4
-
5
- #config.uri = "http://myrhoconnect-server.com"
6
- #config.token = "secrettoken"
7
-
8
- # app_endpoint is the url of this rails app. It is used to tell the rhoconnect instance where this rails app is located. A rest call is sent on the startup of this rails app
9
- # which will set the rhoconnect instance to point to this rails app.
10
- # If you do not define app_endpoint, you will have to set this variable manually using the rhoconnect console.
11
-
12
- #config.app_endpoint = "http://myapp.heroku.com"
13
-
14
- # authenticate allows you to define your own custom authentication. credentials is a hash = {:login => login, :password => password}. Leave commented out or return true if you do not wish to authenticate yourself.
15
-
16
- #config.authenticate = lambda { |credentials|
17
- # return true
18
- #}
1
+ # Configure your Rhoconnect-rb plugin
2
+ Rhoconnectrb.configure do |config|
3
+
4
+ # `uri` defines the location of your rhoconnect instance.
5
+ config.uri = "http://localhost:9292"
6
+
7
+ # `token` is the rhoconnect token for your rhoconnect instance.
8
+ # You can find the value for this token in your rhoconnect web console.
9
+ config.token = "my-rhoconnect-token"
10
+
11
+ # `app_endpoint` is the url of this rails app. It is used to notify the
12
+ # rhoconnect instance where this rails app is located on startup.
13
+ # If you do not define `app_endpoint`, you will have to set this variable
14
+ # manually using the rhoconnect web console.
15
+ config.app_endpoint = "http://localhost:3000"
16
+
17
+
18
+ # Use `authenticate` to define your authentication logic.
19
+ # credentials are passed in as a hash:
20
+ # {
21
+ # :login => 'someusername',
22
+ # :password => 'somepassword'
23
+ # }
24
+ config.authenticate = lambda { |credentials|
25
+ return true
26
+ }
19
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhoconnect-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 Z
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -54,19 +54,29 @@ files:
54
54
  - .gitignore
55
55
  - .rspec
56
56
  - .travis.yml
57
+ - CHANGELOG.md
57
58
  - Gemfile
58
59
  - README.md
59
60
  - Rakefile
60
61
  - config/routes.rb
61
62
  - init.rb
62
63
  - lib/rhoconnect-rb.rb
63
- - lib/rhoconnect/client.rb
64
- - lib/rhoconnect/configuration.rb
65
- - lib/rhoconnect/endpoints.rb
66
- - lib/rhoconnect/railtie.rb
67
- - lib/rhoconnect/resource.rb
68
- - lib/rhoconnect/version.rb
64
+ - lib/rhoconnectrb/api/base.rb
65
+ - lib/rhoconnectrb/api/clients.rb
66
+ - lib/rhoconnectrb/api/read_state.rb
67
+ - lib/rhoconnectrb/api/resource.rb
68
+ - lib/rhoconnectrb/api/sources.rb
69
+ - lib/rhoconnectrb/api/store.rb
70
+ - lib/rhoconnectrb/api/system.rb
71
+ - lib/rhoconnectrb/api/users.rb
72
+ - lib/rhoconnectrb/client.rb
73
+ - lib/rhoconnectrb/configuration.rb
74
+ - lib/rhoconnectrb/endpoints.rb
75
+ - lib/rhoconnectrb/railtie.rb
76
+ - lib/rhoconnectrb/resource.rb
77
+ - lib/rhoconnectrb/version.rb
69
78
  - rhoconnect-rb.gemspec
79
+ - spec/api_spec.rb
70
80
  - spec/client_spec.rb
71
81
  - spec/endpoints_spec.rb
72
82
  - spec/resource_spec.rb
@@ -87,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
97
  version: '0'
88
98
  segments:
89
99
  - 0
90
- hash: 2309536265588466998
100
+ hash: 2603888256390272486
91
101
  required_rubygems_version: !ruby/object:Gem::Requirement
92
102
  none: false
93
103
  requirements:
@@ -101,6 +111,7 @@ signing_key:
101
111
  specification_version: 3
102
112
  summary: Rhoconnect rails plugin
103
113
  test_files:
114
+ - spec/api_spec.rb
104
115
  - spec/client_spec.rb
105
116
  - spec/endpoints_spec.rb
106
117
  - spec/resource_spec.rb
@@ -1,3 +0,0 @@
1
- module Rhoconnect
2
- VERSION = "0.3.2"
3
- end