rails3_devise_wizard 0.2

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.
Files changed (61) hide show
  1. data/README.textile +135 -0
  2. data/bin/rails3_devise_wizard +7 -0
  3. data/lib/rails_wizard/command.rb +79 -0
  4. data/lib/rails_wizard/config.rb +86 -0
  5. data/lib/rails_wizard/recipe.rb +106 -0
  6. data/lib/rails_wizard/recipes.rb +38 -0
  7. data/lib/rails_wizard/template.rb +58 -0
  8. data/lib/rails_wizard.rb +10 -0
  9. data/recipes/action_mailer.rb +41 -0
  10. data/recipes/activerecord.rb +37 -0
  11. data/recipes/add_user_name.rb +75 -0
  12. data/recipes/application_layout.rb +43 -0
  13. data/recipes/ban_spiders.rb +19 -0
  14. data/recipes/capybara.rb +34 -0
  15. data/recipes/cleanup.rb +34 -0
  16. data/recipes/css_setup.rb +40 -0
  17. data/recipes/cucumber.rb +69 -0
  18. data/recipes/devise.rb +35 -0
  19. data/recipes/devise_navigation.rb +95 -0
  20. data/recipes/env_yaml.rb +54 -0
  21. data/recipes/git.rb +26 -0
  22. data/recipes/haml.rb +14 -0
  23. data/recipes/heroku.rb +58 -0
  24. data/recipes/home_page.rb +43 -0
  25. data/recipes/home_page_users.rb +50 -0
  26. data/recipes/hoptoad.rb +34 -0
  27. data/recipes/jammit.rb +43 -0
  28. data/recipes/jquery.rb +44 -0
  29. data/recipes/less.rb +12 -0
  30. data/recipes/mongo_mapper.rb +18 -0
  31. data/recipes/mongohq.rb +59 -0
  32. data/recipes/mongoid.rb +30 -0
  33. data/recipes/mootools.rb +23 -0
  34. data/recipes/omniauth.rb +15 -0
  35. data/recipes/pow.rb +12 -0
  36. data/recipes/prototype.rb +11 -0
  37. data/recipes/rails_admin.rb +21 -0
  38. data/recipes/redis.rb +17 -0
  39. data/recipes/redistogo.rb +40 -0
  40. data/recipes/rightjs.rb +17 -0
  41. data/recipes/rspec.rb +89 -0
  42. data/recipes/sass.rb +13 -0
  43. data/recipes/seed_database.rb +35 -0
  44. data/recipes/sequel.rb +13 -0
  45. data/recipes/settingslogic.rb +43 -0
  46. data/recipes/slim.rb +11 -0
  47. data/recipes/test_unit.rb +11 -0
  48. data/recipes/users_page.rb +103 -0
  49. data/spec/rails_wizard/config_spec.rb +99 -0
  50. data/spec/rails_wizard/recipe_spec.rb +103 -0
  51. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  52. data/spec/rails_wizard/recipes_spec.rb +24 -0
  53. data/spec/rails_wizard/template_spec.rb +48 -0
  54. data/spec/spec_helper.rb +11 -0
  55. data/spec/support/rails_directory.rb +17 -0
  56. data/spec/support/template_runner.rb +28 -0
  57. data/templates/helpers.erb +45 -0
  58. data/templates/layout.erb +46 -0
  59. data/templates/recipe.erb +10 -0
  60. data/version.rb +3 -0
  61. metadata +205 -0
@@ -0,0 +1,35 @@
1
+ # Application template recipe for the rails3_devise_wizard. Check for a newer version here:
2
+ # https://github.com/fortuity/rails3_devise_wizard/blob/master/recipes/seed_database.rb
3
+
4
+
5
+ after_bundler do
6
+
7
+ if recipes.include? 'devise'
8
+
9
+ if recipes.include? 'mongoid'
10
+ # create a default user
11
+ append_file 'db/seeds.rb' do <<-FILE
12
+ puts 'EMPTY THE MONGODB DATABASE'
13
+ Mongoid.master.collections.reject { |c| c.name =~ /^system/}.each(&:drop)
14
+ puts 'SETTING UP DEFAULT USER LOGIN'
15
+ user = User.create! :name => 'First User', :email => 'user@test.com', :password => 'please', :password_confirmation => 'please'
16
+ puts 'New user created: ' << user.name
17
+ FILE
18
+ end
19
+ end
20
+
21
+ run 'rake db:seed'
22
+
23
+ end
24
+
25
+ end
26
+
27
+ __END__
28
+
29
+ name: SeedDatabase
30
+ description: "Create a database seed file with a default user."
31
+ author: fortuity
32
+
33
+ requires: [devise]
34
+ category: other
35
+ tags: [utilities, configuration]
data/recipes/sequel.rb ADDED
@@ -0,0 +1,13 @@
1
+ gem 'sequel-rails'
2
+
3
+ application "require 'sequel-rails/railtie'"
4
+
5
+ __END__
6
+
7
+ name: Sequel
8
+ description: "Utilize Sequel as the primary ORM for your application."
9
+ author: mbleigh
10
+
11
+ exclusive: orm
12
+ category: persistence
13
+ tags: [orm, sql]
@@ -0,0 +1,43 @@
1
+ gem 'settingslogic'
2
+
3
+ say_wizard "Generating config/application.yml..."
4
+
5
+ append_file "config/application.rb", <<-RUBY
6
+
7
+ require 'settings'
8
+ RUBY
9
+
10
+ create_file "lib/settings.rb", <<-RUBY
11
+ class Settings < Settingslogic
12
+ source "#\{Rails.root\}/config/application.yml"
13
+ namespace Rails.env
14
+ end
15
+
16
+ RUBY
17
+
18
+ create_file "config/application.yml", <<-YAML
19
+ defaults: &defaults
20
+ cool:
21
+ saweet: nested settings
22
+ neat_setting: 24
23
+ awesome_setting: <%= "Did you know 5 + 5 = #{5 + 5}?" %>
24
+
25
+ development:
26
+ <<: *defaults
27
+ neat_setting: 800
28
+
29
+ test:
30
+ <<: *defaults
31
+
32
+ production:
33
+ <<: *defaults
34
+ YAML
35
+
36
+ __END__
37
+
38
+ name: Settingslogic
39
+ description: "A simple and straightforward settings solution that uses an ERB enabled YAML file and a singleton design pattern."
40
+ author: elandesign
41
+
42
+ category: other
43
+ tags: [utilities, configuration]
data/recipes/slim.rb ADDED
@@ -0,0 +1,11 @@
1
+ gem 'slim'
2
+ gem 'slim-rails'
3
+
4
+ __END__
5
+
6
+ name: Slim
7
+ description: "Use Slim as the default templating engine."
8
+ author: mbleigh
9
+
10
+ category: templating
11
+ exclusive: templating
@@ -0,0 +1,11 @@
1
+ # No additional code required.
2
+
3
+ __END__
4
+
5
+ name: Test::Unit
6
+ description: "Utilize the default Rails test facilities."
7
+ author: mbleigh
8
+
9
+ exclusive: unit_testing
10
+ category: testing
11
+ tags: [defaults]
@@ -0,0 +1,103 @@
1
+ # Application template recipe for the rails3_devise_wizard. Check for a newer version here:
2
+ # https://github.com/fortuity/rails3_devise_wizard/blob/master/recipes/users_page.rb
3
+
4
+ after_bundler do
5
+
6
+ if recipes.include? 'devise'
7
+
8
+ #----------------------------------------------------------------------------
9
+ # Create a users controller
10
+ #----------------------------------------------------------------------------
11
+ generate(:controller, "users show")
12
+ gsub_file 'app/controllers/users_controller.rb', /def show/ do
13
+ <<-RUBY
14
+ before_filter :authenticate_user!
15
+
16
+ def show
17
+ @user = User.find(params[:id])
18
+ RUBY
19
+ end
20
+
21
+ #----------------------------------------------------------------------------
22
+ # Modify the routes
23
+ #----------------------------------------------------------------------------
24
+ # @devise_for :users@ route must be placed above @resources :users, :only => :show@.
25
+ gsub_file 'config/routes.rb', /get \"users\/show\"/, '#get \"users\/show\"'
26
+ gsub_file 'config/routes.rb', /devise_for :users/ do
27
+ <<-RUBY
28
+ devise_for :users
29
+ resources :users, :only => :show
30
+ RUBY
31
+ end
32
+
33
+ #----------------------------------------------------------------------------
34
+ # Create a users show page
35
+ #----------------------------------------------------------------------------
36
+ if recipes.include? 'haml'
37
+ remove_file 'app/views/users/show.html.haml'
38
+ # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
39
+ # We have to use single-quote-style-heredoc to avoid interpolation.
40
+ create_file 'app/views/users/show.html.haml' do <<-'HAML'
41
+ %p
42
+ User: #{@user.name}
43
+ HAML
44
+ end
45
+ else
46
+ append_file 'app/views/users/show.html.erb' do <<-ERB
47
+ <p>User: <%= @user.name %></p>
48
+ ERB
49
+ end
50
+ end
51
+
52
+ #----------------------------------------------------------------------------
53
+ # Create a home page containing links to user show pages
54
+ # (clobbers code from the home_page_users recipe)
55
+ #----------------------------------------------------------------------------
56
+ # set up the controller
57
+ remove_file 'app/controllers/home_controller.rb'
58
+ create_file 'app/controllers/home_controller.rb' do
59
+ <<-RUBY
60
+ class HomeController < ApplicationController
61
+ def index
62
+ @users = User.all
63
+ end
64
+ end
65
+ RUBY
66
+ end
67
+
68
+ # modify the home page
69
+ if recipes.include? 'haml'
70
+ remove_file 'app/views/home/index.html.haml'
71
+ # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
72
+ # We have to use single-quote-style-heredoc to avoid interpolation.
73
+ create_file 'app/views/home/index.html.haml' do
74
+ <<-'HAML'
75
+ %h3 Home
76
+ - @users.each do |user|
77
+ %p User: #{link_to user.name, user}
78
+ HAML
79
+ end
80
+ else
81
+ remove_file 'app/views/home/index.html.erb'
82
+ create_file 'app/views/home/index.html.erb' do <<-ERB
83
+ <h3>Home</h3>
84
+ <% @users.each do |user| %>
85
+ <p>User: <%=link_to user.name, user %></p>
86
+ <% end %>
87
+ ERB
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ __END__
96
+
97
+ name: UsersPage
98
+ description: "Add a users controller and user show page with links from the home page."
99
+ author: fortuity
100
+
101
+ requires: [devise]
102
+ category: other
103
+ tags: [utilities, configuration]
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsWizard::Config do
4
+ describe '#initialize' do
5
+ subject{ RailsWizard::Config.new(YAML.load(@schema)) }
6
+ it 'should add a question key for each key of the schema' do
7
+ @schema = <<-YAML
8
+ - test:
9
+ type: string
10
+ YAML
11
+ subject.questions.should be_key('test')
12
+ end
13
+
14
+ it 'should instantiate the correct question type for each question' do
15
+ @schema = <<-YAML
16
+ - string:
17
+ type: string
18
+ - boolean:
19
+ type: boolean
20
+ - multiple_choice:
21
+ type: multiple_choice
22
+ YAML
23
+ subject.questions['string'].should be_kind_of(RailsWizard::Config::Prompt)
24
+ subject.questions['boolean'].should be_kind_of(RailsWizard::Config::TrueFalse)
25
+ subject.questions['multiple_choice'].should be_kind_of(RailsWizard::Config::MultipleChoice)
26
+ end
27
+
28
+ it 'should error on invalid question type' do
29
+ @schema = <<-YAML
30
+ - invalid
31
+ type: invalid
32
+ YAML
33
+ lambda{ subject }.should raise_error(ArgumentError)
34
+ end
35
+
36
+ describe '#compile' do
37
+ let(:lines) { subject.compile.split("\n") }
38
+ before do
39
+ @schema = <<-YAML
40
+ - string:
41
+ type: string
42
+ prompt: Give me a string?
43
+ if: is_true
44
+ - boolean:
45
+ type: boolean
46
+ prompt: Yes or no?
47
+ unless: is_false
48
+ if_recipe: awesome
49
+ - multiple_choice:
50
+ type: multiple_choice
51
+ choices: [[ABC, abc], [DEF, def]]
52
+ unless_recipe: awesome
53
+ YAML
54
+ end
55
+
56
+ it 'should include all questions' do
57
+ lines.size.should == 4
58
+ end
59
+
60
+ it 'should handle "if"' do
61
+ lines[1].should be_include("config['is_true']")
62
+ end
63
+
64
+ it 'should handle "unless"' do
65
+ lines[2].should be_include("!config['is_false']")
66
+ end
67
+
68
+ it 'should handle "if_recipe"' do
69
+ lines[2].should be_include("recipe?('awesome')")
70
+ end
71
+
72
+ it 'should handle "unelss_recipe"' do
73
+ lines[3].should be_include("!recipe?('awesome')")
74
+ end
75
+ end
76
+
77
+ describe RailsWizard::Config::Prompt do
78
+ subject{ RailsWizard::Config::Prompt }
79
+ it 'should compile to a prompt' do
80
+ subject.new({'prompt' => "What's your favorite color?"}).question.should == 'ask_wizard("What\'s your favorite color?")'
81
+ end
82
+ end
83
+
84
+ describe RailsWizard::Config::TrueFalse do
85
+ subject{ RailsWizard::Config::TrueFalse }
86
+ it 'should compile to a yes? question' do
87
+ subject.new({'prompt' => 'Yes yes?'}).question.should == 'yes_wizard?("Yes yes?")'
88
+ end
89
+ end
90
+
91
+ describe RailsWizard::Config::MultipleChoice do
92
+ subject{ RailsWizard::Config::MultipleChoice }
93
+ it 'should compile into a multiple_choice' do
94
+ subject.new({'prompt' => 'What kind of fruit?', 'choices' => [['Apples', 'apples'], ['Bananas', 'bananas']]}).question.should ==
95
+ 'multiple_choice("What kind of fruit?", [["Apples", "apples"], ["Bananas", "bananas"]])'
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsWizard::Recipe do
4
+ context "with a generated recipe" do
5
+ subject{ RailsWizard::Recipe.generate('recipe_example', "# this is a test", :category => 'example', :name => "RailsWizard Example") }
6
+
7
+ context 'string setter methods' do
8
+ (RailsWizard::Recipe::ATTRIBUTES - ['config']).each do |setter|
9
+ it "should be able to set #{setter} with an argument" do
10
+ subject.send(setter + '=', "test")
11
+ subject.send(setter).should == 'test'
12
+ end
13
+
14
+ it 'should be able to get the value from the instance' do
15
+ subject.send(setter + '=', 'test')
16
+ subject.new.send(setter).should == subject.send(setter)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '.attributes' do
22
+ it 'should be accessible from the instance' do
23
+ subject.new.attributes.should == subject.attributes
24
+ end
25
+ end
26
+
27
+ describe '.generate' do
28
+ it 'should work with a string and hash as arguments' do
29
+ recipe = RailsWizard::Recipe.generate('some_key', '# some code', :name => "Example")
30
+ recipe.superclass.should == RailsWizard::Recipe
31
+ end
32
+
33
+ it 'should work with an IO object' do
34
+ file = StringIO.new <<-RUBY
35
+ # this is an example
36
+
37
+ __END__
38
+
39
+ category: example
40
+ name: This is an Example
41
+ description: You know it's an exmaple.
42
+ RUBY
43
+ recipe = RailsWizard::Recipe.generate('just_a_test', file)
44
+ recipe.template.should == '# this is an example'
45
+ recipe.category.should == 'example'
46
+ recipe.name.should == 'This is an Example'
47
+ end
48
+
49
+ it 'should raise an exception if the file is incorrectly formatted' do
50
+ file = StringIO.new <<-RUBY
51
+ # just ruby, no YAML
52
+ RUBY
53
+ lambda{RailsWizard::Recipe.generate('testing',file)}.should raise_error(ArgumentError)
54
+ end
55
+ end
56
+
57
+ describe '#compile' do
58
+ it 'should say the name' do
59
+ subject.name = "Awesome Sauce"
60
+ subject.new.compile.should be_include("say_recipe 'Awesome Sauce'")
61
+ end
62
+
63
+ it 'should include the template' do
64
+ subject.template = "This is only a test."
65
+ subject.new.compile.should be_include(subject.template)
66
+ end
67
+ end
68
+ end
69
+
70
+ it 'should set default attributes' do
71
+ recipe = RailsWizard::Recipe.generate('abc','# test')
72
+
73
+ RailsWizard::Recipe::DEFAULT_ATTRIBUTES.each_pair do |k,v|
74
+ recipe.send(k).should == v
75
+ end
76
+ end
77
+
78
+ context 'Comparable' do
79
+ subject{ RailsWizard::Recipe }
80
+ it 'a < b.run_after(a)' do
81
+ A = subject.generate('a', '#')
82
+ B = subject.generate('b', '#', :run_after => ['a'])
83
+
84
+ (A < B).should be_true
85
+ end
86
+
87
+ it 'a > b.run_before(a)' do
88
+ A = subject.generate('a', '#')
89
+ B = subject.generate('b', '#', :run_before => ['a'])
90
+
91
+ (A > B).should be_true
92
+ end
93
+
94
+ after do
95
+ Object.send :remove_const, :A if defined?(A)
96
+ Object.send :remove_const, :B if defined?(B)
97
+ end
98
+ end
99
+ end
100
+
101
+ __END__
102
+
103
+ this is a test
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ # This is a simple set of tests to make sure that
4
+ # all of the recipes conform to the base requirements.
5
+
6
+ RailsWizard::Recipes.list_classes.each do |recipe|
7
+ describe recipe do
8
+ it("should have a name"){ recipe.name.should be_kind_of(String) }
9
+ it("should have a description"){ recipe.description.should be_kind_of(String) }
10
+ it("should have a template"){ recipe.template.should be_kind_of(String) }
11
+ it("should be able to compile"){ recipe.new.compile.should be_kind_of(String) }
12
+
13
+ it "should have a string or nil category" do
14
+ if recipe.category
15
+ recipe.category.should be_kind_of(String)
16
+ end
17
+ end
18
+
19
+ it "should have a Config or nil config" do
20
+ if recipe.config
21
+ recipe.config.should be_kind_of(RailsWizard::Config)
22
+ end
23
+ end
24
+
25
+ it "should be in the list" do
26
+ RailsWizard::Recipes.list_classes.should be_include(recipe)
27
+ RailsWizard::Recipes.list.should be_include(recipe.key)
28
+ end
29
+ end
30
+ end