thyone_creator 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/bin/thyone +7 -0
  2. data/lib/rails_wizard/command.rb +116 -0
  3. data/lib/rails_wizard/config.rb +88 -0
  4. data/lib/rails_wizard/recipe.rb +106 -0
  5. data/lib/rails_wizard/recipes.rb +38 -0
  6. data/lib/rails_wizard/template.rb +73 -0
  7. data/lib/rails_wizard.rb +10 -0
  8. data/recipes/action_mailer.rb +123 -0
  9. data/recipes/active_admin.rb +44 -0
  10. data/recipes/activerecord.rb +37 -0
  11. data/recipes/add_user.rb +129 -0
  12. data/recipes/airbrake.rb +34 -0
  13. data/recipes/backbone.rb +23 -0
  14. data/recipes/capybara.rb +34 -0
  15. data/recipes/cleanup.rb +40 -0
  16. data/recipes/cloudfiles.rb +36 -0
  17. data/recipes/compass.rb +46 -0
  18. data/recipes/compass_960.rb +48 -0
  19. data/recipes/cucumber.rb +75 -0
  20. data/recipes/datamapper.rb +111 -0
  21. data/recipes/devise.rb +114 -0
  22. data/recipes/extras.rb +80 -0
  23. data/recipes/git.rb +40 -0
  24. data/recipes/guard.rb +99 -0
  25. data/recipes/haml.rb +23 -0
  26. data/recipes/heroku.rb +62 -0
  27. data/recipes/home_page.rb +58 -0
  28. data/recipes/home_page_users.rb +47 -0
  29. data/recipes/html5.rb +153 -0
  30. data/recipes/inherited_resources.rb +23 -0
  31. data/recipes/less.rb +12 -0
  32. data/recipes/mongohq.rb +59 -0
  33. data/recipes/mongoid.rb +39 -0
  34. data/recipes/mongolab.rb +59 -0
  35. data/recipes/omniauth.rb +192 -0
  36. data/recipes/omniauth_email.rb +82 -0
  37. data/recipes/paperclip.rb +79 -0
  38. data/recipes/rails_admin.rb +21 -0
  39. data/recipes/redis.rb +23 -0
  40. data/recipes/responders.rb +10 -0
  41. data/recipes/resque.rb +25 -0
  42. data/recipes/rspec.rb +133 -0
  43. data/recipes/sass.rb +25 -0
  44. data/recipes/seed_database.rb +76 -0
  45. data/recipes/settingslogic.rb +43 -0
  46. data/recipes/simple_form.rb +54 -0
  47. data/recipes/slim.rb +46 -0
  48. data/recipes/static_page.rb +43 -0
  49. data/recipes/subdomains.rb +121 -0
  50. data/recipes/users_page.rb +165 -0
  51. data/spec/rails_wizard/config_spec.rb +108 -0
  52. data/spec/rails_wizard/recipe_spec.rb +81 -0
  53. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  54. data/spec/rails_wizard/recipes_spec.rb +24 -0
  55. data/spec/rails_wizard/template_spec.rb +78 -0
  56. data/spec/spec_helper.rb +11 -0
  57. data/spec/support/rails_directory.rb +17 -0
  58. data/spec/support/template_runner.rb +28 -0
  59. data/templates/helpers.erb +45 -0
  60. data/templates/layout.erb +83 -0
  61. data/templates/recipe.erb +10 -0
  62. data/version.rb +3 -0
  63. metadata +251 -0
@@ -0,0 +1,121 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/subdomains.rb
3
+ # this recipe requires Mongoid and Haml (ActiveRecord and ERB verions are not implemented)
4
+
5
+ if recipes.include? 'haml'
6
+ if recipes.include? 'mongoid'
7
+ after_bundler do
8
+ say_wizard "Subdomains recipe running 'after bundler'"
9
+ case config['subdomain_option']
10
+ when 'no'
11
+ say_wizard "Subdomains recipe skipped."
12
+ when 'one-per-user'
13
+ # user name as a subdomain
14
+ inject_into_file 'app/models/user.rb', :before => 'attr_accessible' do <<-RUBY
15
+ validates_format_of :name, with: /^[a-z0-9_]+$/, message: 'must be lowercase alphanumerics only'
16
+ validates_length_of :name, maximum: 32, message: 'exceeds maximum of 32 characters'
17
+ validates_exclusion_of :name, in: ['www', 'mail', 'ftp'], message: 'is not available'
18
+
19
+ RUBY
20
+ end
21
+ # modify db/seeds.rb
22
+ gsub_file 'db/seeds.rb', /First User/, 'user1'
23
+ gsub_file 'db/seeds.rb', /Second User/, 'user2'
24
+ # controller and views for the profile page
25
+ create_file 'app/controllers/profiles_controller.rb' do
26
+ <<-RUBY
27
+ class ProfilesController < ApplicationController
28
+ def show
29
+ @user = User.first(conditions: { name: request.subdomain }) || not_found
30
+ end
31
+
32
+ def not_found
33
+ raise ActionController::RoutingError.new('User Not Found')
34
+ end
35
+ end
36
+ RUBY
37
+ end
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/profiles/show.html.haml' do
41
+ <<-'HAML'
42
+ %h1 Profile
43
+ %h3= @user.name
44
+ %h3= @user.email
45
+ HAML
46
+ end
47
+ # implement routing constraint for subdomains
48
+ # be sure to autoload (set config.autoload_paths in config/application.rb)
49
+ # or require this class in the config/routes.rb file
50
+ create_file 'lib/subdomain.rb' do
51
+ <<-RUBY
52
+ class Subdomain
53
+ def self.matches?(request)
54
+ case request.subdomain
55
+ when 'www', '', nil
56
+ false
57
+ else
58
+ true
59
+ end
60
+ end
61
+ end
62
+ RUBY
63
+ end
64
+ # create routes for subdomains
65
+ gsub_file 'config/routes.rb', /root :to => "home#index"/, ''
66
+ inject_into_file 'config/routes.rb', :after => 'resources :users, :only => [:show, :index]' do <<-RUBY
67
+
68
+ constraints(Subdomain) do
69
+ match '/' => 'profiles#show'
70
+ end
71
+ root :to => "home#index"
72
+ RUBY
73
+ end
74
+ remove_file 'app/views/users/show.html.haml'
75
+ # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
76
+ # We have to use single-quote-style-heredoc to avoid interpolation.
77
+ create_file 'app/views/users/show.html.haml' do
78
+ <<-'HAML'
79
+ %p
80
+ User: #{@user.name}
81
+ %p
82
+ Email: #{@user.email if @user.email}
83
+ %p
84
+ Profile: #{link_to root_url(:subdomain => @user.name), root_url(:subdomain => @user.name)}
85
+ HAML
86
+ end
87
+ remove_file 'app/views/home/index.html.haml'
88
+ # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
89
+ # We have to use single-quote-style-heredoc to avoid interpolation.
90
+ create_file 'app/views/home/index.html.haml' do
91
+ <<-'HAML'
92
+ %h3 Home
93
+ - @users.each do |user|
94
+ %br/
95
+ #{user.name} profile: #{link_to root_url(:subdomain => user.name), root_url(:subdomain => user.name)}
96
+ HAML
97
+ end
98
+ gsub_file 'app/controllers/users_controller.rb', /before_filter :authenticate_user!/, ''
99
+ end
100
+ end
101
+ else
102
+ say_wizard "The subdomains recipe is only implememted for Mongoid (no support for ActiveRecord)."
103
+ end
104
+ else
105
+ say_wizard "The subdomains recipe is only implememted for Haml (no support for ERB)."
106
+ end
107
+
108
+ __END__
109
+
110
+ name: subdomains
111
+ description: "Allow use of subdomains."
112
+ author: RailsApps
113
+
114
+ category: other
115
+ tags: [utilities, configuration]
116
+
117
+ config:
118
+ - subdomain_option:
119
+ type: multiple_choice
120
+ prompt: "Would you like to add support for subdomains?"
121
+ choices: [["No", no], ["One subdomain per user (like Basecamp)", one-per-user]]
@@ -0,0 +1,165 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/users_page.rb
3
+
4
+ after_bundler do
5
+
6
+ say_wizard "UsersPage recipe running 'after bundler'"
7
+
8
+ #----------------------------------------------------------------------------
9
+ # Create a users controller
10
+ #----------------------------------------------------------------------------
11
+ generate(:controller, "users show index")
12
+ remove_file 'app/controllers/users_controller.rb'
13
+ create_file 'app/controllers/users_controller.rb' do <<-RUBY
14
+ class UsersController < ApplicationController
15
+ before_filter :authenticate_user!
16
+
17
+ def index
18
+ @users = User.all
19
+ end
20
+
21
+ def show
22
+ @user = User.find(params[:id])
23
+ end
24
+
25
+ end
26
+ RUBY
27
+ end
28
+ if recipes.include? 'authorization'
29
+ inject_into_file 'app/controllers/users_controller.rb', " authorize! :index, @user, :message => 'Not authorized as an administrator.'\n", :after => "def index\n"
30
+ end
31
+ if recipes.include? 'paginate'
32
+ gsub_file 'app/controllers/users_controller.rb', /@users = User.all/, '@users = User.paginate(:page => params[:page])'
33
+ end
34
+
35
+ #----------------------------------------------------------------------------
36
+ # Limit access to the users#index page
37
+ #----------------------------------------------------------------------------
38
+ if recipes.include? 'authorization'
39
+ inject_into_file 'app/models/ability.rb', :after => "def initialize(user)\n" do <<-RUBY
40
+ user ||= User.new # guest user (not logged in)
41
+ if user.has_role? :admin
42
+ can :manage, :all
43
+ end
44
+ RUBY
45
+ end
46
+ end
47
+
48
+ #----------------------------------------------------------------------------
49
+ # Modify the routes
50
+ #----------------------------------------------------------------------------
51
+ # @devise_for :users@ route must be placed above @resources :users, :only => :show@.
52
+ gsub_file 'config/routes.rb', /get \"users\/show\"/, ''
53
+ gsub_file 'config/routes.rb', /get \"users\/index\"/, ''
54
+ gsub_file 'config/routes.rb', /devise_for :users/ do
55
+ <<-RUBY
56
+ devise_for :users
57
+ resources :users, :only => [:show, :index]
58
+ RUBY
59
+ end
60
+
61
+ #----------------------------------------------------------------------------
62
+ # Create a users index page
63
+ #----------------------------------------------------------------------------
64
+ if recipes.include? 'haml'
65
+ remove_file 'app/views/users/index.html.haml'
66
+ # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
67
+ # We have to use single-quote-style-heredoc to avoid interpolation.
68
+ create_file 'app/views/users/index.html.haml' do <<-'HAML'
69
+ %h2 Users
70
+ - @users.each do |user|
71
+ %br/
72
+ #{link_to user.email, user} signed up #{user.created_at.to_date}
73
+ HAML
74
+ end
75
+ if recipes.include? 'paginate'
76
+ append_file 'app/views/users/index.html.haml', "\n= will_paginate\n"
77
+ end
78
+ else
79
+ append_file 'app/views/users/index.html.erb' do <<-ERB
80
+ <ul class="users">
81
+ <% @users.each do |user| %>
82
+ <li>
83
+ <%= link_to user.name, user %> signed up <%= user.created_at.to_date %>
84
+ </li>
85
+ <% end %>
86
+ </ul>
87
+ ERB
88
+ end
89
+ if recipes.include? 'paginate'
90
+ append_file 'app/views/users/index.html.erb', "\n<%= will_paginate %>\n"
91
+ end
92
+ end
93
+
94
+ #----------------------------------------------------------------------------
95
+ # Create a users show page
96
+ #----------------------------------------------------------------------------
97
+ if recipes.include? 'haml'
98
+ remove_file 'app/views/users/show.html.haml'
99
+ # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
100
+ # We have to use single-quote-style-heredoc to avoid interpolation.
101
+ create_file 'app/views/users/show.html.haml' do <<-'HAML'
102
+ %p
103
+ User: #{@user.name}
104
+ %p
105
+ Email: #{@user.email if @user.email}
106
+ HAML
107
+ end
108
+ else
109
+ append_file 'app/views/users/show.html.erb' do <<-ERB
110
+ <p>User: <%= @user.name %></p>
111
+ <p>Email: <%= @user.email if @user.email %></p>
112
+ ERB
113
+ end
114
+ end
115
+
116
+ #----------------------------------------------------------------------------
117
+ # Create a home page containing links to user show pages
118
+ # (clobbers code from the home_page_users recipe)
119
+ #----------------------------------------------------------------------------
120
+ # set up the controller
121
+ remove_file 'app/controllers/home_controller.rb'
122
+ create_file 'app/controllers/home_controller.rb' do
123
+ <<-RUBY
124
+ class HomeController < ApplicationController
125
+ def index
126
+ @users = User.all
127
+ end
128
+ end
129
+ RUBY
130
+ end
131
+
132
+ # modify the home page
133
+ if recipes.include? 'haml'
134
+ remove_file 'app/views/home/index.html.haml'
135
+ # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
136
+ # We have to use single-quote-style-heredoc to avoid interpolation.
137
+ create_file 'app/views/home/index.html.haml' do
138
+ <<-'HAML'
139
+ %h3 Home
140
+ - @users.each do |user|
141
+ %p User: #{link_to user.name, user}
142
+ HAML
143
+ end
144
+ else
145
+ remove_file 'app/views/home/index.html.erb'
146
+ create_file 'app/views/home/index.html.erb' do <<-ERB
147
+ <h3>Home</h3>
148
+ <% @users.each do |user| %>
149
+ <p>User: <%=link_to user.name, user %></p>
150
+ <% end %>
151
+ ERB
152
+ end
153
+ end
154
+
155
+ end
156
+
157
+ __END__
158
+
159
+ name: UsersPage
160
+ description: "Add a users controller and user show page with links from the home page."
161
+ author: RailsApps
162
+
163
+ run_after: [add_user]
164
+ category: other
165
+ tags: [utilities, configuration]
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsWizard::Config do
4
+ describe '#initialize' do
5
+ let(:defaults) { nil }
6
+ subject{ RailsWizard::Config.new(YAML.load(@schema), defaults) }
7
+ it 'should add a question key for each key of the schema' do
8
+ @schema = <<-YAML
9
+ - test:
10
+ type: string
11
+ YAML
12
+ subject.questions.should be_key('test')
13
+ end
14
+
15
+ it 'should instantiate the correct question type for each question' do
16
+ @schema = <<-YAML
17
+ - string:
18
+ type: string
19
+ - boolean:
20
+ type: boolean
21
+ - multiple_choice:
22
+ type: multiple_choice
23
+ YAML
24
+ subject.questions['string'].should be_kind_of(RailsWizard::Config::Prompt)
25
+ subject.questions['boolean'].should be_kind_of(RailsWizard::Config::TrueFalse)
26
+ subject.questions['multiple_choice'].should be_kind_of(RailsWizard::Config::MultipleChoice)
27
+ end
28
+
29
+ # it 'should error on invalid question type' do
30
+ # @schema = <<-YAML
31
+ # - invalid
32
+ # type: invalid
33
+ # YAML
34
+ # lambda{ subject }.should raise_error(ArgumentError)
35
+ # end
36
+
37
+ describe '#compile' do
38
+ let(:lines) { subject.compile.split("\n") }
39
+ before do
40
+ @schema = <<-YAML
41
+ - string:
42
+ type: string
43
+ prompt: Give me a string?
44
+ if: is_true
45
+ - boolean:
46
+ type: boolean
47
+ prompt: Yes or no?
48
+ unless: is_false
49
+ if_recipe: awesome
50
+ - multiple_choice:
51
+ type: multiple_choice
52
+ choices: [[ABC, abc], [DEF, def]]
53
+ unless_recipe: awesome
54
+ YAML
55
+ end
56
+
57
+ it 'should include all questions' do
58
+ lines.size.should == 4
59
+ end
60
+
61
+ it 'should handle "if"' do
62
+ lines[1].should be_include("config['is_true']")
63
+ end
64
+
65
+ it 'should handle "unless"' do
66
+ lines[2].should be_include("!config['is_false']")
67
+ end
68
+
69
+ it 'should handle "if_recipe"' do
70
+ lines[2].should be_include("recipe?('awesome')")
71
+ end
72
+
73
+ it 'should handle "unelss_recipe"' do
74
+ lines[3].should be_include("!recipe?('awesome')")
75
+ end
76
+
77
+ describe 'with defaults' do
78
+ let(:defaults) { { 'multiple_choice' => 'def' }}
79
+
80
+ it 'should process defaults' do
81
+ lines[0].should == 'config = {"multiple_choice"=>"def"}'
82
+ end
83
+ end
84
+ end
85
+
86
+ describe RailsWizard::Config::Prompt do
87
+ subject{ RailsWizard::Config::Prompt }
88
+ it 'should compile to a prompt' do
89
+ subject.new({'prompt' => "What's your favorite color?"}).question.should == 'ask_wizard("What\'s your favorite color?")'
90
+ end
91
+ end
92
+
93
+ describe RailsWizard::Config::TrueFalse do
94
+ subject{ RailsWizard::Config::TrueFalse }
95
+ it 'should compile to a yes? question' do
96
+ subject.new({'prompt' => 'Yes yes?'}).question.should == 'yes_wizard?("Yes yes?")'
97
+ end
98
+ end
99
+
100
+ describe RailsWizard::Config::MultipleChoice do
101
+ subject{ RailsWizard::Config::MultipleChoice }
102
+ it 'should compile into a multiple_choice' do
103
+ subject.new({'prompt' => 'What kind of fruit?', 'choices' => [['Apples', 'apples'], ['Bananas', 'bananas']]}).question.should ==
104
+ 'multiple_choice("What kind of fruit?", [["Apples", "apples"], ["Bananas", "bananas"]])'
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,81 @@
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
+ end
78
+
79
+ __END__
80
+
81
+ 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
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsWizard::Recipes do
4
+ subject{ RailsWizard::Recipes }
5
+ let(:recipe){ RailsWizard::Recipe.generate("recipe_test", "# Testing", :name => "Test Recipe", :category => "test", :description => "Just a test.")}
6
+
7
+ before(:all) do
8
+ RailsWizard::Recipes.add(recipe)
9
+ end
10
+
11
+ it '.list_classes should include recipe classes' do
12
+ subject.list_classes.should be_include(recipe)
13
+ end
14
+
15
+ it '.list should include recipe keys' do
16
+ subject.list.should be_include('recipe_test')
17
+ end
18
+
19
+ describe '.for' do
20
+ it 'should find for a given category' do
21
+ RailsWizard::Recipes.for('test').should be_include('recipe_test')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsWizard::Template do
4
+ subject{ RailsWizard::Template }
5
+ let(:recipe){ RailsWizard::Recipe.generate('name','# test') }
6
+ let(:defaults){ { "some_option" => "value" } }
7
+
8
+ describe '#initialize' do
9
+ it 'should work with classes' do
10
+ subject.new([recipe]).recipes.should == [recipe]
11
+ end
12
+
13
+ it 'should accept optional defaults' do
14
+ subject.new([recipe], defaults).defaults.should == defaults
15
+ end
16
+ end
17
+
18
+ describe '#resolve_dependencies' do
19
+ def recipe(name, opts={})
20
+ RailsWizard::Recipe.generate(name, '', opts)
21
+ end
22
+
23
+ subject do
24
+ @template = RailsWizard::Template.new([])
25
+ @template.stub!(:recipes_with_dependencies).and_return(@recipes)
26
+ @template.resolve_recipes.map { |r| r.key }
27
+ end
28
+
29
+ it 'should sort properly' do
30
+ @recipes = [
31
+ recipe('add_user', :run_after => ['devise']),
32
+ recipe('devise', :run_after => ['omniauth']),
33
+ recipe('omniauth'),
34
+ recipe('haml'),
35
+ recipe('compass')
36
+ ]
37
+
38
+ subject.index('devise').should > subject.index('omniauth')
39
+ end
40
+
41
+ end
42
+
43
+ describe '#recipes_with_dependencies' do
44
+ def r(*deps)
45
+ mock(:Class, :requires => deps, :superclass => RailsWizard::Recipe)
46
+ end
47
+
48
+ subject do
49
+ @template = RailsWizard::Template.new([])
50
+ @template.stub!(:recipes).and_return(@recipes)
51
+ @template.stub!(:recipe_classes).and_return(@recipes)
52
+ @template
53
+ end
54
+
55
+ it 'should return the same number recipes if none have dependencies' do
56
+ @recipes = [r, r]
57
+ subject.recipes_with_dependencies.size.should == 2
58
+ end
59
+
60
+ it 'should handle simple dependencies' do
61
+ @recipes = [r(r, r), r(r)]
62
+ subject.recipes_with_dependencies.size.should == 5
63
+ end
64
+
65
+ it 'should handle multi-level dependencies' do
66
+ @recipes = [r(r(r))]
67
+ subject.recipes_with_dependencies.size.should == 3
68
+ end
69
+
70
+ it 'should uniqify' do
71
+ a = r
72
+ b = r(a)
73
+ c = r(r, a, b)
74
+ @recipes = [a,b,c]
75
+ subject.recipes_with_dependencies.size.should == 4
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+ require 'rspec'
4
+
5
+ Dir[File.dirname(__FILE__) + '/support/*'].each{|path| require path}
6
+
7
+ require 'rails_wizard'
8
+
9
+ RSpec.configure do |config|
10
+
11
+ end
@@ -0,0 +1,17 @@
1
+ class RailsDirectory
2
+ def initialize(path)
3
+ @path = path
4
+ end
5
+
6
+ def file_path(path)
7
+ File.join(@path, path)
8
+ end
9
+
10
+ def has_file?(path)
11
+ File.exist?(file_path(path))
12
+ end
13
+
14
+ def [](path)
15
+ File.open(file_path(path)).read
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ class TemplateRunner
2
+ attr_reader :template, :config, :app_name, :dir, :rails_dir, :output
3
+ def initialize(template, config)
4
+ @template = template
5
+ @config = config
6
+ end
7
+
8
+ def run(app_name = 'rails_app')
9
+ @app_name = app_name
10
+ @dir = Dir.mktmpdir
11
+ @rails_dir = File.join(@dir, @app_name)
12
+ Dir.chrdir(@dir) do
13
+ template_file = File.open 'template.rb', 'w'
14
+ template_file.write
15
+ template_file.close
16
+ @output = `rails new #{@app_name} -m template.rb`
17
+ end
18
+ @output
19
+ end
20
+
21
+ def rails
22
+ RailsDirectory.new(@rails_dir)
23
+ end
24
+
25
+ def clean
26
+ FileUtils.remove_entry_secure @dir
27
+ end
28
+ end