remote_database_cleaner 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b0e61e8e2d3f185a306b10762b53afeb0e25033
4
+ data.tar.gz: f989f626027a228d0920675b776f5bc5c8a81f73
5
+ SHA512:
6
+ metadata.gz: 231565a9970f00fe2328679da6b026b71a8f0698a900c938206a4b214778abb1978d23971b1b08e590971f053eb598686ab7e2d2895030c77a8ae3a5a241bd46
7
+ data.tar.gz: 48c05cfce55d1a28a241d8770a0f9daf6f039090d7711a9dfd4b2a9638ac6e8bf56d6a328e99c328bb23151cb74b2c72f3df9fb923a44c4ceffde004c675ff0c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --default_path spec
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rest-client' # http
4
+ gem 'virtus', '~> 1.0' # defining attributes on a model: strong typing like objects and defaults
5
+
6
+ # Specify your gem's dependencies in remote_database_cleaner.gemspec
7
+ gemspec
8
+
9
+ gem 'rspec'
10
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tdouce
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # RemoteDatabaseCleaner
2
+
3
+ [database_cleaner](https://github.com/bmabey/database_cleaner) for [Software Oriented Architecture](http://en.wikipedia.org/wiki/Service-oriented_architecture) (SOA). Clean
4
+ database remotely when used in conjunction with [remote_database_cleaner_home_rails](https://github.com/tdouce/remote_database_cleaner_home_rails).
5
+
6
+ ## Getting Started
7
+
8
+ See [GETTING STARTED](https://github.com/tdouce/remote_database_cleaner/wiki/Getting-Started)
9
+
10
+ ## Run Tests
11
+ $ rspec
12
+
13
+ ## Contributing
14
+
15
+ 1. Fork it ( http://github.com/<my-github-username>/remote_database_cleaner/fork )
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task :default => :spec
@@ -0,0 +1,52 @@
1
+ require 'remote_database_cleaner/exceptions'
2
+ require 'virtus'
3
+
4
+ module RemoteDatabaseCleaner
5
+ class Config
6
+ include Virtus.model
7
+
8
+ DEFAULT_HOME_CONFIG = { :host => nil,
9
+ :port => nil,
10
+ :end_point => '/remote_database_cleaner/home/clean' }
11
+
12
+ attribute :home, Hash, :default => DEFAULT_HOME_CONFIG
13
+
14
+ def self.configure(configs)
15
+ new(configs)
16
+ end
17
+
18
+ def initialize(attrs = {})
19
+ attrs[:home] = update_home_config(attrs)
20
+ super(attrs)
21
+ end
22
+
23
+ def home_url
24
+ raise_no_host_error
25
+ http = 'http://'
26
+ if home[:port]
27
+ "#{ http }#{ home.fetch(:host) }:#{ home.fetch(:port) }#{ home.fetch(:end_point) }"
28
+ else
29
+ "#{ http }#{ home.fetch(:host) }#{ home.fetch(:end_point) }"
30
+ end
31
+ end
32
+
33
+ def to_hash
34
+ raise_no_host_error
35
+ super.merge(home_url: home_url)
36
+ end
37
+
38
+ def raise_no_host_error
39
+ raise RemoteDatabaseCleanerConfigError.new("RemoteDatabaseCleaner.config.home[:host] can not be nil") unless has_home?
40
+ end
41
+
42
+ def has_home?
43
+ !home[:host].nil? && !(home[:host] == '') && !home[:end_point].nil? && !(home[:end_point] == '')
44
+ end
45
+
46
+ private
47
+
48
+ def update_home_config(attrs)
49
+ attrs[:home] = DEFAULT_HOME_CONFIG.merge(attrs.fetch(:home, {}))
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,19 @@
1
+ require 'ostruct'
2
+
3
+ module RemoteDatabaseCleaner
4
+ class ConfigStruct < OpenStruct
5
+ def self.block_to_hash(block = nil)
6
+ config = self.new
7
+ if block
8
+ block.call(config)
9
+ config.to_hash
10
+ else
11
+ {}
12
+ end
13
+ end
14
+
15
+ def to_hash
16
+ @table
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module RemoteDatabaseCleaner
2
+ class RemoteDatabaseCleanerConfigError < StandardError; end
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'rest-client'
2
+
3
+ module RemoteDatabaseCleaner
4
+ class Http
5
+ def self.post(config, params, rest_client = RestClient)
6
+ new.post(config, params, rest_client)
7
+ end
8
+
9
+ def post(config, params, rest_client)
10
+ config.raise_no_host_error
11
+ rest_client.post config.home_url, params, content_type: :json, accept: :json
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module RemoteDatabaseCleaner
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ require "remote_database_cleaner/version"
2
+ require 'remote_database_cleaner/config'
3
+ require 'remote_database_cleaner/http'
4
+ require 'remote_database_cleaner/config_struct'
5
+
6
+ module RemoteDatabaseCleaner
7
+ class RemoteDatabaseCleaner
8
+ def params
9
+ { :database => :clean }
10
+ end
11
+ end
12
+
13
+ def self.configure(opts = { :config_struct => ConfigStruct, :config => Config }, &block)
14
+ config = opts.fetch(:config_struct).block_to_hash(block)
15
+ self.config = opts.fetch(:config).configure(config)
16
+ end
17
+
18
+ def self.clean(http = Http)
19
+ database_cleaner = RemoteDatabaseCleaner.new
20
+ http.post(config, database_cleaner.params)
21
+ end
22
+
23
+ def self.config
24
+ @config
25
+ end
26
+
27
+ def self.config=(config)
28
+ @config = config
29
+ end
30
+
31
+ def self.reset(config = Config.new)
32
+ self.config = config
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'remote_database_cleaner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "remote_database_cleaner"
8
+ spec.version = RemoteDatabaseCleaner::VERSION
9
+ spec.authors = ["tdouce"]
10
+ spec.email = ["travisdouce@gmail.com"]
11
+ spec.summary = %q{Initiate cleaning of test database in server from client }
12
+ spec.description = %q{Faciliates SOA (software oriented architecture) integration testing.}
13
+ spec.homepage = "https://github.com/tdouce/remote_database_cleaner"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'virtus', '~> 1.0'
25
+ spec.add_dependency 'rest-client'
26
+ end
@@ -0,0 +1,53 @@
1
+ require 'remote_database_cleaner'
2
+
3
+ describe RemoteDatabaseCleaner do
4
+
5
+ before { RemoteDatabaseCleaner.reset }
6
+
7
+ describe 'configuration' do
8
+ it 'should be configured with correct defaults' do
9
+ expect(RemoteDatabaseCleaner.config.home).to eq({:host => nil,
10
+ :port => nil,
11
+ :end_point => '/remote_database_cleaners'})
12
+ end
13
+
14
+ it 'should be able to configure with a block' do
15
+ RemoteDatabaseCleaner.configure do |config|
16
+ config.home = { host: 'tifton' }
17
+ end
18
+ expect(RemoteDatabaseCleaner.config.home[:host]).to eq('tifton')
19
+ end
20
+
21
+ it 'should be able to configure .home' do
22
+ RemoteDatabaseCleaner.config.home[:host] = 'fun_guy'
23
+ RemoteDatabaseCleaner.config.home[:port] = 3333
24
+ RemoteDatabaseCleaner.config.home[:end_point] = '/down_home'
25
+ expect(RemoteDatabaseCleaner.config.home[:host]).to eq('fun_guy')
26
+ expect(RemoteDatabaseCleaner.config.home[:port]).to eq(3333)
27
+ expect(RemoteDatabaseCleaner.config.home[:end_point]).to eq('/down_home')
28
+ end
29
+ end
30
+
31
+ describe 'errors' do
32
+ it 'should raise RemoteDatabaseCleanerConfigError if .config.home[:host] is nil' do
33
+ RemoteDatabaseCleaner.config.home[:host] = nil
34
+ expect { RemoteDatabaseCleaner.clean }.to raise_error(RemoteDatabaseCleaner::RemoteDatabaseCleanerConfigError)
35
+ end
36
+
37
+ it 'should raise RemoteDatabaseCleanerConfigError if .config.home[:end_point] is nil' do
38
+ RemoteDatabaseCleaner.config.home[:end_point] = nil
39
+ expect { RemoteDatabaseCleaner.clean }.to raise_error(RemoteDatabaseCleaner::RemoteDatabaseCleanerConfigError)
40
+ end
41
+ end
42
+
43
+ describe '.clean' do
44
+ it 'should send a post request to home' do
45
+ RemoteDatabaseCleaner::Http.stub(:post).and_return(true)
46
+ RemoteDatabaseCleaner.config.home[:host] = 'localhost'
47
+ config = RemoteDatabaseCleaner.config
48
+ params = { :database => :clean }
49
+ expect(RemoteDatabaseCleaner::Http).to receive(:post).with(config, params)
50
+ RemoteDatabaseCleaner.clean
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,55 @@
1
+ require 'virtus'
2
+ require 'remote_database_cleaner/config'
3
+ require 'remote_database_cleaner/exceptions'
4
+
5
+ describe RemoteDatabaseCleaner::Config do
6
+
7
+ let(:default_config) { RemoteDatabaseCleaner::Config.new }
8
+
9
+ describe 'initialize' do
10
+
11
+ describe 'default configuration' do
12
+ it 'should be configured with correct defaults' do
13
+ default_config = RemoteDatabaseCleaner::Config.new
14
+ expect(default_config.home).to eq({ :host => nil,
15
+ :port => nil,
16
+ :end_point => '/remote_database_cleaners'})
17
+ end
18
+ end
19
+
20
+ describe '.configure' do
21
+ it 'should be able to set configurations' do
22
+ config = RemoteDatabaseCleaner::Config.configure({ :home => { :host => 'tifton', :port => 9999, :end_point => '/somewhere' }})
23
+ expect(config.home).to eq({ :host => 'tifton',
24
+ :port => 9999,
25
+ :end_point => '/somewhere'})
26
+ end
27
+ end
28
+
29
+ describe '#home_url' do
30
+ it 'should return a url with port if port is configured' do
31
+ default_config.home[:host] = 'localhost'
32
+ default_config.home[:port] = 5555
33
+ expect(default_config.home_url).to eq('http://localhost:5555/remote_database_cleaners')
34
+ end
35
+
36
+ it 'should return a url without a port if port is not configured' do
37
+ default_config.home[:host] = 'localhost_no_port'
38
+ default_config.home[:port] = nil
39
+ expect(default_config.home_url).to eq('http://localhost_no_port/remote_database_cleaners')
40
+ end
41
+ end
42
+
43
+ describe 'errors' do
44
+ it 'should raise RemoteDatabaseConfigError if .config.home[:host] is nil' do
45
+ default_config.home[:host] = nil
46
+ expect { default_config.to_hash }.to raise_error(RemoteDatabaseCleaner::RemoteDatabaseCleanerConfigError)
47
+ end
48
+
49
+ it 'should raise RemoteDatabaseConfigError if .config.home[:end_point] is nil' do
50
+ default_config.home[:end_point] = nil
51
+ expect { default_config.to_hash }.to raise_error(RemoteDatabaseCleaner::RemoteDatabaseCleanerConfigError)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ require 'remote_database_cleaner/config_struct.rb'
2
+
3
+ describe RemoteDatabaseCleaner::ConfigStruct do
4
+
5
+ describe '.block_to_hash' do
6
+ it 'should be able to configure with a block' do
7
+ class Thing
8
+ def self.configure(&block)
9
+ RemoteDatabaseCleaner::ConfigStruct.block_to_hash(block)
10
+ end
11
+ end
12
+
13
+ thing = Thing.configure do |config|
14
+ config.first_name = 'Sam'
15
+ config.last_name = 'Iam'
16
+ end
17
+
18
+ expect(thing.to_hash).to eq({:first_name => 'Sam', :last_name => 'Iam'})
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'remote_database_cleaner/http.rb'
2
+
3
+ describe RemoteDatabaseCleaner::Http do
4
+
5
+ describe '.post' do
6
+
7
+ let(:config) { double(:home_url => 'http://somewhere') }
8
+ let(:params) { double(:first_name => 'Sam', :last_name => 'Iam') }
9
+ let(:rest_client) { double('RestClient') }
10
+
11
+ it 'should raise no host config errors' do
12
+ rest_client.stub(:post).with(config.home_url, params, content_type: :json, accept: :json).and_return(true)
13
+ expect(config).to receive(:raise_no_host_error)
14
+ RemoteDatabaseCleaner::Http.post(config, params, rest_client)
15
+ end
16
+
17
+ it 'should send http request to home_url with params' do
18
+ config.stub(:raise_no_host_error)
19
+ expect(rest_client).to receive(:post).with(config.home_url, params, content_type: :json, accept: :json)
20
+ RemoteDatabaseCleaner::Http.post(config, params, rest_client)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ require 'remote_database_cleaner'
2
+
3
+ describe RemoteDatabaseCleaner do
4
+ it 'should return params for http request' do
5
+ rfg = RemoteDatabaseCleaner::RemoteDatabaseCleaner.new
6
+ expect(rfg.params).to eq({ :database => :clean })
7
+ end
8
+
9
+ it 'should be able to configure with a block' do
10
+ pending
11
+ end
12
+
13
+ describe '.config' do
14
+ it 'should be able to set and get config' do
15
+ config = double('config')
16
+ RemoteDatabaseCleaner.config = config
17
+ expect(RemoteDatabaseCleaner.config).to equal(config)
18
+ end
19
+ end
20
+
21
+ describe '.reset' do
22
+ it 'should be able to reset the configuration' do
23
+ config = double('config')
24
+ RemoteDatabaseCleaner.config = config
25
+ RemoteDatabaseCleaner.reset(double('config'))
26
+ expect(RemoteDatabaseCleaner.config).to_not equal(config)
27
+ end
28
+ end
29
+
30
+ describe '.clean' do
31
+ it 'should send http request and parse request' do
32
+ config = double('config', :home_url => 'http://somewhere', :to_hash => {})
33
+ http = double('RemoteDatabaseCleaner::Http', :post => {})
34
+ RemoteDatabaseCleaner.config = config
35
+ expect(http).to receive(:post).with(config, { :database => :clean })
36
+ RemoteDatabaseCleaner.clean(http)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ # our gem
4
+ require 'remote_database_cleaner'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remote_database_cleaner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - tdouce
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: virtus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Faciliates SOA (software oriented architecture) integration testing.
70
+ email:
71
+ - travisdouce@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/remote_database_cleaner.rb
83
+ - lib/remote_database_cleaner/config.rb
84
+ - lib/remote_database_cleaner/config_struct.rb
85
+ - lib/remote_database_cleaner/exceptions.rb
86
+ - lib/remote_database_cleaner/http.rb
87
+ - lib/remote_database_cleaner/version.rb
88
+ - remote_database_cleaner.gemspec
89
+ - spec/integration/remote_database_cleaner_spec.rb
90
+ - spec/models/remote_database_cleaner/config_spec.rb
91
+ - spec/models/remote_database_cleaner/config_struct_spec.rb
92
+ - spec/models/remote_database_cleaner/http_spec.rb
93
+ - spec/models/remote_database_cleaner_spec.rb
94
+ - spec/spec_helper.rb
95
+ homepage: https://github.com/tdouce/remote_database_cleaner
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Initiate cleaning of test database in server from client
119
+ test_files:
120
+ - spec/integration/remote_database_cleaner_spec.rb
121
+ - spec/models/remote_database_cleaner/config_spec.rb
122
+ - spec/models/remote_database_cleaner/config_struct_spec.rb
123
+ - spec/models/remote_database_cleaner/http_spec.rb
124
+ - spec/models/remote_database_cleaner_spec.rb
125
+ - spec/spec_helper.rb
126
+ has_rdoc: