rails_assist 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +17 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.markdown +204 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/lib/rails_assist.rb +43 -0
  10. data/lib/rails_assist/app.rb +13 -0
  11. data/lib/rails_assist/artifact.rb +34 -0
  12. data/lib/rails_assist/artifact/directory.rb +66 -0
  13. data/lib/rails_assist/artifact/files.rb +95 -0
  14. data/lib/rails_assist/artifact/path.rb +16 -0
  15. data/lib/rails_assist/directory.rb +64 -0
  16. data/lib/rails_assist/directory/app.rb +21 -0
  17. data/lib/rails_assist/directory/container.rb +24 -0
  18. data/lib/rails_assist/directory/root.rb +24 -0
  19. data/lib/rails_assist/file.rb +91 -0
  20. data/lib/rails_assist/file/application.rb +15 -0
  21. data/lib/rails_assist/file/environment.rb +16 -0
  22. data/lib/rails_assist/file/gem_file.rb +32 -0
  23. data/lib/rails_assist/file/routes_file.rb +13 -0
  24. data/lib/rails_assist/file/special.rb +78 -0
  25. data/lib/rails_assist/files.rb +153 -0
  26. data/lib/rails_assist/macro.rb +68 -0
  27. data/lib/rails_assist/namespaces.rb +11 -0
  28. data/lib/rails_assist/rspec.rb +1 -0
  29. data/lib/rails_assist/rspec/configure.rb +7 -0
  30. data/rails_assist.gemspec +221 -0
  31. data/sandbox/test.rb +16 -0
  32. data/sandbox/test.txt +5 -0
  33. data/spec/fixtures.rb +3 -0
  34. data/spec/fixtures/.gitignore +4 -0
  35. data/spec/fixtures/Gemfile +9 -0
  36. data/spec/fixtures/README +256 -0
  37. data/spec/fixtures/Rakefile +7 -0
  38. data/spec/fixtures/app/controllers/application_controller.rb +3 -0
  39. data/spec/fixtures/app/controllers/users_controller.rb +83 -0
  40. data/spec/fixtures/app/helpers/application_helper.rb +2 -0
  41. data/spec/fixtures/app/helpers/users_helper.rb +2 -0
  42. data/spec/fixtures/app/licenses/blogging_license.rb +0 -0
  43. data/spec/fixtures/app/mailers/user_mailer.rb +0 -0
  44. data/spec/fixtures/app/models/user.rb +2 -0
  45. data/spec/fixtures/app/models/user_observer.rb +0 -0
  46. data/spec/fixtures/app/permits/user_permit.rb +0 -0
  47. data/spec/fixtures/app/validators/email_validator.rb +0 -0
  48. data/spec/fixtures/app/views/layouts/application.html.erb +14 -0
  49. data/spec/fixtures/app/views/users/_form.html.erb +21 -0
  50. data/spec/fixtures/app/views/users/edit.html.erb +6 -0
  51. data/spec/fixtures/app/views/users/index.html.erb +23 -0
  52. data/spec/fixtures/app/views/users/new.html.erb +5 -0
  53. data/spec/fixtures/app/views/users/show.html.erb +10 -0
  54. data/spec/fixtures/config.ru +4 -0
  55. data/spec/fixtures/config/application.rb +43 -0
  56. data/spec/fixtures/config/boot.rb +13 -0
  57. data/spec/fixtures/config/database.yml +22 -0
  58. data/spec/fixtures/config/environment.rb +5 -0
  59. data/spec/fixtures/config/environments/development.rb +26 -0
  60. data/spec/fixtures/config/environments/production.rb +49 -0
  61. data/spec/fixtures/config/environments/test.rb +35 -0
  62. data/spec/fixtures/config/initializers/backtrace_silencers.rb +7 -0
  63. data/spec/fixtures/config/initializers/inflections.rb +10 -0
  64. data/spec/fixtures/config/initializers/mime_types.rb +5 -0
  65. data/spec/fixtures/config/initializers/my_init.rb +0 -0
  66. data/spec/fixtures/config/initializers/secret_token.rb +7 -0
  67. data/spec/fixtures/config/initializers/session_store.rb +8 -0
  68. data/spec/fixtures/config/locales/en.yml +5 -0
  69. data/spec/fixtures/config/routes.rb +60 -0
  70. data/spec/fixtures/db/migrate/20100831135208_create_users.rb +13 -0
  71. data/spec/fixtures/db/seeds.rb +7 -0
  72. data/spec/fixtures/lib/tasks/.gitkeep +0 -0
  73. data/spec/fixtures/public/404.html +26 -0
  74. data/spec/fixtures/public/422.html +26 -0
  75. data/spec/fixtures/public/500.html +26 -0
  76. data/spec/fixtures/public/favicon.ico +0 -0
  77. data/spec/fixtures/public/images/rails.png +0 -0
  78. data/spec/fixtures/public/index.html +239 -0
  79. data/spec/fixtures/public/javascripts/application.js +2 -0
  80. data/spec/fixtures/public/javascripts/controls.js +965 -0
  81. data/spec/fixtures/public/javascripts/dragdrop.js +974 -0
  82. data/spec/fixtures/public/javascripts/effects.js +1 -0
  83. data/spec/fixtures/public/javascripts/prototype.js +6001 -0
  84. data/spec/fixtures/public/javascripts/rails.js +175 -0
  85. data/spec/fixtures/public/robots.txt +5 -0
  86. data/spec/fixtures/public/stylesheets/.gitkeep +0 -0
  87. data/spec/fixtures/public/stylesheets/scaffold.css +56 -0
  88. data/spec/fixtures/script/rails +6 -0
  89. data/spec/fixtures/test/fixtures/users.yml +7 -0
  90. data/spec/fixtures/test/functional/users_controller_test.rb +49 -0
  91. data/spec/fixtures/test/performance/browsing_test.rb +9 -0
  92. data/spec/fixtures/test/test_helper.rb +13 -0
  93. data/spec/fixtures/test/unit/helpers/users_helper_test.rb +4 -0
  94. data/spec/fixtures/test/unit/user_test.rb +8 -0
  95. data/spec/fixtures/vendor/plugins/.gitkeep +0 -0
  96. data/spec/load_spec.rb +1 -0
  97. data/spec/rails_assist/app_spec.rb +31 -0
  98. data/spec/rails_assist/artifact/directory_spec.rb +66 -0
  99. data/spec/rails_assist/artifact/files_spec.rb +79 -0
  100. data/spec/rails_assist/artifact/path_spec.rb +23 -0
  101. data/spec/rails_assist/artifact_spec.rb +33 -0
  102. data/spec/rails_assist/directory/app_spec.rb +45 -0
  103. data/spec/rails_assist/directory/container_spec.rb +63 -0
  104. data/spec/rails_assist/directory/root_spec.rb +46 -0
  105. data/spec/rails_assist/directory_spec.rb +64 -0
  106. data/spec/rails_assist/file/application_spec.rb +33 -0
  107. data/spec/rails_assist/file/environment_spec.rb +49 -0
  108. data/spec/rails_assist/file/special_spec.rb +171 -0
  109. data/spec/rails_assist/file_spec.rb +115 -0
  110. data/spec/rails_assist/files_spec.rb +90 -0
  111. data/spec/rails_assist/rspec/have_app_config_spec.rb +0 -0
  112. data/spec/rails_assist_spec.rb +7 -0
  113. data/spec/spec_helper.rb +53 -0
  114. metadata +291 -0
@@ -0,0 +1,175 @@
1
+ (function() {
2
+ // Technique from Juriy Zaytsev
3
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
+ function isEventSupported(eventName) {
5
+ var el = document.createElement('div');
6
+ eventName = 'on' + eventName;
7
+ var isSupported = (eventName in el);
8
+ if (!isSupported) {
9
+ el.setAttribute(eventName, 'return;');
10
+ isSupported = typeof el[eventName] == 'function';
11
+ }
12
+ el = null;
13
+ return isSupported;
14
+ }
15
+
16
+ function isForm(element) {
17
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
+ }
19
+
20
+ function isInput(element) {
21
+ if (Object.isElement(element)) {
22
+ var name = element.nodeName.toUpperCase()
23
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
+ }
25
+ else return false
26
+ }
27
+
28
+ var submitBubbles = isEventSupported('submit'),
29
+ changeBubbles = isEventSupported('change')
30
+
31
+ if (!submitBubbles || !changeBubbles) {
32
+ // augment the Event.Handler class to observe custom events when needed
33
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
+ function(init, element, eventName, selector, callback) {
35
+ init(element, eventName, selector, callback)
36
+ // is the handler being attached to an element that doesn't support this event?
37
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
+ // "submit" => "emulated:submit"
40
+ this.eventName = 'emulated:' + this.eventName
41
+ }
42
+ }
43
+ )
44
+ }
45
+
46
+ if (!submitBubbles) {
47
+ // discover forms on the page by observing focus events which always bubble
48
+ document.on('focusin', 'form', function(focusEvent, form) {
49
+ // special handler for the real "submit" event (one-time operation)
50
+ if (!form.retrieve('emulated:submit')) {
51
+ form.on('submit', function(submitEvent) {
52
+ var emulated = form.fire('emulated:submit', submitEvent, true)
53
+ // if custom event received preventDefault, cancel the real one too
54
+ if (emulated.returnValue === false) submitEvent.preventDefault()
55
+ })
56
+ form.store('emulated:submit', true)
57
+ }
58
+ })
59
+ }
60
+
61
+ if (!changeBubbles) {
62
+ // discover form inputs on the page
63
+ document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
+ // special handler for real "change" events
65
+ if (!input.retrieve('emulated:change')) {
66
+ input.on('change', function(changeEvent) {
67
+ input.fire('emulated:change', changeEvent, true)
68
+ })
69
+ input.store('emulated:change', true)
70
+ }
71
+ })
72
+ }
73
+
74
+ function handleRemote(element) {
75
+ var method, url, params;
76
+
77
+ var event = element.fire("ajax:before");
78
+ if (event.stopped) return false;
79
+
80
+ if (element.tagName.toLowerCase() === 'form') {
81
+ method = element.readAttribute('method') || 'post';
82
+ url = element.readAttribute('action');
83
+ params = element.serialize();
84
+ } else {
85
+ method = element.readAttribute('data-method') || 'get';
86
+ url = element.readAttribute('href');
87
+ params = {};
88
+ }
89
+
90
+ new Ajax.Request(url, {
91
+ method: method,
92
+ parameters: params,
93
+ evalScripts: true,
94
+
95
+ onComplete: function(request) { element.fire("ajax:complete", request); },
96
+ onSuccess: function(request) { element.fire("ajax:success", request); },
97
+ onFailure: function(request) { element.fire("ajax:failure", request); }
98
+ });
99
+
100
+ element.fire("ajax:after");
101
+ }
102
+
103
+ function handleMethod(element) {
104
+ var method = element.readAttribute('data-method'),
105
+ url = element.readAttribute('href'),
106
+ csrf_param = $$('meta[name=csrf-param]')[0],
107
+ csrf_token = $$('meta[name=csrf-token]')[0];
108
+
109
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
+ element.parentNode.insert(form);
111
+
112
+ if (method !== 'post') {
113
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
+ form.insert(field);
115
+ }
116
+
117
+ if (csrf_param) {
118
+ var param = csrf_param.readAttribute('content'),
119
+ token = csrf_token.readAttribute('content'),
120
+ field = new Element('input', { type: 'hidden', name: param, value: token });
121
+ form.insert(field);
122
+ }
123
+
124
+ form.submit();
125
+ }
126
+
127
+
128
+ document.on("click", "*[data-confirm]", function(event, element) {
129
+ var message = element.readAttribute('data-confirm');
130
+ if (!confirm(message)) event.stop();
131
+ });
132
+
133
+ document.on("click", "a[data-remote]", function(event, element) {
134
+ if (event.stopped) return;
135
+ handleRemote(element);
136
+ event.stop();
137
+ });
138
+
139
+ document.on("click", "a[data-method]", function(event, element) {
140
+ if (event.stopped) return;
141
+ handleMethod(element);
142
+ event.stop();
143
+ });
144
+
145
+ document.on("submit", function(event) {
146
+ var element = event.findElement(),
147
+ message = element.readAttribute('data-confirm');
148
+ if (message && !confirm(message)) {
149
+ event.stop();
150
+ return false;
151
+ }
152
+
153
+ var inputs = element.select("input[type=submit][data-disable-with]");
154
+ inputs.each(function(input) {
155
+ input.disabled = true;
156
+ input.writeAttribute('data-original-value', input.value);
157
+ input.value = input.readAttribute('data-disable-with');
158
+ });
159
+
160
+ var element = event.findElement("form[data-remote]");
161
+ if (element) {
162
+ handleRemote(element);
163
+ event.stop();
164
+ }
165
+ });
166
+
167
+ document.on("ajax:after", "form", function(event, element) {
168
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
+ inputs.each(function(input) {
170
+ input.value = input.readAttribute('data-original-value');
171
+ input.removeAttribute('data-original-value');
172
+ input.disabled = false;
173
+ });
174
+ });
175
+ })();
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
File without changes
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ name: MyString
5
+
6
+ two:
7
+ name: MyString
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ class UsersControllerTest < ActionController::TestCase
4
+ setup do
5
+ @user = users(:one)
6
+ end
7
+
8
+ test "should get index" do
9
+ get :index
10
+ assert_response :success
11
+ assert_not_nil assigns(:users)
12
+ end
13
+
14
+ test "should get new" do
15
+ get :new
16
+ assert_response :success
17
+ end
18
+
19
+ test "should create user" do
20
+ assert_difference('User.count') do
21
+ post :create, :user => @user.attributes
22
+ end
23
+
24
+ assert_redirected_to user_path(assigns(:user))
25
+ end
26
+
27
+ test "should show user" do
28
+ get :show, :id => @user.to_param
29
+ assert_response :success
30
+ end
31
+
32
+ test "should get edit" do
33
+ get :edit, :id => @user.to_param
34
+ assert_response :success
35
+ end
36
+
37
+ test "should update user" do
38
+ put :update, :id => @user.to_param, :user => @user.attributes
39
+ assert_redirected_to user_path(assigns(:user))
40
+ end
41
+
42
+ test "should destroy user" do
43
+ assert_difference('User.count', -1) do
44
+ delete :destroy, :id => @user.to_param
45
+ end
46
+
47
+ assert_redirected_to users_path
48
+ end
49
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'rails/performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionDispatch::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
+ #
8
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
+ # -- they do not yet inherit this setting
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class UsersHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class UserTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
File without changes
data/spec/load_spec.rb ADDED
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::App
4
+
5
+ class Helper
6
+ include RailsAssist::App
7
+ include RailsAssist::Directory
8
+ include RailsAssist::Artifact
9
+ end
10
+
11
+ describe 'controller' do
12
+ before do
13
+ RailsAssist::Directory.rails_root = fixtures_dir
14
+ @helper = Helper.new
15
+ end
16
+
17
+ after do
18
+ remove_temp_dir 'tmp_rails'
19
+ end
20
+
21
+ it "should create basic root directories" do
22
+ CLASS.create_empty_tmp @helper.root_directories
23
+ @helper.root_dir.path.should have_dirs(@helper.root_directories)
24
+ end
25
+
26
+ # TODO: have_dirs should also work on Directory object!
27
+ it "should have basic app directories" do
28
+ @helper.create_empty_tmp @helper.app_artifacts
29
+ @helper.app_dir.path.should have_dirs(@helper.app_directories)
30
+ end
31
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::Artifact::Directory
4
+
5
+ class ArtDir
6
+ include CLASS
7
+ end
8
+
9
+ describe RailsAssist::Artifact::Directory do
10
+ # use_helper :directories
11
+
12
+ before do
13
+ RailsAssist::Directory.rails_root = fixtures_dir
14
+ @test = ArtDir.new
15
+ end
16
+
17
+ RailsAssist::Artifact.app_artifacts.each do |name|
18
+ eval %{
19
+ describe '##{name}_dir' do
20
+ it "should return #{name} directory name" do
21
+ CLASS.#{name}_dir.path.should match /app\/\#{name}/
22
+ @test.#{name}_dir.path.should match /app\/\#{name}/
23
+ end
24
+ end
25
+ }
26
+ end
27
+
28
+ describe '#observer_dir' do
29
+ it "should return observer directory name" do
30
+ CLASS.observer_dir.path.should match /app\/models/
31
+ @test.observer_dirpath.should match /app\/models/
32
+ end
33
+ end
34
+
35
+ describe '#migration_dir' do
36
+ it "should return migration directory name" do
37
+ CLASS.migration_dir.path.should match /db\/migrate/
38
+ @test.migration_dirpath.should match /db\/migrate/
39
+ end
40
+ end
41
+
42
+
43
+
44
+ [:initializer, :locale].each do |name|
45
+ eval %{
46
+ describe '##{name}_dir' do
47
+ it "should return #{name} directory name" do
48
+ CLASS.#{name}_dir.path.should match /config\/\#{name}/
49
+ @test.#{name}_dirpath.should match /config\/\#{name}/
50
+ end
51
+ end
52
+ }
53
+ end
54
+
55
+ [:stylesheet, :javascript].each do |name|
56
+ eval %{
57
+ describe '##{name}_dir' do
58
+ it "should return #{name} directory name" do
59
+ CLASS.#{name}_dir.path.should match /public\/\#{name}/
60
+ @test.#{name}_dirpath.should match /public\/\#{name}/
61
+ end
62
+ end
63
+ }
64
+ end
65
+
66
+ end