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,79 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::Artifact::Files
4
+
5
+ class ArtDir
6
+ extend RailsAssist::UseMacro
7
+ use_helper :files
8
+ end
9
+
10
+ describe RailsAssist::Artifact::Files do
11
+ extend RailsAssist::UseMacro
12
+
13
+ use_helpers :directory
14
+
15
+ before do
16
+ RailsAssist::Directory.rails_root = fixtures_dir
17
+ @test = ArtDir.new
18
+ end
19
+
20
+ describe '#model_files' do
21
+ it "should return :model files" do
22
+ @test.model_files.file_names.should include 'user.rb'
23
+ end
24
+ end
25
+
26
+ describe '#mailer_files' do
27
+ it "should return :mailer files" do
28
+ @test.mailer_files.file_names.should include 'user_mailer.rb'
29
+ end
30
+ end
31
+
32
+ describe '#observer_files' do
33
+ it "should return :observer files" do
34
+ @test.observer_files.file_names.should include 'user_observer.rb'
35
+ end
36
+ end
37
+
38
+ describe '#permit_files' do
39
+ it "should return :permit files" do
40
+ @test.permit_files.file_names.should include 'user_permit.rb'
41
+ end
42
+ end
43
+
44
+ describe '#license_files' do
45
+ it "should return :license files" do
46
+ @test.license_files.file_names.should include 'blogging_license.rb'
47
+ end
48
+ end
49
+
50
+ describe '#validator_files' do
51
+ it "should return :validator files" do
52
+ @test.validator_files.file_names.should include 'email_validator.rb'
53
+ end
54
+ end
55
+
56
+ describe '#helper_files' do
57
+ it "should return :helper files" do
58
+ @test.helper_files.file_names.should include 'users_helper.rb'
59
+ end
60
+ end
61
+
62
+ describe '#controller_files' do
63
+ it "should return :controller files" do
64
+ @test.controller_files.file_names.should include 'users_controller.rb'
65
+ end
66
+ end
67
+
68
+ describe '#view_files' do
69
+ it "should return :view files" do
70
+ @test.view_files(:user).file_names.should include 'show.html.erb'
71
+ end
72
+ end
73
+
74
+ describe '#erb_view_files' do
75
+ it "should return erb :view files" do
76
+ @test.erb_view_files(:user).file_names.should include 'show.html.erb'
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::Artifact::Path
4
+
5
+ class ArtDir
6
+ include CLASS
7
+ end
8
+
9
+ describe RailsAssist::Artifact::Path do
10
+ # use_helper :directories
11
+
12
+ before do
13
+ RailsAssist::Directory.rails_root = fixtures_dir
14
+ @test = ArtDir.new
15
+ end
16
+
17
+ describe '#artifact_path' do
18
+ it "should return mailer directory name" do
19
+ @test.artifact_path(:my_mailer, :mailer)
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::Artifact
4
+
5
+ class ArtDir
6
+ include CLASS
7
+ end
8
+
9
+ describe RailsAssist::Artifact do
10
+ # use_helper :directories
11
+
12
+ before do
13
+ RailsAssist::Directory.rails_root = File.dirname (__FILE__)
14
+ @test = ArtDir.new
15
+ end
16
+
17
+ describe '#self.rails_artifacts' do
18
+ it "should return mailer directory name" do
19
+ CLASS.rails_artifacts.should include :mailer, :model
20
+ end
21
+ end
22
+
23
+ describe '#valid_artifact?' do
24
+ it "should be true that :model is a valid artifact" do
25
+ CLASS.valid_artifact?(:model).should be_true
26
+ end
27
+
28
+ it "should be false that :unknown is a valid artifact" do
29
+ CLASS.valid_artifact?(:unknown).should be_false
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::Directory::App
4
+
5
+ class AppDir
6
+ include CLASS
7
+ end
8
+
9
+ def rails_root
10
+ RailsAssist::Directory.rails_root
11
+ end
12
+
13
+ describe RailsAssist::Directory::App do
14
+ # use_helper :directories
15
+
16
+ before do
17
+ RailsAssist::Directory.rails_root = fixtures_dir
18
+ end
19
+
20
+ describe '#self.app_directories' do
21
+ it "should return symbols list of Rails 3 app directories" do
22
+ CLASS.app_directories.should include :controllers, :mailers, :helpers, :views, :models, :permits
23
+ end
24
+ end
25
+
26
+ describe '#app_directories' do
27
+ it "should return symbols list of Rails 3 app directories" do
28
+ AppDir.new.app_directories.should include :controllers, :mailers, :helpers, :views, :models, :permits
29
+ end
30
+ end
31
+
32
+
33
+ describe '#self.app_dir' do
34
+ it "should the current Rails 3 ap dir when Rails root is set" do
35
+ CLASS.app_dir.path.should == File.join(rails_root, 'app')
36
+ end
37
+ end
38
+
39
+ describe '#app_dir' do
40
+ it "should the current Rails 3 ap dir when Rails root is set" do
41
+ AppDir.new.app_dir.path.should == File.join(rails_root, 'app')
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::Directory::Container
4
+
5
+ class Con
6
+ include RailsAssist::Directory
7
+ end
8
+
9
+ class ConExt
10
+ extend RailsAssist::Directory::Container
11
+ end
12
+
13
+
14
+ describe RailsAssist::Directory::Container do
15
+ # use_helper :directories
16
+
17
+ context "using module methods directly" do
18
+ describe '#rails_containers' do
19
+ it "should return symbols list of rails 3 artifact containers" do
20
+ CLASS.rails_containers.should include :controller, :mailer, :helper, :view, :model, :permit
21
+ end
22
+ end
23
+
24
+ describe '#valid_container?' do
25
+ it "should return true that since controller is a valid container" do
26
+ CLASS.valid_container?(:controller).should be_true
27
+ end
28
+
29
+ it "should return since :unknown is NOT a valid container" do
30
+ CLASS.valid_container?(:unknown).should be_false
31
+ end
32
+ end
33
+ end
34
+
35
+ context "module included into class" do
36
+ describe '#rails_containers' do
37
+ it "should return symbols list of rails 3 artifact containers" do
38
+ Con.new.rails_containers.should include :controller, :mailer, :helper, :view, :model, :permit
39
+ end
40
+ end
41
+
42
+ describe '#valid_container?' do
43
+ it "should return true that since controller is a valid container" do
44
+ Con.new.valid_container?(:controller).should be_true
45
+ end
46
+ end
47
+ end
48
+
49
+ context "module extended into class" do
50
+ describe '#rails_containers' do
51
+ it "should return symbols list of rails 3 artifact containers" do
52
+ ConExt.rails_containers.should include :controller, :mailer, :helper, :view, :model, :permit
53
+ end
54
+ end
55
+
56
+ describe '#valid_container?' do
57
+ it "should return true that since controller is a valid container" do
58
+ ConExt.valid_container?(:controller).should be_true
59
+ end
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::Directory::Root
4
+
5
+ class RootDir
6
+ include CLASS
7
+ end
8
+
9
+ def rails_root
10
+ RailsAssist::Directory.rails_root
11
+ end
12
+
13
+
14
+ describe RailsAssist::Directory::Root do
15
+ # use_helper :directories
16
+
17
+ before do
18
+ RailsAssist::Directory.rails_root = fixtures_dir
19
+ end
20
+
21
+ describe '#self.root_directories' do
22
+ it "should return symbols list of Rails 3 root directories" do
23
+ CLASS.root_directories.should include :app, :config, :db
24
+ end
25
+ end
26
+
27
+ describe '#root_directories' do
28
+ it "should return symbols list of Rails 3 root directories" do
29
+ RootDir.new.root_directories.should include :app, :config, :db
30
+ end
31
+ end
32
+
33
+
34
+ describe '#self.root_dir' do
35
+ it "should the current Rails 3 ap dir when Rails root is set" do
36
+ CLASS.root_dir.path.should == rails_root
37
+ end
38
+ end
39
+
40
+ describe '#root_dir' do
41
+ it "should the current Rails 3 ap dir when Rails root is set" do
42
+ RootDir.new.root_dir.path.should == rails_root
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::Directory
4
+
5
+ class RailsDir
6
+ extend RailsAssist::UseMacro
7
+ use_helper :directory
8
+ end
9
+
10
+ def rails_root
11
+ RailsAssist::Directory.rails_root
12
+ end
13
+
14
+ describe RailsAssist::Directory do
15
+ # use_helper :directories
16
+
17
+ before do
18
+ RailsAssist::Directory.rails_root = fixtures_dir
19
+ @test = RailsDir.new
20
+ end
21
+
22
+ RailsAssist::Directory::Root.root_directories.each do |name|
23
+ eval %{
24
+ describe '##{name}_dir' do
25
+ it "should return #{name} directory name" do
26
+ CLASS.#{name}_dir.path.should match /\/\#{name}/
27
+ CLASS.#{name}_dir.path.should match Regexp.escape(RailsAssist::Directory.rails_root)
28
+ @test.#{name}_dir.path.should match /\/\#{name}/
29
+ end
30
+ end
31
+ }
32
+ end
33
+
34
+ describe '#rails_dir_for' do
35
+ it "should return mailer directory name" do
36
+ @test.rails_dir_for(:mailer).path.should == File.join(rails_root, 'app', 'mailers')
37
+ end
38
+ end
39
+
40
+ describe '#rails_dir_for' do
41
+ it "should return app directory name" do
42
+ @test.rails_dir_for(:app).path.should == File.join(rails_root, 'app')
43
+ end
44
+ end
45
+
46
+ describe '#config_dir_for' do
47
+ it "should return initializers directory name" do
48
+ @test.config_dir_for(:initializer).path.should == File.join(rails_root, 'config', 'initializers')
49
+ end
50
+ end
51
+
52
+ describe '#self.config_dir_for' do
53
+ it "should return initializers directory name" do
54
+ CLASS.config_dir_for(:initializer).path.should == File.join(rails_root, 'config', 'initializers')
55
+ end
56
+ end
57
+
58
+ describe '#public_dir_for' do
59
+ it "should return javascripts directory name" do
60
+ @test.public_dir_for(:javascript).path.should == File.join(rails_root, 'public', 'javascripts')
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::File::Special
4
+
5
+ class AppDir
6
+ include CLASS
7
+ end
8
+
9
+ describe RailsAssist::File::Application do
10
+ # use_helper :directories
11
+
12
+ before do
13
+ RailsAssist::Directory.rails_root = fixtures_dir
14
+ end
15
+
16
+ before :each do
17
+ file_name = CLASS.application_filepath
18
+ FileUtils.cp file_name, file_name + '.bak'
19
+ end
20
+
21
+ after :each do
22
+ file_name = CLASS.application_filepath
23
+ FileUtils.mv file_name + '.bak', file_name
24
+ end
25
+
26
+ describe '#insert_application_config' do
27
+ it "should return the #{name} file path" do
28
+ CLASS.insert_application_config 'hello = 2'
29
+ content = CLASS.read_application_file
30
+ content.should match /Rails::Application\n\s+config\.hello = 2/
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ CLASS = RailsAssist::File::Special
4
+
5
+ class AppDir
6
+ include CLASS
7
+ end
8
+
9
+ describe RailsAssist::File::Environment do
10
+ # use_helper :directories
11
+
12
+ before do
13
+ RailsAssist::Directory.rails_root = fixtures_dir
14
+ end
15
+
16
+ before :each do
17
+ file_name = CLASS.environment_filepath
18
+ FileUtils.cp file_name, file_name + '.bak'
19
+ end
20
+
21
+ after :each do
22
+ file_name = CLASS.environment_filepath
23
+ FileUtils.mv file_name + '.bak', file_name
24
+ end
25
+
26
+ describe '#insert_before_application_init' do
27
+ it "should add code or content BEFORE the application is initialized" do
28
+ CLASS.insert_before_application_init 'config.hello = 2'
29
+ content = CLASS.read_environment_file
30
+ content.should match /config\.hello = 2\n(.*)::Application.initialize!/
31
+ end
32
+ end
33
+
34
+ describe '#insert_after_application_init' do
35
+ it "should add code or content AFTER the application is initialized" do
36
+ CLASS.insert_after_application_init 'config.hello = 2'
37
+ content = CLASS.read_environment_file
38
+ content.should match /::Application.initialize!\n(.*)config\.hello = 2/
39
+ end
40
+ end
41
+
42
+ describe '#insert_application_init' do
43
+ it "should add code or content AFTER the application is initialized" do
44
+ CLASS.insert_application_init :after, 'config.hello = 2'
45
+ content = CLASS.read_environment_file
46
+ content.should match /::Application.initialize!\n(.*)config\.hello = 2/
47
+ end
48
+ end
49
+ end