focus-generator 0.0.1
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/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.rdoc +109 -0
- data/Rakefile +10 -0
- data/features/fcus_authentication.feature +80 -0
- data/features/fcus_config.feature +17 -0
- data/features/fcus_layout.feature +20 -0
- data/features/fcus_scaffold.feature +80 -0
- data/features/step_definitions/common_steps.rb +62 -0
- data/features/step_definitions/rails_setup_steps.rb +6 -0
- data/features/support/env.rb +6 -0
- data/features/support/matchers.rb +7 -0
- data/lib/generators/fcus.rb +28 -0
- data/lib/generators/fcus/authentication/USAGE +50 -0
- data/lib/generators/fcus/authentication/authentication_generator.rb +154 -0
- data/lib/generators/fcus/authentication/templates/authlogic_session.rb +2 -0
- data/lib/generators/fcus/authentication/templates/controller_authentication.rb +60 -0
- data/lib/generators/fcus/authentication/templates/fixtures.yml +24 -0
- data/lib/generators/fcus/authentication/templates/migration.rb +20 -0
- data/lib/generators/fcus/authentication/templates/sessions_controller.rb +41 -0
- data/lib/generators/fcus/authentication/templates/sessions_helper.rb +2 -0
- data/lib/generators/fcus/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
- data/lib/generators/fcus/authentication/templates/tests/rspec/user.rb +83 -0
- data/lib/generators/fcus/authentication/templates/tests/rspec/users_controller.rb +56 -0
- data/lib/generators/fcus/authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
- data/lib/generators/fcus/authentication/templates/tests/shoulda/user.rb +85 -0
- data/lib/generators/fcus/authentication/templates/tests/shoulda/users_controller.rb +61 -0
- data/lib/generators/fcus/authentication/templates/tests/testunit/sessions_controller.rb +36 -0
- data/lib/generators/fcus/authentication/templates/tests/testunit/user.rb +88 -0
- data/lib/generators/fcus/authentication/templates/tests/testunit/users_controller.rb +53 -0
- data/lib/generators/fcus/authentication/templates/user.rb +38 -0
- data/lib/generators/fcus/authentication/templates/users_controller.rb +32 -0
- data/lib/generators/fcus/authentication/templates/users_helper.rb +2 -0
- data/lib/generators/fcus/authentication/templates/views/erb/_form.html.erb +20 -0
- data/lib/generators/fcus/authentication/templates/views/erb/edit.html.erb +3 -0
- data/lib/generators/fcus/authentication/templates/views/erb/login.html.erb +30 -0
- data/lib/generators/fcus/authentication/templates/views/erb/signup.html.erb +5 -0
- data/lib/generators/fcus/authentication/templates/views/haml/_form.html.haml +16 -0
- data/lib/generators/fcus/authentication/templates/views/haml/edit.html.haml +3 -0
- data/lib/generators/fcus/authentication/templates/views/haml/login.html.haml +26 -0
- data/lib/generators/fcus/authentication/templates/views/haml/signup.html.haml +5 -0
- data/lib/generators/fcus/config/USAGE +23 -0
- data/lib/generators/fcus/config/config_generator.rb +24 -0
- data/lib/generators/fcus/config/templates/config.yml +8 -0
- data/lib/generators/fcus/config/templates/load_config.rb +2 -0
- data/lib/generators/fcus/layout/USAGE +25 -0
- data/lib/generators/fcus/layout/layout_generator.rb +29 -0
- data/lib/generators/fcus/layout/templates/error_messages_helper.rb +23 -0
- data/lib/generators/fcus/layout/templates/layout.html.erb +19 -0
- data/lib/generators/fcus/layout/templates/layout.html.haml +21 -0
- data/lib/generators/fcus/layout/templates/layout_helper.rb +22 -0
- data/lib/generators/fcus/layout/templates/stylesheet.css +83 -0
- data/lib/generators/fcus/layout/templates/stylesheet.sass +73 -0
- data/lib/generators/fcus/scaffold/USAGE +51 -0
- data/lib/generators/fcus/scaffold/scaffold_generator.rb +318 -0
- data/lib/generators/fcus/scaffold/templates/actions/create.rb +8 -0
- data/lib/generators/fcus/scaffold/templates/actions/destroy.rb +5 -0
- data/lib/generators/fcus/scaffold/templates/actions/edit.rb +3 -0
- data/lib/generators/fcus/scaffold/templates/actions/index.rb +3 -0
- data/lib/generators/fcus/scaffold/templates/actions/new.rb +3 -0
- data/lib/generators/fcus/scaffold/templates/actions/show.rb +3 -0
- data/lib/generators/fcus/scaffold/templates/actions/update.rb +8 -0
- data/lib/generators/fcus/scaffold/templates/controller.rb +3 -0
- data/lib/generators/fcus/scaffold/templates/fixtures.yml +9 -0
- data/lib/generators/fcus/scaffold/templates/helper.rb +2 -0
- data/lib/generators/fcus/scaffold/templates/migration.rb +16 -0
- data/lib/generators/fcus/scaffold/templates/model.rb +4 -0
- data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/fcus/scaffold/templates/tests/rspec/controller.rb +8 -0
- data/lib/generators/fcus/scaffold/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/fcus/scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/fcus/scaffold/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/fcus/scaffold/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/fcus/scaffold/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/fcus/scaffold/templates/views/erb/_form.html.erb +10 -0
- data/lib/generators/fcus/scaffold/templates/views/erb/edit.html.erb +14 -0
- data/lib/generators/fcus/scaffold/templates/views/erb/index.html.erb +29 -0
- data/lib/generators/fcus/scaffold/templates/views/erb/new.html.erb +7 -0
- data/lib/generators/fcus/scaffold/templates/views/erb/show.html.erb +20 -0
- data/lib/generators/fcus/scaffold/templates/views/haml/_form.html.haml +9 -0
- data/lib/generators/fcus/scaffold/templates/views/haml/edit.html.haml +14 -0
- data/lib/generators/fcus/scaffold/templates/views/haml/index.html.haml +25 -0
- data/lib/generators/fcus/scaffold/templates/views/haml/new.html.haml +7 -0
- data/lib/generators/fcus/scaffold/templates/views/haml/show.html.haml +20 -0
- data/rails_generators/fcus_authentication/USAGE +50 -0
- data/rails_generators/fcus_authentication/fcus_authentication_generator.rb +128 -0
- data/rails_generators/fcus_authentication/lib/insert_commands.rb +74 -0
- data/rails_generators/fcus_authentication/templates/authentication.rb +61 -0
- data/rails_generators/fcus_authentication/templates/authlogic_session.rb +2 -0
- data/rails_generators/fcus_authentication/templates/fixtures.yml +24 -0
- data/rails_generators/fcus_authentication/templates/migration.rb +20 -0
- data/rails_generators/fcus_authentication/templates/sessions_controller.rb +45 -0
- data/rails_generators/fcus_authentication/templates/sessions_helper.rb +2 -0
- data/rails_generators/fcus_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
- data/rails_generators/fcus_authentication/templates/tests/rspec/user.rb +83 -0
- data/rails_generators/fcus_authentication/templates/tests/rspec/users_controller.rb +26 -0
- data/rails_generators/fcus_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
- data/rails_generators/fcus_authentication/templates/tests/shoulda/user.rb +85 -0
- data/rails_generators/fcus_authentication/templates/tests/shoulda/users_controller.rb +27 -0
- data/rails_generators/fcus_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
- data/rails_generators/fcus_authentication/templates/tests/testunit/user.rb +88 -0
- data/rails_generators/fcus_authentication/templates/tests/testunit/users_controller.rb +23 -0
- data/rails_generators/fcus_authentication/templates/user.rb +42 -0
- data/rails_generators/fcus_authentication/templates/users_controller.rb +18 -0
- data/rails_generators/fcus_authentication/templates/users_helper.rb +2 -0
- data/rails_generators/fcus_authentication/templates/views/erb/login.html.erb +30 -0
- data/rails_generators/fcus_authentication/templates/views/erb/signup.html.erb +24 -0
- data/rails_generators/fcus_authentication/templates/views/haml/login.html.haml +30 -0
- data/rails_generators/fcus_authentication/templates/views/haml/signup.html.haml +24 -0
- data/rails_generators/fcus_config/USAGE +23 -0
- data/rails_generators/fcus_config/fcus_config_generator.rb +32 -0
- data/rails_generators/fcus_config/templates/config.yml +8 -0
- data/rails_generators/fcus_config/templates/load_config.rb +2 -0
- data/rails_generators/fcus_layout/USAGE +25 -0
- data/rails_generators/fcus_layout/fcus_layout_generator.rb +44 -0
- data/rails_generators/fcus_layout/templates/helper.rb +22 -0
- data/rails_generators/fcus_layout/templates/layout.html.erb +22 -0
- data/rails_generators/fcus_layout/templates/layout.html.haml +19 -0
- data/rails_generators/fcus_layout/templates/stylesheet.css +81 -0
- data/rails_generators/fcus_layout/templates/stylesheet.sass +67 -0
- data/rails_generators/fcus_scaffold/USAGE +51 -0
- data/rails_generators/fcus_scaffold/fcus_scaffold_generator.rb +232 -0
- data/rails_generators/fcus_scaffold/templates/actions/create.rb +9 -0
- data/rails_generators/fcus_scaffold/templates/actions/destroy.rb +6 -0
- data/rails_generators/fcus_scaffold/templates/actions/edit.rb +3 -0
- data/rails_generators/fcus_scaffold/templates/actions/index.rb +3 -0
- data/rails_generators/fcus_scaffold/templates/actions/new.rb +3 -0
- data/rails_generators/fcus_scaffold/templates/actions/show.rb +3 -0
- data/rails_generators/fcus_scaffold/templates/actions/update.rb +9 -0
- data/rails_generators/fcus_scaffold/templates/controller.rb +3 -0
- data/rails_generators/fcus_scaffold/templates/fixtures.yml +9 -0
- data/rails_generators/fcus_scaffold/templates/helper.rb +2 -0
- data/rails_generators/fcus_scaffold/templates/migration.rb +16 -0
- data/rails_generators/fcus_scaffold/templates/model.rb +3 -0
- data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/rails_generators/fcus_scaffold/templates/tests/rspec/controller.rb +8 -0
- data/rails_generators/fcus_scaffold/templates/tests/rspec/model.rb +7 -0
- data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/rails_generators/fcus_scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/rails_generators/fcus_scaffold/templates/tests/shoulda/model.rb +7 -0
- data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/rails_generators/fcus_scaffold/templates/tests/testunit/controller.rb +5 -0
- data/rails_generators/fcus_scaffold/templates/tests/testunit/model.rb +7 -0
- data/rails_generators/fcus_scaffold/templates/views/erb/_form.html.erb +10 -0
- data/rails_generators/fcus_scaffold/templates/views/erb/edit.html.erb +14 -0
- data/rails_generators/fcus_scaffold/templates/views/erb/index.html.erb +29 -0
- data/rails_generators/fcus_scaffold/templates/views/erb/new.html.erb +7 -0
- data/rails_generators/fcus_scaffold/templates/views/erb/show.html.erb +20 -0
- data/rails_generators/fcus_scaffold/templates/views/haml/_form.html.haml +10 -0
- data/rails_generators/fcus_scaffold/templates/views/haml/edit.html.haml +14 -0
- data/rails_generators/fcus_scaffold/templates/views/haml/index.html.haml +25 -0
- data/rails_generators/fcus_scaffold/templates/views/haml/new.html.haml +7 -0
- data/rails_generators/fcus_scaffold/templates/views/haml/show.html.haml +20 -0
- data/test/test_fcus_authentication_generator.rb +274 -0
- data/test/test_fcus_config_generator.rb +37 -0
- data/test/test_fcus_layout_generator.rb +42 -0
- data/test/test_fcus_scaffold_generator.rb +534 -0
- data/test/test_helper.rb +119 -0
- metadata +314 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Ryan Bates
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
= Fcus Generators
|
|
2
|
+
|
|
3
|
+
A collection of useful Rails generator scripts for scaffolding, layout files, authentication, and more.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
== Setup
|
|
7
|
+
|
|
8
|
+
=== Rails 3
|
|
9
|
+
|
|
10
|
+
Add the gem to your Gemfile.
|
|
11
|
+
|
|
12
|
+
gem "focus-generator", :group => :development
|
|
13
|
+
|
|
14
|
+
Then you can run any of the included generators.
|
|
15
|
+
|
|
16
|
+
rails g fcus:scaffold Recipe name:string index new
|
|
17
|
+
|
|
18
|
+
=== Rails 2
|
|
19
|
+
|
|
20
|
+
First install the gem.
|
|
21
|
+
|
|
22
|
+
gem install focus-generator
|
|
23
|
+
|
|
24
|
+
The generators will be available in all Rails applications. To run the generator, go to your rails project directory and call it using the script/generate or script/destroy command.
|
|
25
|
+
|
|
26
|
+
script/generate fcus_scaffold Recipe name:string index new
|
|
27
|
+
|
|
28
|
+
Note an underscore is used instead of a colon for the Rails 2 generators.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
== Included Generators
|
|
32
|
+
|
|
33
|
+
* fcus:layout: generates generic layout, stylesheet, and helper files.
|
|
34
|
+
* fcus:scaffold: generates a controller and optional model/migration.
|
|
35
|
+
* fcus:config: generates a config YAML file and loader.
|
|
36
|
+
* fcus:authentication: generates user model with sign up and log in.
|
|
37
|
+
|
|
38
|
+
To view the README for each generator, run it with the +help+ option.
|
|
39
|
+
|
|
40
|
+
rails g fcus:layout --help
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
== Troubleshooting and FAQs
|
|
44
|
+
|
|
45
|
+
<b>What is the difference between fcus:scaffold and built-in scaffold?</b>
|
|
46
|
+
|
|
47
|
+
One of the primary differences is that fcus:scaffold allows you to choose which controller actions to generate.
|
|
48
|
+
|
|
49
|
+
rails g fcus:scaffold post name:string index new edit
|
|
50
|
+
|
|
51
|
+
There are a few changes to the generated code as well, such as no XML format by default.
|
|
52
|
+
|
|
53
|
+
It also offers support for HAML, Shoulda, and RSpec.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
<b>I get "undefined method 'title'" error.</b>
|
|
57
|
+
|
|
58
|
+
Try running fcus:layout, that will generate this helper method. Or you can just change the templates to whatever approach you prefer for setting the title.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
<b>I can't set new attributes in my model.</b>
|
|
62
|
+
|
|
63
|
+
Add the attribute to the attr_accessible line in the model.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
<b>I get "undefined method 'root_url'" error.</b>
|
|
67
|
+
|
|
68
|
+
Some generators default redirecting to the root_url. Set this in your routes.rb file like this (substituting your controller name).
|
|
69
|
+
|
|
70
|
+
root :to => "home#index"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
<b>I get a missing database error.</b>
|
|
74
|
+
|
|
75
|
+
Run <tt>rake db:migrate</tt>.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
<b>I get a routing error when I try to submit a form.</b>
|
|
79
|
+
|
|
80
|
+
Try restarting your development server. Sometimes it doesn't detect the change in the routing.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
<b>The tests/specs don't work.</b>
|
|
84
|
+
|
|
85
|
+
Make sure you have mocha installed and require it in your spec/test helper.
|
|
86
|
+
|
|
87
|
+
gem install mocha
|
|
88
|
+
|
|
89
|
+
# in spec_helper.rb
|
|
90
|
+
config.mock_with :mocha
|
|
91
|
+
|
|
92
|
+
# in test_helper.rb
|
|
93
|
+
require 'mocha'
|
|
94
|
+
|
|
95
|
+
Also, make sure you're using Rails 2.1 or greater.
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
== Found a bug?
|
|
99
|
+
|
|
100
|
+
If you are having a problem with Fcus Generators, first look at the FAQs above. If you still cannot resolve it, please submit an issue here.
|
|
101
|
+
|
|
102
|
+
http://github.com/lihaoalbert/focus-generator/issues
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
== Development
|
|
106
|
+
|
|
107
|
+
If you want to contribute to this project, you can download the Git repository and get the Cucumber features running by calling +bundle+ then +rake+. I normally develop this using Ruby 1.9.2 however it should work with 1.8.7 as well.
|
|
108
|
+
|
|
109
|
+
The Rails 3 generators are located under <tt>lib/generators</tt> and are tested with Cucumber. The older Rails 2 generators are under <tt>rails_generators</tt> and are tested with Shoulda under the <tt>test</tt> directory.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Feature: Fcus Authentication Generator
|
|
2
|
+
In order to authenticate users
|
|
3
|
+
As a rails developer
|
|
4
|
+
I want to generate some user authentication
|
|
5
|
+
|
|
6
|
+
Scenario: Generate default authentication
|
|
7
|
+
Given a new Rails app
|
|
8
|
+
When I insert "root :to => 'users#new'" into "config/routes.rb" after line 1
|
|
9
|
+
And I run "rails g fcus:authentication"
|
|
10
|
+
Then I should see the following files
|
|
11
|
+
| app/models/user.rb |
|
|
12
|
+
| app/controllers/users_controller.rb |
|
|
13
|
+
| app/helpers/users_helper.rb |
|
|
14
|
+
| app/views/users/new.html.erb |
|
|
15
|
+
| app/views/users/edit.html.erb |
|
|
16
|
+
| app/controllers/sessions_controller.rb |
|
|
17
|
+
| app/helpers/sessions_helper.rb |
|
|
18
|
+
| app/views/sessions/new.html.erb |
|
|
19
|
+
| lib/controller_authentication.rb |
|
|
20
|
+
| test/fixtures/users.yml |
|
|
21
|
+
| test/unit/user_test.rb |
|
|
22
|
+
| test/functional/users_controller_test.rb |
|
|
23
|
+
| test/functional/sessions_controller_test.rb |
|
|
24
|
+
| db/migrate |
|
|
25
|
+
And I should see the following in file "config/routes.rb"
|
|
26
|
+
| resources :sessions |
|
|
27
|
+
| resources :users |
|
|
28
|
+
| match 'login' => 'sessions#new', :as => :login |
|
|
29
|
+
| match 'logout' => 'sessions#destroy', :as => :logout |
|
|
30
|
+
| match 'signup' => 'users#new', :as => :signup |
|
|
31
|
+
| match 'user/edit' => 'users#edit', :as => :edit_current_user |
|
|
32
|
+
And I should see "include ControllerAuthentication" in file "app/controllers/application_controller.rb"
|
|
33
|
+
And I should see "gem "mocha", :group => :test" in file "Gemfile"
|
|
34
|
+
And I should see "gem "bcrypt-ruby", :require => "bcrypt"" in file "Gemfile"
|
|
35
|
+
When I run "rails g fcus:layout -f"
|
|
36
|
+
And I run "rake db:migrate"
|
|
37
|
+
Then I should successfully run "rake test"
|
|
38
|
+
|
|
39
|
+
Scenario: Generate named authentication
|
|
40
|
+
Given a new Rails app
|
|
41
|
+
When I insert "root :to => 'accounts#new'" into "config/routes.rb" after line 1
|
|
42
|
+
And I run "rails g fcus:authentication Account CurrentSession"
|
|
43
|
+
Then I should see the following files
|
|
44
|
+
| app/models/account.rb |
|
|
45
|
+
| app/controllers/accounts_controller.rb |
|
|
46
|
+
| app/helpers/accounts_helper.rb |
|
|
47
|
+
| app/views/accounts/new.html.erb |
|
|
48
|
+
| app/views/accounts/edit.html.erb |
|
|
49
|
+
| app/controllers/current_sessions_controller.rb |
|
|
50
|
+
| app/helpers/current_sessions_helper.rb |
|
|
51
|
+
| app/views/current_sessions/new.html.erb |
|
|
52
|
+
| test/fixtures/accounts.yml |
|
|
53
|
+
| test/unit/account_test.rb |
|
|
54
|
+
| test/functional/accounts_controller_test.rb |
|
|
55
|
+
| test/functional/current_sessions_controller_test.rb |
|
|
56
|
+
And I should see the following in file "config/routes.rb"
|
|
57
|
+
| resources :current_sessions |
|
|
58
|
+
| resources :accounts |
|
|
59
|
+
| match 'login' => 'current_sessions#new', :as => :login |
|
|
60
|
+
| match 'logout' => 'current_sessions#destroy', :as => :logout |
|
|
61
|
+
| match 'signup' => 'accounts#new', :as => :signup |
|
|
62
|
+
| match 'account/edit' => 'accounts#edit', :as => :edit_current_account |
|
|
63
|
+
When I run "rails g fcus:layout -f"
|
|
64
|
+
And I run "rake db:migrate"
|
|
65
|
+
Then I should successfully run "rake test"
|
|
66
|
+
|
|
67
|
+
Scenario: Generate named authentication with rspec
|
|
68
|
+
Given a new Rails app
|
|
69
|
+
When I insert "root :to => 'accounts#new'" into "config/routes.rb" after line 1
|
|
70
|
+
And I run "rails g fcus:authentication Account CurrentSession --rspec"
|
|
71
|
+
Then I should see the following files
|
|
72
|
+
| spec/models/account_spec.rb |
|
|
73
|
+
| spec/controllers/accounts_controller_spec.rb |
|
|
74
|
+
| spec/controllers/current_sessions_controller_spec.rb |
|
|
75
|
+
When I run "rails g fcus:layout -f"
|
|
76
|
+
And I run "rake db:migrate"
|
|
77
|
+
And I add "gem 'rspec-rails', '>= 2.0.1'" to file "Gemfile"
|
|
78
|
+
And I run "rails g rspec:install"
|
|
79
|
+
And I replace "mock_with :rspec" with "mock_with :mocha" in file "spec/spec_helper.rb"
|
|
80
|
+
Then I should successfully run "rake spec"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Feature: Fcus Config Generator
|
|
2
|
+
In order to have configure an app
|
|
3
|
+
As a rails developer
|
|
4
|
+
I want to generate a config file and manager
|
|
5
|
+
|
|
6
|
+
Scenario: Generate normal config
|
|
7
|
+
Given a new Rails app
|
|
8
|
+
When I run "rails g fcus:config"
|
|
9
|
+
Then I should see file "config/app_config.yml"
|
|
10
|
+
And I should see file "config/initializers/load_app_config.rb"
|
|
11
|
+
|
|
12
|
+
Scenario: Generate named config
|
|
13
|
+
Given a new Rails app
|
|
14
|
+
When I run "rails g fcus:config FooBar"
|
|
15
|
+
Then I should see "FOO_BAR_CONFIG" in file "config/initializers/load_foo_bar_config.rb"
|
|
16
|
+
And I should see "config/foo_bar_config.yml" in file "config/initializers/load_foo_bar_config.rb"
|
|
17
|
+
And I should see file "config/foo_bar_config.yml"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Feature: Fcus Layout Generator
|
|
2
|
+
In order to have a layout
|
|
3
|
+
As a rails developer
|
|
4
|
+
I want to generate a simple layout
|
|
5
|
+
|
|
6
|
+
Scenario: Generate normal application layout
|
|
7
|
+
Given a new Rails app
|
|
8
|
+
When I run "rails g fcus:layout -f"
|
|
9
|
+
Then I should see "stylesheet_link_tag "application"" in file "app/views/layouts/application.html.erb"
|
|
10
|
+
Then I should see "h(page_title" in file "app/helpers/layout_helper.rb"
|
|
11
|
+
And I should see file "app/helpers/layout_helper.rb"
|
|
12
|
+
And I should see file "app/helpers/error_messages_helper.rb"
|
|
13
|
+
And I should see file "public/stylesheets/application.css"
|
|
14
|
+
|
|
15
|
+
Scenario: Generate named layout with haml and sass
|
|
16
|
+
Given a new Rails app
|
|
17
|
+
When I run "rails g fcus:layout FooBar --haml -f"
|
|
18
|
+
Then I should see "stylesheet_link_tag "foo_bar"" in file "app/views/layouts/foo_bar.html.haml"
|
|
19
|
+
And I should see file "public/stylesheets/sass/foo_bar.sass"
|
|
20
|
+
And I should see file "app/helpers/layout_helper.rb"
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Feature: Fcus Scaffold Generator
|
|
2
|
+
In order to manage a resource
|
|
3
|
+
As a rails developer
|
|
4
|
+
I want to generate a model, controller, and views for that resource
|
|
5
|
+
|
|
6
|
+
Scenario: Generate scaffold for simple resource
|
|
7
|
+
Given a new Rails app
|
|
8
|
+
When I run "rails g fcus:scaffold Project name:string"
|
|
9
|
+
Then I should see the following files
|
|
10
|
+
| app/models/project.rb |
|
|
11
|
+
| app/controllers/projects_controller.rb |
|
|
12
|
+
| app/helpers/projects_helper.rb |
|
|
13
|
+
| app/views/projects/index.html.erb |
|
|
14
|
+
| app/views/projects/show.html.erb |
|
|
15
|
+
| app/views/projects/new.html.erb |
|
|
16
|
+
| app/views/projects/edit.html.erb |
|
|
17
|
+
| db/migrate |
|
|
18
|
+
And I should see "resources :projects" in file "config/routes.rb"
|
|
19
|
+
And I should see "gem "mocha", :group => :test" in file "Gemfile"
|
|
20
|
+
When I run "rails g fcus:layout -f"
|
|
21
|
+
And I run "rake db:migrate"
|
|
22
|
+
And I should successfully run "rails g fcus:scaffold Project -f"
|
|
23
|
+
Then I should successfully run "rake test"
|
|
24
|
+
|
|
25
|
+
Scenario: Generate scaffold with rspec tests
|
|
26
|
+
Given a new Rails app
|
|
27
|
+
When I run "rails g fcus:scaffold Project name:string --rspec"
|
|
28
|
+
Then I should see the following files
|
|
29
|
+
| spec/models/project_spec.rb |
|
|
30
|
+
| spec/controllers/projects_controller_spec.rb |
|
|
31
|
+
When I run "rails g fcus:scaffold Task project_id:integer"
|
|
32
|
+
Then I should see the following files
|
|
33
|
+
| spec/models/task_spec.rb |
|
|
34
|
+
| spec/controllers/tasks_controller_spec.rb |
|
|
35
|
+
When I run "rails g fcus:layout -f"
|
|
36
|
+
And I run "rake db:migrate"
|
|
37
|
+
And I add "gem 'rspec-rails', '>= 2.0.0.beta.19'" to file "Gemfile"
|
|
38
|
+
And I run "rails g rspec:install"
|
|
39
|
+
And I replace "mock_with :rspec" with "mock_with :mocha" in file "spec/spec_helper.rb"
|
|
40
|
+
Then I should successfully run "rake spec"
|
|
41
|
+
|
|
42
|
+
Scenario: Report error when invalid model name
|
|
43
|
+
Given a new Rails app
|
|
44
|
+
Then I should see "Usage:" when running "rails g fcus:scaffold name:string parent_id:integer"
|
|
45
|
+
|
|
46
|
+
Scenario: Generate scaffold for namespaced resource
|
|
47
|
+
Given a new Rails app
|
|
48
|
+
When I run "rails g fcus:scaffold Admin::User name:string"
|
|
49
|
+
Then I should see the following files
|
|
50
|
+
| app/models/user.rb |
|
|
51
|
+
| app/controllers/admin/users_controller.rb |
|
|
52
|
+
| app/helpers/admin/users_helper.rb |
|
|
53
|
+
| app/views/admin/users/index.html.erb |
|
|
54
|
+
| app/views/admin/users/show.html.erb |
|
|
55
|
+
| app/views/admin/users/new.html.erb |
|
|
56
|
+
| app/views/admin/users/edit.html.erb |
|
|
57
|
+
| db/migrate |
|
|
58
|
+
And I should see "class User" in file "app/models/user.rb"
|
|
59
|
+
And I should not see "set_table_name :" in file "app/models/user.rb"
|
|
60
|
+
And I should see "namespace(:admin){ resources :users }" in file "config/routes.rb"
|
|
61
|
+
When I run "rails g fcus:layout -f"
|
|
62
|
+
And I run "rake db:migrate"
|
|
63
|
+
And I should successfully run "rails g fcus:scaffold Admin::User -f"
|
|
64
|
+
Then I should successfully run "rake test"
|
|
65
|
+
|
|
66
|
+
Scenario: Generate scaffold with a namespaced model
|
|
67
|
+
Given a new Rails app
|
|
68
|
+
When I run "rails g fcus:scaffold Admin::User name:string --namespace_model"
|
|
69
|
+
Then I should see "class Admin::User" in file "app/models/admin/user.rb"
|
|
70
|
+
And I should see "set_table_name :admin_users" in file "app/models/admin/user.rb"
|
|
71
|
+
When I run "rails g fcus:layout -f"
|
|
72
|
+
And I run "rake db:migrate"
|
|
73
|
+
And I should successfully run "rails g fcus:scaffold Admin::User -f --namespace_model"
|
|
74
|
+
Then I should successfully run "rake test"
|
|
75
|
+
|
|
76
|
+
Scenario: Given scaffold with a new and index action
|
|
77
|
+
Given a new Rails app
|
|
78
|
+
When I run "rails g fcus:scaffold Project name:string index new"
|
|
79
|
+
Then I should see "class Project" in file "app/models/project.rb"
|
|
80
|
+
And I should see "<%= form_for @project do |f| %>" in file "app/views/projects/new.html.erb"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
When /^I run "([^\"]*)"$/ do |command|
|
|
2
|
+
system("cd #{@current_directory} && #{command}").should be_true
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
When /^I add "([^\"]*)" to file "([^\"]*)"$/ do |content, short_path|
|
|
6
|
+
path = File.join(@current_directory, short_path)
|
|
7
|
+
File.should exist(path)
|
|
8
|
+
File.open(path, 'a') { |f| f.write(content + "\n") }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
When /^I replace "([^\"]*)" with "([^\"]*)" in file "([^\"]*)"$/ do |old_content, new_content, short_path|
|
|
12
|
+
path = File.join(@current_directory, short_path)
|
|
13
|
+
File.should exist(path)
|
|
14
|
+
content = File.read(path).gsub(old_content, new_content)
|
|
15
|
+
File.open(path, 'w') { |f| f.write(content) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
When /^I insert "([^\"]*)" into "([^\"]*)" after line (\d+)$/ do |content, short_path, after_line|
|
|
19
|
+
path = File.join(@current_directory, short_path)
|
|
20
|
+
File.should exist(path)
|
|
21
|
+
lines = File.read(path).split("\n")
|
|
22
|
+
lines[after_line.to_i, 0] = content
|
|
23
|
+
File.open(path, 'w') { |f| f.write(lines.join("\n")) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Then /^I should see file "([^\"]*)"$/ do |path|
|
|
27
|
+
File.should exist(File.join(@current_directory, path))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Then /^I should see "(.*)" in file "([^\"]*)"$/ do |content, short_path|
|
|
31
|
+
path = File.join(@current_directory, short_path)
|
|
32
|
+
File.should exist(path)
|
|
33
|
+
File.readlines(path).join.should include(content)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Then /^I should not see "(.*)" in file "([^\"]*)"$/ do |content, short_path|
|
|
37
|
+
path = File.join(@current_directory, short_path)
|
|
38
|
+
File.should exist(path)
|
|
39
|
+
File.readlines(path).join.should_not include(content)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
Then /^I should see the following files$/ do |table|
|
|
43
|
+
table.raw.flatten.each do |path|
|
|
44
|
+
File.should exist(File.join(@current_directory, path))
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
Then /^I should see the following in file "([^\"]*)"$/ do |short_path, table|
|
|
49
|
+
path = File.join(@current_directory, short_path)
|
|
50
|
+
File.should exist(path)
|
|
51
|
+
table.raw.flatten.each do |content|
|
|
52
|
+
File.readlines(path).join.should include(content)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
Then /^I should successfully run "([^\"]*)"$/ do |command|
|
|
57
|
+
system("cd #{@current_directory} && #{command}").should be_true
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
Then /^I should see "([^\"]*)" when running "([^\"]*)"$/ do |expected_response, command|
|
|
61
|
+
`cd #{@current_directory} && #{command}`.should include(expected_response)
|
|
62
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'rails/generators/base'
|
|
2
|
+
|
|
3
|
+
module Fcus
|
|
4
|
+
module Generators
|
|
5
|
+
class Base < Rails::Generators::Base #:nodoc:
|
|
6
|
+
def self.source_root
|
|
7
|
+
@_fcus_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'fcus', generator_name, 'templates'))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.banner
|
|
11
|
+
"rails generate fcus:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def add_gem(name, options = {})
|
|
17
|
+
gemfile_content = File.read(destination_path("Gemfile"))
|
|
18
|
+
File.open(destination_path("Gemfile"), 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
|
|
19
|
+
gem name, options unless gemfile_content.include? name
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def print_usage
|
|
23
|
+
self.class.help(Thor::Base.shell.new)
|
|
24
|
+
exit
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|