rest-assured 0.2.0.rc5 → 0.2.0.rc7

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.
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
- Gemfile.lock
4
3
  pkg/*
5
4
  bundle_bin
6
5
  *.db
data/Gemfile CHANGED
@@ -17,4 +17,7 @@ gem 'launchy'
17
17
  gem 'rake'
18
18
  gem "spork", "> 0.9.0.rc"
19
19
  gem "guard-spork"
20
+ gem 'rb-fsevent' if RUBY_PLATFORM =~ /darwin/
20
21
  gem 'sinatra-activerecord'
22
+ gem 'mysql'
23
+ gem 'sqlite3', '~> 1.3.4'
data/Gemfile.lock ADDED
@@ -0,0 +1,144 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rest-assured (0.2.0.rc6)
5
+ activerecord (~> 3.1.0)
6
+ activeresource (~> 3.1.0)
7
+ haml (>= 3.1.3)
8
+ rack-flash (>= 0.1.2)
9
+ sass (>= 3.1.8)
10
+ sinatra (>= 1.3.1)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ activemodel (3.1.1)
16
+ activesupport (= 3.1.1)
17
+ builder (~> 3.0.0)
18
+ i18n (~> 0.6)
19
+ activerecord (3.1.1)
20
+ activemodel (= 3.1.1)
21
+ activesupport (= 3.1.1)
22
+ arel (~> 2.2.1)
23
+ tzinfo (~> 0.3.29)
24
+ activeresource (3.1.1)
25
+ activemodel (= 3.1.1)
26
+ activesupport (= 3.1.1)
27
+ activesupport (3.1.1)
28
+ multi_json (~> 1.0)
29
+ addressable (2.2.6)
30
+ arel (2.2.1)
31
+ awesome_print (0.4.0)
32
+ builder (3.0.0)
33
+ capybara (1.1.1)
34
+ mime-types (>= 1.16)
35
+ nokogiri (>= 1.3.3)
36
+ rack (>= 1.0.0)
37
+ rack-test (>= 0.5.4)
38
+ selenium-webdriver (~> 2.0)
39
+ xpath (~> 0.1.4)
40
+ capybara-firebug (0.0.10)
41
+ capybara (~> 1.0)
42
+ childprocess (0.2.2)
43
+ ffi (~> 1.0.6)
44
+ columnize (0.3.4)
45
+ cucumber (1.1.0)
46
+ builder (>= 2.1.2)
47
+ diff-lcs (>= 1.1.2)
48
+ gherkin (~> 2.5.0)
49
+ json (>= 1.4.6)
50
+ term-ansicolor (>= 1.0.6)
51
+ database_cleaner (0.6.7)
52
+ diff-lcs (1.1.3)
53
+ ffi (1.0.9)
54
+ gherkin (2.5.4)
55
+ json (>= 1.4.6)
56
+ guard (0.8.8)
57
+ thor (~> 0.14.6)
58
+ guard-spork (0.3.1)
59
+ guard (>= 0.8.4)
60
+ spork (>= 0.8.4)
61
+ haml (3.1.3)
62
+ i18n (0.6.0)
63
+ interactive_editor (0.0.10)
64
+ spoon (>= 0.0.1)
65
+ json (1.6.1)
66
+ json_pure (1.6.1)
67
+ launchy (2.0.5)
68
+ addressable (~> 2.2.6)
69
+ linecache (0.46)
70
+ rbx-require-relative (> 0.0.4)
71
+ mime-types (1.16)
72
+ multi_json (1.0.3)
73
+ mysql (2.8.1)
74
+ nokogiri (1.5.0)
75
+ rack (1.3.5)
76
+ rack-flash (0.1.2)
77
+ rack
78
+ rack-protection (1.1.4)
79
+ rack
80
+ rack-test (0.6.1)
81
+ rack (>= 1.0)
82
+ rake (0.9.2.2)
83
+ rb-fsevent (0.4.3.1)
84
+ rbx-require-relative (0.0.5)
85
+ rspec (2.7.0)
86
+ rspec-core (~> 2.7.0)
87
+ rspec-expectations (~> 2.7.0)
88
+ rspec-mocks (~> 2.7.0)
89
+ rspec-core (2.7.1)
90
+ rspec-expectations (2.7.0)
91
+ diff-lcs (~> 1.1.2)
92
+ rspec-mocks (2.7.0)
93
+ ruby-debug (0.10.4)
94
+ columnize (>= 0.1)
95
+ ruby-debug-base (~> 0.10.4.0)
96
+ ruby-debug-base (0.10.4)
97
+ linecache (>= 0.3)
98
+ rubyzip (0.9.4)
99
+ sass (3.1.10)
100
+ selenium-webdriver (2.9.1)
101
+ childprocess (>= 0.2.1)
102
+ ffi (= 1.0.9)
103
+ json_pure
104
+ rubyzip
105
+ shoulda-matchers (1.0.0.beta3)
106
+ sinatra (1.3.1)
107
+ rack (>= 1.3.4, ~> 1.3)
108
+ rack-protection (>= 1.1.2, ~> 1.1)
109
+ tilt (>= 1.3.3, ~> 1.3)
110
+ sinatra-activerecord (0.1.3)
111
+ sinatra (>= 0.9.4)
112
+ spoon (0.0.1)
113
+ spork (0.9.0.rc9)
114
+ sqlite3 (1.3.4)
115
+ term-ansicolor (1.0.7)
116
+ thor (0.14.6)
117
+ tilt (1.3.3)
118
+ tzinfo (0.3.30)
119
+ xpath (0.1.4)
120
+ nokogiri (~> 1.3)
121
+
122
+ PLATFORMS
123
+ ruby
124
+
125
+ DEPENDENCIES
126
+ awesome_print
127
+ capybara
128
+ capybara-firebug
129
+ cucumber
130
+ database_cleaner
131
+ guard-spork
132
+ interactive_editor
133
+ launchy
134
+ mysql
135
+ rack-test
136
+ rake
137
+ rb-fsevent
138
+ rest-assured!
139
+ rspec
140
+ ruby-debug
141
+ shoulda-matchers
142
+ sinatra-activerecord
143
+ spork (> 0.9.0.rc)
144
+ sqlite3 (~> 1.3.4)
data/bin/rest-assured CHANGED
@@ -9,10 +9,22 @@ require 'rest-assured/config'
9
9
  OptionParser.new do |opts|
10
10
  opts.banner = "Usage: rest-assured [options]"
11
11
 
12
+ opts.on('-a', '--adapter mysql|sqlite') do |adapter|
13
+ AppConfig[:adapter] = adapter
14
+ end
15
+
12
16
  opts.on('-d', '--database FILENAME', "Path to database file. Defaults to ./rest-assured.db. There is a special value ':memory:' for in memory database.") do |fname|
13
17
  AppConfig[:database] = fname
14
18
  end
15
19
 
20
+ opts.on('--user', "Db username") do |uname|
21
+ AppConfig[:db_user] = uname
22
+ end
23
+
24
+ opts.on('--password', 'Db password') do |password|
25
+ AppConfig[:db_password] = password
26
+ end
27
+
16
28
  opts.on('-p', '--port PORT', Integer, "Server port. Defaults to 4578") do |port|
17
29
  AppConfig[:port] = port
18
30
  end
@@ -3,7 +3,6 @@ Feature: use doubles via api
3
3
  As a developer
4
4
  I want to mock rest services my app is consuming from
5
5
 
6
- @now
7
6
  Scenario Outline: create double
8
7
  When I create a double with "<fullpath>" as fullpath, "<content>" as response content, "<verb>" as request verb and status as "<status>"
9
8
  Then there should be 1 double with "<fullpath>" as fullpath, "<content>" as response content, "<result_verb>" as request verb and status as "<result_status>"
@@ -122,6 +122,7 @@ When /^I make (first|second) double active$/ do |ord|
122
122
  end
123
123
 
124
124
  Then /^(first|second) double should be served$/ do |ord|
125
+ sleep 0.1 # allow time for change to end up in the db
125
126
  f = instance_variable_get('@' + ord)
126
127
  get f.fullpath
127
128
  last_response.body.should == f.content
@@ -38,6 +38,9 @@ end
38
38
 
39
39
 
40
40
  Spork.each_run do
41
+ require 'rest-assured/config'
42
+ AppConfig[:adapter] = 'mysql'
43
+
41
44
  require 'rest-assured'
42
45
  require 'rest-assured/client'
43
46
  require File.expand_path('../test-server', __FILE__)
@@ -71,6 +74,7 @@ Spork.each_run do
71
74
  end
72
75
 
73
76
  After do
77
+ sleep 0.1
74
78
  DatabaseCleaner.clean
75
79
  end
76
80
  end
@@ -13,7 +13,7 @@ class TestServer
13
13
  if get_pid
14
14
  print "\nPrevious TestServer instance appears to be running. Will be using it."
15
15
  else
16
- Process.exec("bundle exec rest-assured -p #{@server_port}")
16
+ Process.exec("bundle exec rest-assured -p #{@server_port} -a mysql")
17
17
  end
18
18
  end
19
19
 
data/lib/rest-assured.rb CHANGED
@@ -4,6 +4,7 @@ require 'haml'
4
4
  require 'sass'
5
5
  require 'rack-flash'
6
6
  require 'sinatra/partials'
7
+ require 'active_record'
7
8
  require 'rest-assured/init'
8
9
  require 'rest-assured/models/double'
9
10
  require 'rest-assured/models/redirect'
@@ -43,6 +44,11 @@ module RestAssured
43
44
  include DoubleRoutes
44
45
  include RedirectRoutes
45
46
 
47
+ #before do
48
+ #ActiveRecord::Base.clear_reloadable_connections!
49
+ #ActiveRecord::Base.clear_cache!
50
+ #end
51
+
46
52
  get '/css/base.css' do
47
53
  scss :base
48
54
  end
@@ -1,3 +1,5 @@
1
+ require 'rest-assured/client/resources'
2
+
1
3
  module RestAssured
2
4
  module Client
3
5
  class Config
@@ -13,5 +15,3 @@ module RestAssured
13
15
  end
14
16
  end
15
17
  end
16
-
17
- require 'rest-assured/client/resources'
@@ -1,7 +1,8 @@
1
1
  require 'active_resource'
2
- require 'uri'
3
2
 
4
- module RestAssured::Client
5
- class Double < ActiveResource::Base
3
+ module RestAssured
4
+ module Client
5
+ class Double < ActiveResource::Base
6
+ end
6
7
  end
7
8
  end
@@ -1,14 +1,11 @@
1
+ #default config values are set here
2
+
1
3
  AppConfig = {
2
4
  :port => 4578,
3
- :environment => ENV['RACK_ENV'] || 'production'
5
+ :environment => ENV['RACK_ENV'] || 'production',
6
+ :adapter => 'sqlite'
4
7
  }
5
8
 
6
- AppConfig[:database] = if AppConfig[:environment] == 'production'
7
- './rest-assured.db'
8
- else
9
- File.expand_path("../../../db/#{AppConfig[:environment]}.db", __FILE__)
10
- end
11
-
12
9
  AppConfig[:log_file] = if AppConfig[:environment] == 'production'
13
10
  './rest-assured.log'
14
11
  else
@@ -1,25 +1,78 @@
1
1
  require 'active_record'
2
- require 'active_record/leak_connection_patch'
2
+ #require 'active_record/leaky_connections_patch'
3
+ #require 'active_record/sqlite_transaction_hell_patch'
3
4
  require 'rest-assured/config'
4
5
  require 'logger'
6
+ require 'active_support/core_ext/kernel/reporting'
5
7
 
6
- $app_logger = Logger.new(AppConfig[:log_file])
7
- $app_logger.level = Logger::DEBUG
8
-
9
- # active record logging is purely internal
10
- # thus disabling it for production
11
- ActiveRecord::Base.logger = if AppConfig[:environment] == 'production'
12
- Logger.new(test('e', '/dev/null') ? '/dev/null' : 'NUL:')
13
- else
14
- $app_logger
15
- end
16
-
17
- ActiveRecord::Base.establish_connection(
18
- :adapter => "sqlite3",
19
- :database => AppConfig[:database],
20
- :timeout => 10000
21
- )
22
-
23
- ActiveRecord::Migrator.migrate(
24
- File.expand_path('../../../db/migrate', __FILE__)
25
- )
8
+ module RestAssured
9
+ class Init
10
+ def self.init!
11
+ setup_logger
12
+ connect_db
13
+ migrate_db
14
+ end
15
+
16
+ private
17
+ def self.build_db_config
18
+ if AppConfig[:adapter] =~ /sqlite/i
19
+ AppConfig[:database] ||= if AppConfig[:environment] == 'production'
20
+ './rest-assured.db'
21
+ else
22
+ File.expand_path("../../../db/#{AppConfig[:environment]}.db", __FILE__)
23
+ end
24
+ {
25
+ :adapter => 'sqlite3',
26
+ :database => AppConfig[:database]
27
+ }
28
+ elsif AppConfig[:adapter] =~ /mysql/i
29
+ AppConfig[:database] ||= if AppConfig[:environment] != 'production'
30
+ "rest_assured_#{AppConfig[:environment]}"
31
+ else
32
+ 'rest_assured'
33
+ end
34
+ AppConfig[:db_user] ||= 'root'
35
+
36
+ {
37
+ :adapter => 'mysql',
38
+ :reconnect => true,
39
+ :user => AppConfig[:db_user],
40
+ :password => AppConfig[:db_password],
41
+ :database => AppConfig[:database]
42
+ }
43
+ else
44
+ raise "Unsupported db adapter '#{AppConfig[:adapter]}'. Valid adapters are sqlite and mysql"
45
+ end
46
+ end
47
+
48
+ def self.connect_db
49
+ config = build_db_config
50
+ ActiveRecord::Base.establish_connection config
51
+ end
52
+
53
+ def self.migrate_db
54
+ migrate = lambda { ActiveRecord::Migrator.migrate(File.expand_path('../../../db/migrate', __FILE__)) }
55
+
56
+ if AppConfig[:environment] == 'production' && Kernel.respond_to?(:silence)
57
+ silence(:stdout, &migrate)
58
+ else
59
+ migrate.call
60
+ end
61
+ end
62
+
63
+ def self.setup_logger
64
+ $app_logger = Logger.new(AppConfig[:log_file])
65
+ $app_logger.level = Logger::DEBUG
66
+
67
+ # active record logging is purely internal
68
+ # thus disabling it for production
69
+ ActiveRecord::Base.logger = if AppConfig[:environment] == 'production'
70
+ Logger.new(test('e', '/dev/null') ? '/dev/null' : 'NUL:')
71
+ else
72
+ $app_logger
73
+ end
74
+ end
75
+ end
76
+
77
+ Init.init!
78
+ end
@@ -15,7 +15,7 @@ class Double < ActiveRecord::Base
15
15
  before_validation :set_status
16
16
  after_destroy :set_active
17
17
 
18
- has_many :requests
18
+ has_many :requests, :dependent => :destroy
19
19
 
20
20
  private
21
21
  def toggle_active
@@ -2,7 +2,6 @@ class Redirect < ActiveRecord::Base
2
2
  attr_accessible :pattern, :to, :position
3
3
 
4
4
  validates_presence_of :pattern, :to
5
- validates_uniqueness_of :position, :allow_blank => true
6
5
 
7
6
  scope :ordered, order('position')
8
7
 
@@ -13,15 +12,14 @@ class Redirect < ActiveRecord::Base
13
12
 
14
13
  transaction do
15
14
  begin
16
- update_all :position => nil
17
-
18
15
  ordered_redirect_ids.each_with_index do |r_id, idx|
19
16
  r = find(r_id)
20
17
  r.position = idx
21
18
  r.save!
22
19
  end
23
- rescue
20
+ rescue => e
24
21
  # TODO log exception
22
+ puts e.inspect
25
23
  success = false
26
24
  raise ActiveRecord::Rollback
27
25
  end
@@ -66,6 +66,9 @@ module RestAssured
66
66
  end
67
67
  end
68
68
 
69
+ router.delete '/redirects/all' do
70
+ status Redirect.delete_all ? 200 : 500
71
+ end
69
72
  end
70
73
  end
71
74
  end
@@ -1,3 +1,3 @@
1
1
  module RestAssured
2
- VERSION = '0.2.0.rc5'
2
+ VERSION = '0.2.0.rc7'
3
3
  end
data/rest-assured.gemspec CHANGED
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency 'haml', '>= 3.1.3'
26
26
  s.add_dependency 'sass', '>= 3.1.8'
27
27
  s.add_dependency 'activerecord', '~> 3.1.0'
28
- s.add_dependency 'sqlite3', '>= 1.3.4'
29
- s.add_dependency 'activeresource'
28
+ s.add_dependency 'activeresource', '~> 3.1.0'
30
29
  end
31
30
 
@@ -20,13 +20,16 @@ module RestAssured::Client
20
20
 
21
21
  it 'creates new double' do
22
22
  d = Double.create :fullpath => '/some/api', :content => 'content'
23
- ::Double.where(:id => d.id).should exist
23
+ ::Double.where(:fullpath => d.fullpath, :content => d.content).should exist
24
24
  end
25
25
 
26
26
  it 'finds exising double' do
27
27
  d = ::Double.create :fullpath => '/some/api', :content => 'content'
28
28
 
29
- Double.find(d.id).id.should be d.id
29
+ dd = Double.find(d.id)
30
+
31
+ dd.fullpath.should == d.fullpath
32
+ dd.content.should == d.content
30
33
  end
31
34
 
32
35
  it 'shows request history' do
@@ -11,8 +11,6 @@ describe Redirect do
11
11
  it { should allow_mass_assignment_of(:pattern) }
12
12
  it { should allow_mass_assignment_of(:to) }
13
13
  it { should allow_mass_assignment_of(:position) }
14
- # commented out since it doesn't work with :allow_blank => true
15
- #it { should validate_uniqueness_of(:position) }
16
14
 
17
15
  it 'assigns incremental position on create' do
18
16
  r1 = Redirect.create :pattern => '.*', :to => 'someurl'
data/spec/spec_helper.rb CHANGED
@@ -43,6 +43,9 @@ Spork.prefork do
43
43
  end
44
44
 
45
45
  Spork.each_run do
46
+ require 'rest-assured/config'
47
+ AppConfig[:adapter] = 'mysql'
48
+
46
49
  require 'rest-assured'
47
50
  require 'rest-assured/client'
48
51
  require 'shoulda-matchers'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-assured
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424063
4
+ hash: 15424059
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 0
10
10
  - rc
11
- - 5
12
- version: 0.2.0.rc5
11
+ - 7
12
+ version: 0.2.0.rc7
13
13
  platform: ruby
14
14
  authors:
15
15
  - Artem Avetisyan
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-10-21 00:00:00 Z
20
+ date: 2011-10-24 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: sinatra
@@ -99,36 +99,22 @@ dependencies:
99
99
  version: 3.1.0
100
100
  type: :runtime
101
101
  version_requirements: *id005
102
- - !ruby/object:Gem::Dependency
103
- name: sqlite3
104
- prerelease: false
105
- requirement: &id006 !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 19
111
- segments:
112
- - 1
113
- - 3
114
- - 4
115
- version: 1.3.4
116
- type: :runtime
117
- version_requirements: *id006
118
102
  - !ruby/object:Gem::Dependency
119
103
  name: activeresource
120
104
  prerelease: false
121
- requirement: &id007 !ruby/object:Gem::Requirement
105
+ requirement: &id006 !ruby/object:Gem::Requirement
122
106
  none: false
123
107
  requirements:
124
- - - ">="
108
+ - - ~>
125
109
  - !ruby/object:Gem::Version
126
110
  hash: 3
127
111
  segments:
112
+ - 3
113
+ - 1
128
114
  - 0
129
- version: "0"
115
+ version: 3.1.0
130
116
  type: :runtime
131
- version_requirements: *id007
117
+ version_requirements: *id006
132
118
  description:
133
119
  email:
134
120
  - artem.avetisyan@bbc.co.uk
@@ -141,6 +127,7 @@ extra_rdoc_files: []
141
127
  files:
142
128
  - .gitignore
143
129
  - Gemfile
130
+ - Gemfile.lock
144
131
  - Guardfile
145
132
  - LICENSE
146
133
  - README.markdown
@@ -162,7 +149,6 @@ files:
162
149
  - features/call_history.feature
163
150
  - features/doubles_via_api.feature
164
151
  - features/doubles_via_ui.feature
165
- - features/persistence.feature
166
152
  - features/redirect_rules_via_api.feature
167
153
  - features/redirect_rules_via_ui.feature
168
154
  - features/step_definitions/call_history_steps.rb
@@ -173,10 +159,9 @@ files:
173
159
  - features/support/env.rb
174
160
  - features/support/selenium-fix.rb
175
161
  - features/support/test-server.rb
176
- - lib/active_record/leak_connection_patch.rb
162
+ - lib/active_record/leaky_connections_patch.rb
177
163
  - lib/rest-assured.rb
178
164
  - lib/rest-assured/client.rb
179
- - lib/rest-assured/client/double.rb
180
165
  - lib/rest-assured/client/resources.rb
181
166
  - lib/rest-assured/config.rb
182
167
  - lib/rest-assured/init.rb
@@ -264,7 +249,6 @@ test_files:
264
249
  - features/call_history.feature
265
250
  - features/doubles_via_api.feature
266
251
  - features/doubles_via_ui.feature
267
- - features/persistence.feature
268
252
  - features/redirect_rules_via_api.feature
269
253
  - features/redirect_rules_via_ui.feature
270
254
  - features/step_definitions/call_history_steps.rb
@@ -1,24 +0,0 @@
1
- Feature: Persistence
2
- In order to persist fixtrures/redirects between service restarts
3
- As a developer
4
- I want to be able to specify persistent storage
5
-
6
- Scenario: default storage
7
- Given I start service without --database option
8
- And I register "/api/something" as fullpath and "content" as response content
9
- And I restart service without --database option
10
- When I request "/api/something"
11
- Then I should get 404 in response status
12
-
13
- Scenario Outline: specify storage
14
- Given I start service with --database "<db>" option
15
- And I register "/api/something" as fullpath and "content" as response content
16
- And I restart service with --database "<db2>" option
17
- When I request "/api/something"
18
- Then I should get <status> in response status
19
-
20
- Examples:
21
- | db | db2 | status |
22
- | database.db | database.db | 200 |
23
- | /tmp/database.db | /tmp/database.db | 200 |
24
- | database.db | database2.db | 404 |
@@ -1,9 +0,0 @@
1
- require 'active_resource'
2
-
3
- module RestAssured
4
- module Client
5
- class Double < ActiveResource::Base
6
- self.site = RestAssured.config.server_address
7
- end
8
- end
9
- end