rails-caddy 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +69 -0
  3. data/VERSION.yml +4 -0
  4. data/lib/rails-caddy.rb +43 -0
  5. data/lib/rails-caddy/controllers/rails_caddy_controller.rb +17 -0
  6. data/lib/rails-caddy/controllers/sanitize_email_controller.rb +42 -0
  7. data/lib/rails-caddy/controllers/session_editing_controller.rb +21 -0
  8. data/lib/rails-caddy/controllers/timecop_controller.rb +56 -0
  9. data/lib/rails-caddy/errors.rb +8 -0
  10. data/lib/rails-caddy/helpers/rails_caddy_helper.rb +33 -0
  11. data/lib/rails-caddy/session_controller_finder.rb +17 -0
  12. data/lib/rails-caddy/views/_rails_caddy.html.erb +57 -0
  13. data/lib/rails-caddy/views/_rails_caddy_css.html.erb +60 -0
  14. data/lib/rails-caddy/views/_rails_caddy_js.html.erb +88 -0
  15. data/test/README.txt +40 -0
  16. data/test/files/acet.rb +40 -0
  17. data/test/files/fct.rb +35 -0
  18. data/test/files/rcct.rb +13 -0
  19. data/test/files/sanitize_email_action_controller_extensions_test_methods.rb +71 -0
  20. data/test/files/sanitize_email_controller_test_methods.rb +31 -0
  21. data/test/files/session_editing_controller_test_methods.rb +41 -0
  22. data/test/files/timecop_action_controller_extensions_test_methods.rb +55 -0
  23. data/test/files/timecop_controller_test_methods.rb +30 -0
  24. data/test/geminstaller.yml +5 -0
  25. data/test/rails_caddy_controller_test.rb +43 -0
  26. data/test/rails_caddy_helper_test.rb +24 -0
  27. data/test/rails_caddy_test.rb +39 -0
  28. data/test/rails_modifier.rb +131 -0
  29. data/test/routes.rb +3 -0
  30. data/test/session_controller_finder_test.rb +57 -0
  31. data/test/test_helper.rb +12 -0
  32. metadata +110 -0
@@ -0,0 +1,5 @@
1
+ gems:
2
+ - name: Shoulda
3
+ version: '~> 1.2.0'
4
+ - name: rr
5
+ version: '~> 0.8.1'
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+ require 'timecop'
3
+ require 'files/session_editing_controller_test_methods'
4
+ require 'files/timecop_controller_test_methods'
5
+ require 'files/sanitize_email_controller_test_methods'
6
+
7
+ # We need ActionPack loaded to test this out
8
+ require 'actionpack'
9
+ require 'action_controller'
10
+
11
+ # Fake an ApplicationController
12
+ class ApplicationController < ActionController::Base
13
+ session_options[:key] = "blah"
14
+ end
15
+
16
+ # Define RailsCaddyController
17
+ RailsCaddy.init!
18
+ require 'routes'
19
+
20
+ class RailsCaddyControllerTest < ActionController::TestCase
21
+ tests RailsCaddyController
22
+
23
+ context "RailsCaddy has been initialized" do
24
+
25
+ should "include TimecopController" do
26
+ assert RailsCaddyController.included_modules.include?(TimecopController)
27
+ end
28
+
29
+ should "include SessionEditingController" do
30
+ assert RailsCaddyController.included_modules.include?(SessionEditingController)
31
+ end
32
+
33
+ should "include SanitizeEmailController" do
34
+ assert RailsCaddyController.included_modules.include?(SanitizeEmailController)
35
+ end
36
+
37
+ include SessionEditingControllerTestMethods
38
+ include TimecopControllerTestMethods
39
+ include SanitizeEmailControllerTestMethods
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ # We need ActionPack loaded to test this out
4
+ require 'activesupport'
5
+ require 'actionpack'
6
+ require 'action_controller'
7
+ require 'action_view/test_case'
8
+
9
+ # Fake an ApplicationController
10
+ class ApplicationController < ActionController::Base
11
+ session_options[:key] = "blah"
12
+ end
13
+
14
+ # Define RailsCaddyController
15
+ RailsCaddy.init!
16
+
17
+ class RailsCaddyHelperTest < ActionView::TestCase
18
+ def test_rc_in_place_editor_field
19
+ html = rc_in_place_editor_field("user_id", 1)
20
+ assert_match /rails_caddy_user_id_in_place_editor/, html
21
+ # very hacky, but I'm just trying to verify that the value 1 was placed inside the span tag (of the in place edit)
22
+ assert_match />1<\/span>/, html
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ # We need ActionPack loaded to test this out
4
+ require 'actionpack'
5
+ require 'action_controller'
6
+
7
+ require 'rails-caddy'
8
+
9
+ class ApplicationController < ActionController::Base
10
+ session_options[:key] = "abc"
11
+ end
12
+
13
+ class RailsCaddyTest < Test::Unit::TestCase
14
+
15
+ context "RailsCaddy has been initialized" do
16
+ setup do
17
+ RailsCaddy.init!
18
+ end
19
+
20
+ should "add TimecopController::ActionControllerExtensions to ActionController::Base" do
21
+ assert ActionController::Base.included_modules.include?(TimecopController::ActionControllerExtensions)
22
+ end
23
+
24
+ should "add SanitizeEmailController::ActionControllerExtensions to ActionController::Base" do
25
+ assert ActionController::Base.included_modules.include?(SanitizeEmailController::ActionControllerExtensions)
26
+ end
27
+
28
+ should "load RailsCaddyController" do
29
+ assert Object.const_defined?(:RailsCaddyController)
30
+ end
31
+
32
+ should "add rails-caddy/views to the view_path" do
33
+ path = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "rails-caddy", "views"))
34
+ assert ActionController::Base.view_paths.include?(path)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,131 @@
1
+ require 'fileutils'
2
+
3
+ class RailsModifier
4
+
5
+ class << self
6
+ def modify!(version)
7
+ `ruby script/generate controller frogs index`
8
+ `rake db:migrate`
9
+ # prepend these actions before the def index that is generated...
10
+ prepend(frog_actions, "def index", 'app/controllers/frogs_controller.rb')
11
+ write('app/views/frogs/index.html.erb', frogs_index_html_erb)
12
+ prepend(application_rb, "end", application_controller(version))
13
+ replace("config.time_zone = 'UTC'", "", "config/environment.rb")
14
+ append(config_rb(version), nil, "config/environments/test.rb")
15
+ append(config_rb(version), nil, "config/environments/development.rb")
16
+ append(routes_rb, "ActionController::Routing::Routes.draw do |map|", "config/routes.rb")
17
+ remove('public/index.html')
18
+
19
+ # Copy over tests
20
+ %w(session_editing_controller timecop_controller timecop_action_controller_extensions sanitize_email_controller sanitize_email_action_controller_extensions).each do |file_prefix|
21
+ FileUtils::cp(file_path("#{file_prefix}_test_methods.rb"), File.join("test", "#{file_prefix}_test_methods.rb"))
22
+ end
23
+ FileUtils::cp(file_path("rcct.rb"), File.join("test", "functional", "rails_caddy_controller_test.rb"))
24
+ FileUtils::cp(file_path("fct.rb"), File.join("test", "functional", "frogs_controller_test.rb"))
25
+ FileUtils::cp(file_path("acet.rb"), File.join("test", "functional", "action_controller_extensions_test.rb"))
26
+ end
27
+
28
+ private
29
+ def prepend(content, before_string, filename)
30
+ file_contents = File.readlines(filename).join
31
+ write(filename, file_contents.gsub(before_string, content + "\n" + before_string))
32
+ end
33
+
34
+ def append(content, after_string, filename)
35
+ file_contents = File.readlines(filename).join
36
+ new_contents = if after_string.nil?
37
+ file_contents + "\n" + content
38
+ else
39
+ file_contents.gsub(after_string, after_string + "\n" + content)
40
+ end
41
+ write(filename, new_contents)
42
+ end
43
+
44
+ def replace(original_content, new_content, filename)
45
+ file_contents = File.readlines(filename).join
46
+ write(filename, file_contents.gsub(original_content, new_content))
47
+ end
48
+
49
+ def write(filename, content)
50
+ File.open(filename, 'w') do |f|
51
+ f.write(content)
52
+ end
53
+ end
54
+
55
+ def remove(filename)
56
+ FileUtils.rm(filename, :force => true)
57
+ end
58
+
59
+ def file_path(filename)
60
+ File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "files", filename))
61
+ end
62
+
63
+ def frog_actions
64
+ <<-RUBY
65
+ %w(abc def ghi).each do |action|
66
+ define_method(action) do
67
+ session[:something] = action
68
+ render :action => 'index'
69
+ end
70
+ end
71
+
72
+ RUBY
73
+ end
74
+
75
+ def frogs_index_html_erb
76
+ <<-ERB
77
+ <html>
78
+ <head>
79
+ <title>Test</title>
80
+ <%= javascript_include_tag :all %>
81
+ </head>
82
+ <body>
83
+ <h2>Some Debugging Output</h2>
84
+ <p>Time.now = <%= Time.now.to_s(:db) %></p>
85
+ <p>ActionMailer::Base.sanitized_recipients = <%= ActionMailer::Base.sanitized_recipients.to_s %></p>
86
+ <%= rails_caddy if Object.const_defined?(:RailsCaddy) %>
87
+ </body>
88
+ </html>
89
+ ERB
90
+ end
91
+
92
+ def application_rb_require(version)
93
+ version == "2.3.2" ? "application_controller" : "application"
94
+ end
95
+
96
+ def application_controller(version)
97
+ "app/controllers/#{application_rb_require(version)}.rb"
98
+ end
99
+
100
+ def application_rb
101
+ <<-RUBY
102
+ if Object.const_defined?(:RailsCaddy)
103
+ helper RailsCaddyHelper
104
+ around_filter :handle_sanitize_email
105
+ around_filter :handle_timecop_offset, :except => [:timecop_update, :timecop_reset]
106
+ end
107
+ layout nil
108
+ RUBY
109
+ end
110
+
111
+ def config_rb(version)
112
+ <<-RUBY
113
+ config.gem 'rails-caddy'
114
+
115
+ config.after_initialize do
116
+ require 'rails-caddy'
117
+ require_dependency '#{application_rb_require(version)}'
118
+ RailsCaddy.init!
119
+ end
120
+ RUBY
121
+ end
122
+
123
+ def routes_rb
124
+ <<-RUBY
125
+ RailsCaddy.define_routes!(map) if Object.const_defined?(:RailsCaddy)
126
+ #map.resources :frogs, :only => [:index], :member => [:abc, :def, :ghi]
127
+ map.root :controller => "frogs"
128
+ RUBY
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,3 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ RailsCaddy.define_routes!(map)
3
+ end
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ # We need ActionPack loaded to test this out
4
+ require 'actionpack'
5
+ require 'action_controller'
6
+
7
+ require 'rails-caddy/session_controller_finder'
8
+
9
+ class SessionControllerFinderTest < Test::Unit::TestCase
10
+
11
+ context "ApplicationController has yet to be defined" do
12
+
13
+ setup do
14
+ Object.send(:remove_const, :ApplicationController) if Object.const_defined?(:ApplicationController)
15
+ end
16
+
17
+ should "raise NameError when accessing ApplicationController" do
18
+ assert_raise(NameError) { ApplicationController }
19
+ end
20
+
21
+ should "raise RailsCaddy::SessionControllerNotFoundError when searching" do
22
+ assert_raise(RailsCaddy::SessionControllerNotFoundError) { SessionControllerFinder.find }
23
+ end
24
+
25
+ context "ApplicationController has been defined" do
26
+
27
+ setup do
28
+ class ::ApplicationController < ActionController::Base
29
+ session_options[:key] = nil
30
+ end
31
+ end
32
+
33
+ # context "session has not been initialized, but the key is nil" do
34
+ # setup do
35
+ # ::ApplicationController.session_options[:key] = nil
36
+ # end
37
+ #
38
+ # should "raise SessionUninitializedError when calling #find" do
39
+ # assert_raise(RailsCaddy::SessionUninitializedError) { SessionControllerFinder.find }
40
+ # end
41
+ # end
42
+
43
+ context "session has been initialized, and a key set" do
44
+ setup do
45
+ ::ApplicationController.session_options[:key] = "blah"
46
+ end
47
+
48
+ should "not return ApplicationController when calling #find" do
49
+ assert_equal ::ApplicationController, SessionControllerFinder.find
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'rr'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'rails-caddy'
9
+
10
+ class Test::Unit::TestCase
11
+ include RR::Adapters::TestUnit unless include?(RR::Adapters::TestUnit)
12
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-caddy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - John Trupiano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-19 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: timecop
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: sanitize_email
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ version:
35
+ description:
36
+ email: jtrupiano@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ - LICENSE
44
+ files:
45
+ - README.rdoc
46
+ - VERSION.yml
47
+ - lib/rails-caddy
48
+ - lib/rails-caddy/controllers
49
+ - lib/rails-caddy/controllers/rails_caddy_controller.rb
50
+ - lib/rails-caddy/controllers/sanitize_email_controller.rb
51
+ - lib/rails-caddy/controllers/session_editing_controller.rb
52
+ - lib/rails-caddy/controllers/timecop_controller.rb
53
+ - lib/rails-caddy/errors.rb
54
+ - lib/rails-caddy/helpers
55
+ - lib/rails-caddy/helpers/rails_caddy_helper.rb
56
+ - lib/rails-caddy/session_controller_finder.rb
57
+ - lib/rails-caddy/views
58
+ - lib/rails-caddy/views/_rails_caddy.html.erb
59
+ - lib/rails-caddy/views/_rails_caddy_css.html.erb
60
+ - lib/rails-caddy/views/_rails_caddy_js.html.erb
61
+ - lib/rails-caddy.rb
62
+ - test/files
63
+ - test/files/acet.rb
64
+ - test/files/fct.rb
65
+ - test/files/rcct.rb
66
+ - test/files/sanitize_email_action_controller_extensions_test_methods.rb
67
+ - test/files/sanitize_email_controller_test_methods.rb
68
+ - test/files/session_editing_controller_test_methods.rb
69
+ - test/files/timecop_action_controller_extensions_test_methods.rb
70
+ - test/files/timecop_controller_test_methods.rb
71
+ - test/geminstaller.yml
72
+ - test/rails
73
+ - test/rails_caddy_controller_test.rb
74
+ - test/rails_caddy_helper_test.rb
75
+ - test/rails_caddy_test.rb
76
+ - test/rails_modifier.rb
77
+ - test/README.txt
78
+ - test/routes.rb
79
+ - test/session_controller_finder_test.rb
80
+ - test/test_helper.rb
81
+ - LICENSE
82
+ has_rdoc: true
83
+ homepage: http://github.com/jtrupiano/rails-caddy
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --inline-source
87
+ - --charset=UTF-8
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ requirements: []
103
+
104
+ rubyforge_project: johntrupiano
105
+ rubygems_version: 1.3.1
106
+ signing_key:
107
+ specification_version: 2
108
+ summary: A developer's QA "caddy" that aids in QA'ing, debugging, and otherwise navigating your application during development and/or QA.
109
+ test_files: []
110
+