cant_wait 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/.travis.yml +16 -0
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +33 -13
  4. data/cant_wait.gemspec +15 -19
  5. data/lib/cant_wait/cant_wait_railtie.rb +17 -13
  6. data/lib/cant_wait/version.rb +1 -1
  7. data/tasks/publishing.rake +4 -4
  8. data/tasks/testing.rake +32 -10
  9. data/test/README.md +49 -20
  10. data/test/cant_wait_test.rb +2 -2
  11. data/test/test_apps/Test_3_0_03/.gitignore +12 -0
  12. data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/Gemfile +0 -26
  13. data/test/test_apps/Test_3_0_20/.gitignore +8 -0
  14. data/test/test_apps/Test_3_0_20/Gemfile +0 -26
  15. data/test/test_apps/Test_3_1_12/.gitignore +3 -6
  16. data/test/test_apps/Test_3_1_12/Gemfile +14 -33
  17. data/test/test_apps/Test_3_2_13/.gitignore +3 -6
  18. data/test/test_apps/Test_3_2_13/Gemfile +9 -31
  19. data/test/test_apps/Test_4_0_0_rc2/.gitignore +13 -0
  20. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/Gemfile +23 -38
  21. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/Rakefile +1 -1
  22. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/app/assets/javascripts/application.js +2 -2
  23. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/app/views/layouts/application.html.erb +1 -1
  24. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/application.rb +1 -1
  25. data/test/test_apps/Test_4_0_0_rc2/config/environment.rb +5 -0
  26. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/environments/development.rb +1 -1
  27. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/environments/production.rb +1 -1
  28. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/environments/test.rb +1 -1
  29. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/initializers/secret_token.rb +1 -1
  30. data/test/test_apps/Test_4_0_0_rc2/config/initializers/session_store.rb +3 -0
  31. data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/routes.rb +8 -1
  32. data/test/test_apps/Test_4_0_0_rc2/vendor/assets/stylesheets/.keep +0 -0
  33. data.tar.gz.sig +0 -0
  34. metadata +194 -198
  35. metadata.gz.sig +0 -0
  36. data/test/test_apps/Test_3_0_3/.gitignore +0 -4
  37. data/test/test_apps/Test_3_0_3/config/database.yml +0 -6
  38. data/test/test_apps/Test_4_0_0_rc1/.gitignore +0 -16
  39. data/test/test_apps/Test_4_0_0_rc1/config/database.yml +0 -7
  40. data/test/test_apps/Test_4_0_0_rc1/config/environment.rb +0 -5
  41. data/test/test_apps/Test_4_0_0_rc1/config/initializers/session_store.rb +0 -3
  42. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/README +0 -0
  43. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/Rakefile +0 -0
  44. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/app/controllers/application_controller.rb +0 -0
  45. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/app/helpers/application_helper.rb +0 -0
  46. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/app/views/layouts/application.html.erb +0 -0
  47. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/application.rb +0 -0
  48. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/boot.rb +0 -0
  49. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/environment.rb +0 -0
  50. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/environments/development.rb +0 -0
  51. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/environments/production.rb +0 -0
  52. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/environments/test.rb +0 -0
  53. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/initializers/backtrace_silencers.rb +0 -0
  54. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/initializers/inflections.rb +0 -0
  55. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/initializers/mime_types.rb +0 -0
  56. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/initializers/secret_token.rb +0 -0
  57. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/initializers/session_store.rb +0 -0
  58. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/locales/en.yml +0 -0
  59. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config/routes.rb +0 -0
  60. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/config.ru +0 -0
  61. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/db/seeds.rb +0 -0
  62. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/lib/tasks/.gitkeep +0 -0
  63. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/404.html +0 -0
  64. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/422.html +0 -0
  65. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/500.html +0 -0
  66. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/favicon.ico +0 -0
  67. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/images/rails.png +0 -0
  68. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/index.html +0 -0
  69. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/javascripts/application.js +0 -0
  70. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/javascripts/controls.js +0 -0
  71. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/javascripts/dragdrop.js +0 -0
  72. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/javascripts/effects.js +0 -0
  73. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/javascripts/prototype.js +0 -0
  74. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/javascripts/rails.js +0 -0
  75. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/robots.txt +0 -0
  76. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/public/stylesheets/.gitkeep +0 -0
  77. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/script/rails +0 -0
  78. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/test/performance/browsing_test.rb +0 -0
  79. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/test/test_helper.rb +0 -0
  80. /data/test/test_apps/{Test_3_0_3 → Test_3_0_03}/vendor/plugins/.gitkeep +0 -0
  81. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/README.rdoc +0 -0
  82. /data/test/test_apps/{Test_4_0_0_rc1/app/controllers/concerns → Test_4_0_0_rc2/app/assets/images}/.keep +0 -0
  83. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/app/assets/stylesheets/application.css +0 -0
  84. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/app/controllers/application_controller.rb +0 -0
  85. /data/test/test_apps/{Test_4_0_0_rc1/app/mailers → Test_4_0_0_rc2/app/controllers/concerns}/.keep +0 -0
  86. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/app/helpers/application_helper.rb +0 -0
  87. /data/test/test_apps/{Test_4_0_0_rc1/app/models → Test_4_0_0_rc2/app/mailers}/.keep +0 -0
  88. /data/test/test_apps/{Test_4_0_0_rc1/app/models/concerns → Test_4_0_0_rc2/app/models}/.keep +0 -0
  89. /data/test/test_apps/{Test_4_0_0_rc1/lib/assets → Test_4_0_0_rc2/app/models/concerns}/.keep +0 -0
  90. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/bin/bundle +0 -0
  91. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/bin/rails +0 -0
  92. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/bin/rake +0 -0
  93. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/boot.rb +0 -0
  94. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/initializers/backtrace_silencers.rb +0 -0
  95. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/initializers/filter_parameter_logging.rb +0 -0
  96. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/initializers/inflections.rb +0 -0
  97. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/initializers/mime_types.rb +0 -0
  98. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/initializers/wrap_parameters.rb +0 -0
  99. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config/locales/en.yml +0 -0
  100. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/config.ru +0 -0
  101. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/db/seeds.rb +0 -0
  102. /data/test/test_apps/{Test_4_0_0_rc1/lib/tasks → Test_4_0_0_rc2/lib/assets}/.keep +0 -0
  103. /data/test/test_apps/{Test_4_0_0_rc1/log → Test_4_0_0_rc2/lib/tasks}/.keep +0 -0
  104. /data/test/test_apps/{Test_4_0_0_rc1/test/controllers → Test_4_0_0_rc2/log}/.keep +0 -0
  105. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/public/404.html +0 -0
  106. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/public/422.html +0 -0
  107. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/public/500.html +0 -0
  108. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/public/favicon.ico +0 -0
  109. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/public/robots.txt +0 -0
  110. /data/test/test_apps/{Test_4_0_0_rc1/test/fixtures → Test_4_0_0_rc2/test/controllers}/.keep +0 -0
  111. /data/test/test_apps/{Test_4_0_0_rc1/test/helpers → Test_4_0_0_rc2/test/fixtures}/.keep +0 -0
  112. /data/test/test_apps/{Test_4_0_0_rc1/test/integration → Test_4_0_0_rc2/test/helpers}/.keep +0 -0
  113. /data/test/test_apps/{Test_4_0_0_rc1/test/mailers → Test_4_0_0_rc2/test/integration}/.keep +0 -0
  114. /data/test/test_apps/{Test_4_0_0_rc1/test/models → Test_4_0_0_rc2/test/mailers}/.keep +0 -0
  115. /data/test/test_apps/{Test_4_0_0_rc1/vendor/assets/javascripts → Test_4_0_0_rc2/test/models}/.keep +0 -0
  116. /data/test/test_apps/{Test_4_0_0_rc1 → Test_4_0_0_rc2}/test/test_helper.rb +0 -0
  117. /data/test/test_apps/{Test_4_0_0_rc1/vendor/assets/stylesheets → Test_4_0_0_rc2/vendor/assets/javascripts}/.keep +0 -0
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ # branches:
2
+ # only:
3
+ # - development
4
+ # except:
5
+ # - master
6
+ language: ruby
7
+ rvm:
8
+ - 1.9.2
9
+ - 1.9.3
10
+ - 2.0.0
11
+ - jruby-19mode # JRuby in 1.9 mode (last was 1.7.3)
12
+ - rbx-19mode # Rubinius in 1.9 mode (last was 2.0.0, weekly build)
13
+ before_script:
14
+ - psql -c "CREATE ROLE tester WITH LOGIN PASSWORD 'secret';" -U postgres
15
+ - psql -c 'CREATE DATABASE test WITH OWNER=tester;' -U postgres
16
+ script: rake test:all
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ 0.0.2 (June 15, 2013)
2
+ =====================
3
+
4
+ Documentation:
5
+
6
+ - Minor changes in the documentation
7
+
8
+ Development:
9
+
10
+ - Integration with travis-ci.org
11
+ - Added tests for Rails 4.0.0.rc2
12
+ - Minor code refactoring (no changes in functionality)
13
+ - Added a new rake task to run test:bundle and test:run in one pass
data/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  # cant_wait
2
+ [![Gem Version](https://badge.fury.io/rb/cant_wait.png)](https://badge.fury.io/rb/cant_wait)
3
+ [![Build Status](https://api.travis-ci.org/CarlosCD/cant_wait.png)](https://travis-ci.org/CarlosCD/cant_wait)
2
4
 
3
- This ruby gem allows to add a statement timeout for PostgreSQL databases within a Ruby on Rails application.
4
5
 
5
- If any SQL statement takes more time than the timeout value (measured in milliseconds), its execution will be cancelled, and Active Record
6
- would raise a PGError exception.
7
-
8
- ActiveRecord::StatementInvalid: PGError: ERROR: canceling statement due to statement timeout
6
+ This Ruby gem allows to add a statement timeout for PostgreSQL databases within a Ruby on Rails application.
9
7
 
10
8
  From the PostgreSQL documentation:
11
9
 
@@ -20,38 +18,55 @@ From the PostgreSQL documentation:
20
18
  (Visit <http://www.postgresql.org/docs/devel/static/runtime-config-client.html> for more information)
21
19
 
22
20
 
23
- The gem has been tested for ruby 1.9.2 and above, as well as with Rails 3.0.3 and above. Tested also with PostgreSQL 8 and 9, but it may work also in other versions supported by Active Record (see PostgreSQL documentation).
21
+ The gem has been tested with Rails 3.0.3 and above. Tested also with PostgreSQL 8 and 9, but it may work also in other versions supported by Active Record (see PostgreSQL documentation). See also test/README.md for more details.
24
22
 
25
- If you find any problems, please feel free to open any issues within the gem repository ([GitHub](https://github.com/CarlosCD/cant_wait)).
23
+ If any SQL statement takes more time than the timeout value (measured in milliseconds), its execution will be cancelled, and Active Record would raise a PGError exception.
24
+
25
+ ActiveRecord::StatementInvalid: PGError: ERROR: canceling statement due to statement timeout
26
+
27
+ If you find any problems, please feel free to open an issue in the gem repository ([GitHub](https://github.com/CarlosCD/cant_wait)).
26
28
 
27
29
 
28
30
  ## Installation
29
31
 
30
32
  Add this line to your application's Gemfile:
31
33
 
32
- gem 'cant_wait', '~> 0.0.1'
34
+ gem 'cant_wait', '~> 0.0.2'
33
35
 
34
36
  And then execute:
35
37
 
36
38
  $ bundle
37
39
 
38
40
 
41
+ ## Supported Rubies
42
+
43
+ **cant_wait** has been tested with the following versions of Ruby:
44
+
45
+ - 1.9.2
46
+ - 1.9.3
47
+ - 2.0.0
48
+ - jruby
49
+ - Rubinius
50
+
51
+ The gem may work just fine with a Ruby flavors/version not listed above. See the development documentation for more details.
52
+
53
+
39
54
  ## Usage
40
55
 
41
- In the file config/database.yml, indicate a timeout in milliseconds for each environment:
56
+ In the file <tt>config/database.yml<tt /> of the Rails application, indicate a timeout in milliseconds for each environment:
42
57
 
43
58
  production:
44
59
  adapter: postgresql
45
- timeout: 120_000 # 2 minutes
60
+ timeout: 180_000 # 3 minutes
46
61
  ...
47
62
 
48
- Then restart the application to establish the new configuration parameter(s).
63
+ Then restart the application to establish the new database settings.
49
64
 
50
65
 
51
66
  ## Development / Contributing
52
67
 
53
68
  * Source hosted on [GitHub](https://github.com/CarlosCD/cant_wait)
54
- * Details on the test setup are in the file Readme.md within the test folder. It includes details on testing in several Ruby and Rails versions.
69
+ * Details on the test setup are in the file README.md within the test folder. It includes details on testing in several Ruby and Rails versions.
55
70
 
56
71
  Contributing:
57
72
 
@@ -62,4 +77,9 @@ Contributing:
62
77
  5. Create new Pull Request
63
78
 
64
79
 
65
- May 2013
80
+ ## License
81
+
82
+ **cant_wait** is released under the [MIT License](http://opensource.org/licenses/MIT).
83
+
84
+
85
+ June 2013
data/cant_wait.gemspec CHANGED
@@ -6,30 +6,26 @@ require 'cant_wait/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'cant_wait'
8
8
  spec.version = CantWait::VERSION
9
- spec.authors = ['Carlos A. Carro Duplá']
10
- spec.email = ['ccarrodupla@gmail.com']
11
- spec.description = <<-EOF
12
- Adds a timeout setting for PostgreSQL databases in a Ruby on Rails application.
13
- If any SQL statement takes more time than the timeout value, it will be cancelled, and ActiveRecord
14
- would raise a PGError exception.
15
- In the config/database.yml file, indicate a timeout in milliseconds for each environment:
16
- production:
17
- adapter: postgresql
18
- timeout: 120_000 # 2 minutes
19
- ...
20
- (see documentation for more details)
21
- EOF
22
- spec.summary = %q{Adds statement timeout for PostgreSQL databases in Ruby on Rails. Timeout is measured in milliseconds.}
23
- spec.homepage = 'https://github.com/CarlosCD/cant_wait'
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.summary = 'Complements the Ruby on Rails web application framework by providing statement timeouts for PostgreSQL databases.'
11
+ spec.description = 'Provides statement timeouts for PostgreSQL databases in a Ruby on Rails web application. Stops any SQL statement ' <<
12
+ 'that takes more than a specified number of milliseconds.'
13
+
24
14
  spec.license = 'MIT'
25
- spec.signing_key = '/users/CarlosCD/.ssh/private_key.pem'
26
- spec.cert_chain = ['/users/CarlosCD/.ssh/public_cert.pem']
27
15
 
28
- spec.add_dependency 'rails', '>= 3.0.3'
16
+ spec.author = 'Carlos A. Carro Duplá'
17
+ spec.email = 'ccarrodupla@gmail.com'
18
+ spec.homepage = 'https://github.com/CarlosCD/cant_wait'
19
+
29
20
  spec.files = `git ls-files`.split($/)
30
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
31
21
  spec.require_paths = ['lib']
32
22
 
23
+ spec.add_dependency 'rails', '>= 3.0.3'
24
+
25
+ spec.signing_key = '/users/CarlosCD/.ssh/private_key.pem'
26
+ spec.cert_chain = ['/users/CarlosCD/.ssh/public_cert.pem']
27
+
28
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
33
29
  spec.add_development_dependency 'bundler', '~> 1.3'
34
30
  spec.add_development_dependency 'rake', '~> 10.0'
35
31
  if RUBY_ENGINE == 'jruby' && RUBY_PLATFORM == 'java'
@@ -1,20 +1,24 @@
1
- ##
2
- # This class is a Railtie which adds an initializer to Rails
3
- #
4
- # It reads the database configuration timeout, and if the adapter is PostgreSQL,
5
- # sets its value as the PostgreSQL statement_timeout.
1
+ module CantWait
6
2
 
7
- class CantWaitRailtie < Rails::Railtie
3
+ ##
4
+ # This class is a Railtie which adds an initializer to Rails
5
+ #
6
+ # It reads the database configuration timeout, and if the adapter is PostgreSQL,
7
+ # sets its value as the statement_timeout.
8
8
 
9
- initializer 'cant_wait.set_timeout' do
10
- begin
11
- database_config = Rails.configuration.database_configuration[Rails.env]
12
- if (database_config['adapter'].downcase == 'postgresql') && database_config['timeout']
13
- ActiveRecord::Base.connection.execute "set statement_timeout = #{database_config['timeout']}"
9
+ class CantWaitRailtie < Rails::Railtie
10
+
11
+ initializer 'cant_wait.set_timeout' do
12
+ begin
13
+ database_config = Rails.configuration.database_configuration[Rails.env]
14
+ if (database_config['adapter'].downcase == 'postgresql') && database_config['timeout']
15
+ ActiveRecord::Base.connection.execute "set statement_timeout = #{database_config['timeout']}"
16
+ end
17
+ rescue Exception => e
18
+ puts "\n#{e.message}\n\n"
14
19
  end
15
- rescue Exception => e
16
- puts "\n#{e.message}\n\n"
17
20
  end
21
+
18
22
  end
19
23
 
20
24
  end
@@ -1,3 +1,3 @@
1
1
  module CantWait
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -2,13 +2,13 @@
2
2
  #
3
3
  # rake gemspec_valid # Validate the gemspec
4
4
  #
5
- # rake build # Build cant_wait-0.0.1.gem into the pkg directory.
5
+ # rake build # Build cant_wait-X.Y.Z.gem into the pkg directory.
6
6
  # rake clean # Clean automatically generated gem files (removes the pkg folder).
7
7
  #
8
- # rake install # Build and install cant_wait-0.0.1.gem into system gems.
8
+ # rake install # Build and install cant_wait-X.Y.Z.gem into system gems.
9
9
  #
10
- # rake push # Push pkg/cant_wait-0.0.1.gem to rubygems, if it exists.
11
- # rake release # Create tag v0.0.1 and build and push cant_wait-0.0.1.gem to Rubygems
10
+ # rake push # Push pkg/cant_wait-X.Y.Z.gem to rubygems, if it exists.
11
+ # rake release # Create tag vX.Y.Z and build and push cant_wait-X.Y.Z.gem to Rubygems
12
12
 
13
13
  begin
14
14
  require 'bundler/gem_tasks' # Adds these tasks: build, install and release
data/tasks/testing.rake CHANGED
@@ -1,15 +1,34 @@
1
- # Testing:
1
+ # Testing tasks:
2
2
  #
3
3
  # rake test:bundle # Installs gems needed for the test apps (Bundle Install for each Rails app's Gemfile)
4
4
  # rake test:run # Tests the gem's behavior, using 5 test rails apps of different versions, and random timeouts
5
+ # rake test:all # Tests the gem's behavior, installing needed gems for the test apps first
5
6
 
6
7
  namespace :test do
7
8
 
8
- TEST_RAILS_APP = [{ version: '3.0.3', rails_root: 'test/test_apps/Test_3_0_3'},
9
+ TEST_RAILS_APP = [{ version: '3.0.3', rails_root: 'test/test_apps/Test_3_0_03'},
9
10
  { version: '3.0.20', rails_root: 'test/test_apps/Test_3_0_20'},
10
11
  { version: '3.1.12', rails_root: 'test/test_apps/Test_3_1_12'},
11
12
  { version: '3.2.13', rails_root: 'test/test_apps/Test_3_2_13'},
12
- { version: '4.0.0.rc1', rails_root: 'test/test_apps/Test_4_0_0_rc1'}]
13
+ { version: '4.0.0.rc2', rails_root: 'test/test_apps/Test_4_0_0_rc2'}]
14
+
15
+ # Argument (env.):
16
+ # REBUILD=f It doesn't remove the Gemfile.lock for the test apps, not forcing a clean bundle install
17
+ # Other possible values (meaning the same): f, false, n, no, off, nope
18
+ # Default: Rebuild all when no flag is present.
19
+ # (The opposite default as for test:bundle)
20
+ # Examples:
21
+ # $ rake test:all
22
+ # $ rake test:all REBUILD=no
23
+ desc "Tests the gem's behavior, installing needed gems for the test apps first"
24
+ task :all do
25
+ # Rebuild setting:
26
+ rebuild = !boolean_env_param('REBUILD', 'f', 'n', 'off', 'nope', 'no', 'false')
27
+ ENV['REBUILD'] = rebuild.to_s
28
+ puts 'Not rebuilding the Gemfile.lock for the test rails apps' unless rebuild
29
+ Rake::Task['test:bundle'].invoke
30
+ Rake::Task['test:run'].invoke
31
+ end
13
32
 
14
33
  # Argument (env.):
15
34
  # VERBOSE=t Gives more information about what's going on
@@ -27,6 +46,7 @@ namespace :test do
27
46
  puts "We'll run 5 times the test #1 (5 rails versions)"
28
47
  puts "Gem's ENV['BUNDLE_GEMFILE']='#{ENV['BUNDLE_GEMFILE']}'"
29
48
  end
49
+ all_passing = true # Used to signal to travis-ci a build failure
30
50
  can_wait_bundle_gemfile = ENV['BUNDLE_GEMFILE']
31
51
  5.times do |num|
32
52
  puts "====TESTING Rails version #{TEST_RAILS_APP[num][:version]}================="
@@ -34,7 +54,7 @@ namespace :test do
34
54
  puts 'At least Ruby 1.9.3 is required for rails 4 or above...'
35
55
  else
36
56
  # Uses Gemfile for the given version of rails
37
- gemfile_path = escape_filename_espaces TEST_RAILS_APP[num][:rails_root]
57
+ gemfile_path = escape_filename_spaces TEST_RAILS_APP[num][:rails_root]
38
58
  gemfile = gemfile_path<<'/Gemfile'
39
59
  ENV['BUNDLE_GEMFILE'] = gemfile
40
60
  if verbose
@@ -51,10 +71,11 @@ namespace :test do
51
71
  end
52
72
  # Run several timeouts test for that version of rails (bundle exec...)
53
73
  # Only the last argument (V) is optional here:
54
- system "bundle exec ruby test/cant_wait_test.rb #{num} #{@gem_spec.version} #{'V' if verbose}"
74
+ all_passing = false unless system "bundle exec ruby test/cant_wait_test.rb #{num} #{@gem_spec.version} #{'V' if verbose}"
55
75
  else
56
76
  puts ' bundle check and bundle failed! Check your rails test app Gemfile.'
57
- puts ' If there are missing gems, run rake test:bundle_apps'
77
+ puts ' If there are missing gems, run rake test:bundle'
78
+ all_passing = false
58
79
  end
59
80
  end
60
81
  end
@@ -64,13 +85,14 @@ namespace :test do
64
85
  puts "Finally set again the gem ENV['BUNDLE_GEMFILE'] as:"
65
86
  puts " '#{ENV['BUNDLE_GEMFILE']}'"
66
87
  end
88
+ exit(1) unless all_passing # non zero meand build failure
67
89
  end
68
90
 
69
91
  # Arguments (env.):
70
92
  # VERBOSE=t It gives more information about what's going on
71
93
  # REBUILD=t It removes the Gemfile.lock, so it forces a clean bundle install
72
94
  # Other possible values (meaning the same): t, true, y, yes, on, ok
73
- # Default: no verbose (no flags)
95
+ # Default: no verbose, and no rebuild (no flags)
74
96
  # Example:
75
97
  # $ rake test:bundle_apps REBUILD=y
76
98
  desc "Installs gems needed for the test apps (Bundle Install for each Rails app's Gemfile)"
@@ -98,9 +120,9 @@ namespace :test do
98
120
  puts " Present directory (pwd): #{FileUtils.pwd}"
99
121
  puts " Changing to the app root..."
100
122
  end
101
- FileUtils.cd escape_filename_espaces TEST_RAILS_APP[num][:rails_root]
123
+ FileUtils.cd escape_filename_spaces TEST_RAILS_APP[num][:rails_root]
102
124
  puts " Now present directory (pwd) is: #{FileUtils.pwd}" if verbose
103
- app_root = escape_filename_espaces FileUtils.pwd
125
+ app_root = escape_filename_spaces FileUtils.pwd
104
126
  puts " App Root: #{app_root}" if verbose
105
127
  # Rebuilding the Gemfile.lock installs missing gems
106
128
  if rebuild
@@ -127,7 +149,7 @@ namespace :test do
127
149
 
128
150
  private
129
151
 
130
- def escape_filename_espaces(filename)
152
+ def escape_filename_spaces(filename)
131
153
  filename.gsub(' ', '\ ')
132
154
  end
133
155
 
data/test/README.md CHANGED
@@ -1,8 +1,9 @@
1
- # cant_wait
2
- # Development and Test
1
+ # cant_wait ~ development and test
2
+ [![Gem Version](https://badge.fury.io/rb/cant_wait.png)](https://badge.fury.io/rb/cant_wait)
3
+ [![Build Status](https://api.travis-ci.org/CarlosCD/cant_wait.png)](https://travis-ci.org/CarlosCD/cant_wait)
3
4
 
4
5
 
5
- ## Test preferences and setup
6
+ ## Test setup and choices
6
7
 
7
8
  - Minitest, to keep things simple.
8
9
  - PostgreSQL database server (localhost or not).
@@ -11,13 +12,23 @@
11
12
 
12
13
  ## Test strategy: different Rails apps with random timeouts
13
14
 
14
- The approach of using minimal Rails components (ActiveRecord, Railties) is problematic due to the amount of code that Rails loads and of how it changes in the default behavior of Ruby. Running several Rails apps at the same time, and even if it is done in different threads, may result in:
15
+ ### The problem
16
+
17
+ The approach of using minimal Rails components (ActiveRecord, Railties) is problematic due to the amount of code that Rails loads and of how it changes in the default Ruby behavior. I opted here to test the same way an end user would use the gem.
18
+
19
+ To test in different Rails versions requires running several Rails apps simultaneous or sequentially. Even if it is done in different threads, may result in:
15
20
 
16
21
  RuntimeError: You cannot have more than one Rails::Application
17
22
 
18
- This approach also makes the test cases too distant to the real conditions you may encounter in isolated Rails applications. I finally choose to test several versions of Rails/ActiveRecord independently.
23
+ This approach also makes the test cases too distant to the real conditions you may encounter in isolated Rails applications.
24
+
25
+ ### A solution
26
+
27
+ I finally chose to test several versions of Rails/ActiveRecord independently.
19
28
 
20
- I created 5 simple Rails apps in the folder test/test_apps. Then I modified their Gemfile by adding gems for PostgreSQL, Minitest and Growl:
29
+ I created 5 simple Rails apps, of different versions, in the folder test/test_apps.
30
+
31
+ Then I modified their Gemfile by adding gems for PostgreSQL, Minitest and Growl:
21
32
 
22
33
  if RUBY_ENGINE == 'jruby' && RUBY_PLATFORM == 'java'
23
34
  gem 'activerecord-jdbc-adapter', '~> 1.2'
@@ -36,20 +47,22 @@ I created 5 simple Rails apps in the folder test/test_apps. Then I modified the
36
47
 
37
48
  gem 'cant_wait', path: File.expand_path('../../../..', __FILE__)
38
49
 
39
- The rails apps require bundle install, specially when changing the version of Ruby to be used. To make it easier, I added a rake task (rake test:bundle).
40
-
41
- The test is run through the rake test:run command. Due to the complex setup needed, I choose not to use the rake default to run the test.
50
+ The rails apps require bundle install, specially when changing the version of Ruby to be used. To make it easier, I added a rake task (<tt>rake test:bundle<tt />).
42
51
 
43
- The test (rake test:run) goes over each rails app in sequence and:
52
+ The test is run through the <tt>rake test:run command<tt />. The test goes over each rails app in sequence and:
44
53
 
45
54
  1. It sets Bundle to use the test app's Gemfile
46
- 2. It creates the app's config/database.yml with a random timeout
55
+ 2. It creates the app's <tt>config/database.yml<tt /> with a random timeout
47
56
  3. It starts Rails
48
57
  4. It checks the version of Rails and ActiveRecord running.
49
58
  5. It checks that the PostgreSQL connection's statement_timeout is the expected.
50
59
 
60
+ Due to the complex setup needed, I choose not to use the rake default to run the test, just to signal the tester to stop to consider these choices.
61
+
62
+ And additional <tt>rake test:all<tt /> will do both the bundle install and run the tests. This is the way travis-ci is set to run.
51
63
 
52
- ## The Testing process
64
+
65
+ ## The Testing process in detail
53
66
 
54
67
  After cloning the gem, you can start testing it by following these steps:
55
68
 
@@ -58,13 +71,13 @@ After cloning the gem, you can start testing it by following these steps:
58
71
 
59
72
  rvm use 1.9.3@mygemset
60
73
 
61
- 2. Optional: if you are using Mac OS, get Growl
74
+ 2. Optional: if you are using Mac OS X, get Growl
62
75
 
63
76
  3. Get the gem's dependencies:
64
77
 
65
78
  bundle
66
79
 
67
- 4. Set up your PostgreSQL test database and edit accordingly the file test/database.yml
80
+ 4. Set up your PostgreSQL test database and edit accordingly the file <tt>test/database.yml<tt />
68
81
 
69
82
  5. Get the Rails gems used by the test rails apps included:
70
83
 
@@ -76,15 +89,25 @@ After cloning the gem, you can start testing it by following these steps:
76
89
 
77
90
  If so wanted, run the tests several times. The tests use different random timeout scenarios, so each run may be a bit different.
78
91
 
92
+ ## Travis
93
+
94
+ I added travis-ci.org to check every build, as well as a badge to check the status last commit.
95
+
96
+ Check the .travis.yml file for details.
79
97
 
80
- ## Tested for
98
+
99
+ ## Tested with
81
100
 
82
101
  * Versions of Ruby:
83
102
 
84
- jruby 1.7.4
85
- 1.9.2-p320 (MRI's last patchlevel of 1.9.2)
86
- 1.9.3-p429 (MRI last patchlevel of 1.9.3)
87
- 2.0.0-p195 (MRI last patchlevel of 2.0.0)
103
+ 1.9.2-p320 (MRI's last patchlevel of 1.9.2) Linux and MacOS X
104
+ 1.9.3-p327 (MRI) Linux
105
+ 1.9.3-p429 (MRI last patchlevel of 1.9.3) MacOS X
106
+ 2.0.0-p0 (MRI) Linux
107
+ 2.0.0-p195 (MRI last patchlevel of 2.0.0) MacOS X
108
+ jruby 1.7.3 (java 1.7.0_15) Linux
109
+ jruby 1.7.4 (java 1.6.0_45) MacOS X
110
+ Rubinius 2.0.0 (1.9.3, 2013-06-12 JI) Linux
88
111
 
89
112
  * Versions of Rails:
90
113
 
@@ -92,7 +115,13 @@ If so wanted, run the tests several times. The tests use different random timeo
92
115
  Rails 3.0.20 Last patchlevel of Rails 3.0 (at this moment)
93
116
  Rails 3.1.12 Last patchlevel of Rails 3.1
94
117
  Rails 3.2.13 Last patchlevel of Rails 3.2 (many security fixes, last stable version)
95
- Rails 4.0.0.rc1 Last Release candidate for Rails 4, the most stable version at this point in time.
118
+ Rails 4.0.0.rc2 Last Release candidate for Rails 4, the most stable at this point in time.
119
+
120
+ **Note:** in the case of versions of Rails not final yet, <tt>rake test:bundle<tt /> may complain. In those cases you may need to manually install the gems before running the tests. For example:
121
+
122
+ $ gem install rails --version 4.0.0.rc2 --no-ri --no-rdoc
123
+ $ gem install sass-rails -v 4.0.0.rc2
124
+ ...
96
125
 
97
126
  * PostgreSQL versions 8.3.6 and 9.2.4.
98
127
 
@@ -6,11 +6,11 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) # We require the rails environment f
6
6
 
7
7
  class CantWait1Test < MiniTest::Unit::TestCase
8
8
 
9
- TEST_RAILS_APP = [{ version: '3.0.3', rails_root: 'test_apps/Test_3_0_3', },
9
+ TEST_RAILS_APP = [{ version: '3.0.3', rails_root: 'test_apps/Test_3_0_03', },
10
10
  { version: '3.0.20', rails_root: 'test_apps/Test_3_0_20', },
11
11
  { version: '3.1.12', rails_root: 'test_apps/Test_3_1_12', },
12
12
  { version: '3.2.13', rails_root: 'test_apps/Test_3_2_13' },
13
- { version: '4.0.0.rc1', rails_root: 'test_apps/Test_4_0_0_rc1' }]
13
+ { version: '4.0.0.rc2', rails_root: 'test_apps/Test_4_0_0_rc2' }]
14
14
 
15
15
  # Set a random timeout and rails app to be tested
16
16
  def setup
@@ -0,0 +1,12 @@
1
+ # Ignore bundler config
2
+ .bundle
3
+
4
+ # Ignore database.yml
5
+ config/database.yml
6
+
7
+ # Ignore the default SQLite database.
8
+ db/*.sqlite3
9
+
10
+ # Ignore all logfiles and tempfiles.
11
+ log/*.log
12
+ tmp/
@@ -2,9 +2,6 @@ source 'http://rubygems.org'
2
2
 
3
3
  gem 'rails', '3.0.3'
4
4
 
5
- # Bundle edge Rails instead:
6
- # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
-
8
5
  #-- Special additions-----------------
9
6
  # PostgreSQL as the database for ActiveRecord
10
7
  if RUBY_ENGINE == 'jruby' && RUBY_PLATFORM == 'java'
@@ -27,26 +24,3 @@ end
27
24
  # Gem cant_wait from sources, relative path:
28
25
  gem 'cant_wait', path: File.expand_path('../../../..', __FILE__)
29
26
  #-------------------------
30
-
31
- # Use unicorn as the web server
32
- # gem 'unicorn'
33
-
34
- # Deploy with Capistrano
35
- # gem 'capistrano'
36
-
37
- # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
38
- # gem 'ruby-debug'
39
- # gem 'ruby-debug19'
40
-
41
- # Bundle the extra gems:
42
- # gem 'bj'
43
- # gem 'nokogiri'
44
- # gem 'sqlite3-ruby', :require => 'sqlite3'
45
- # gem 'aws-s3', :require => 'aws/s3'
46
-
47
- # Bundle gems for the local environment. Make sure to
48
- # put test-only gems in this group so their generators
49
- # and rake tasks are available in development mode:
50
- # group :development, :test do
51
- # gem 'webrat'
52
- # end
@@ -1,4 +1,12 @@
1
+ # Ignore bundler config
1
2
  .bundle
3
+
4
+ # Ignore database.yml
5
+ config/database.yml
6
+
7
+ # Ignore the default SQLite database.
2
8
  db/*.sqlite3
9
+
10
+ # Ignore all logfiles and tempfiles.
3
11
  log/*.log
4
12
  tmp/
@@ -2,9 +2,6 @@ source 'http://rubygems.org'
2
2
 
3
3
  gem 'rails', '3.0.20'
4
4
 
5
- # Bundle edge Rails instead:
6
- # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
-
8
5
  #-- Special additions-----------------
9
6
  # PostgreSQL as the database for ActiveRecord
10
7
  if RUBY_ENGINE == 'jruby' && RUBY_PLATFORM == 'java'
@@ -27,26 +24,3 @@ end
27
24
  # Gem cant_wait from sources, relative path:
28
25
  gem 'cant_wait', path: File.expand_path('../../../..', __FILE__)
29
26
  #-------------------------
30
-
31
- # Use unicorn as the web server
32
- # gem 'unicorn'
33
-
34
- # Deploy with Capistrano
35
- # gem 'capistrano'
36
-
37
- # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
38
- # gem 'ruby-debug'
39
- # gem 'ruby-debug19', :require => 'ruby-debug'
40
-
41
- # Bundle the extra gems:
42
- # gem 'bj'
43
- # gem 'nokogiri'
44
- # gem 'sqlite3-ruby', :require => 'sqlite3'
45
- # gem 'aws-s3', :require => 'aws/s3'
46
-
47
- # Bundle gems for the local environment. Make sure to
48
- # put test-only gems in this group so their generators
49
- # and rake tasks are available in development mode:
50
- # group :development, :test do
51
- # gem 'webrat'
52
- # end
@@ -1,12 +1,9 @@
1
- # See http://help.github.com/ignore-files/ for more about ignoring files.
2
- #
3
- # If you find yourself ignoring temporary files generated by your text editor
4
- # or operating system, you probably want to add a global ignore instead:
5
- # git config --global core.excludesfile ~/.gitignore_global
6
-
7
1
  # Ignore bundler config
8
2
  /.bundle
9
3
 
4
+ # Ignore database.yml
5
+ config/database.yml
6
+
10
7
  # Ignore the default SQLite database.
11
8
  /db/*.sqlite3
12
9
 
@@ -2,8 +2,20 @@ source 'http://rubygems.org'
2
2
 
3
3
  gem 'rails', '3.1.12'
4
4
 
5
- # Bundle edge Rails instead:
6
- # gem 'rails', :git => 'git://github.com/rails/rails.git'
5
+ # Gems used only for assets and not required
6
+ # in production environments by default.
7
+ group :assets do
8
+ gem 'sass-rails', '~> 3.1.5'
9
+ gem 'coffee-rails', '~> 3.1.1'
10
+ gem 'uglifier', '>= 1.0.3'
11
+ end
12
+
13
+ gem 'jquery-rails'
14
+
15
+ group :test do
16
+ # Pretty printed test output
17
+ gem 'turn', '~> 0.8.3', :require => false
18
+ end
7
19
 
8
20
  #-- Special additions-----------------
9
21
  # PostgreSQL as the database for ActiveRecord
@@ -27,34 +39,3 @@ end
27
39
  # Gem cant_wait from sources, relative path:
28
40
  gem 'cant_wait', path: File.expand_path('../../../..', __FILE__)
29
41
  #-------------------------
30
-
31
- # Gems used only for assets and not required
32
- # in production environments by default.
33
- group :assets do
34
- gem 'sass-rails', '~> 3.1.5'
35
- gem 'coffee-rails', '~> 3.1.1'
36
-
37
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
38
- # gem 'therubyracer'
39
-
40
- gem 'uglifier', '>= 1.0.3'
41
- end
42
-
43
- gem 'jquery-rails'
44
-
45
- # To use ActiveModel has_secure_password
46
- # gem 'bcrypt-ruby', '~> 3.0.0'
47
-
48
- # Use unicorn as the web server
49
- # gem 'unicorn'
50
-
51
- # Deploy with Capistrano
52
- # gem 'capistrano'
53
-
54
- # To use debugger
55
- # gem 'ruby-debug19', :require => 'ruby-debug'
56
-
57
- group :test do
58
- # Pretty printed test output
59
- gem 'turn', '~> 0.8.3', :require => false
60
- end