-
Notifications
You must be signed in to change notification settings - Fork 82
/
rails-prelaunch-signup-template.rb
2056 lines (1812 loc) · 92.7 KB
/
rails-prelaunch-signup-template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# >---------------------------------------------------------------------------<
#
# _____ _ _
# | __ \ (_) | /\
# | |__) |__ _ _| |___ / \ _ __ _ __ ___
# | _ // _` | | / __| / /\ \ | '_ \| '_ \/ __|
# | | \ \ (_| | | \__ \/ ____ \| |_) | |_) \__ \
# |_| \_\__,_|_|_|___/_/ \_\ .__/| .__/|___/
# | | | |
# |_| |_|
#
# Application template generated by the rails_apps_composer gem.
# Restrain your impulse to make changes to this file; instead,
# make changes to the recipes in the rails_apps_composer gem.
#
# For more information, see:
# https://github.com/RailsApps/rails_apps_composer/
#
# Thank you to Michael Bleigh for leading the way with the RailsWizard gem.
#
# >---------------------------------------------------------------------------<
# >----------------------------[ Initial Setup ]------------------------------<
run 'bundle update'
initializer 'generators.rb', <<-RUBY
Rails.application.config.generators do |g|
end
RUBY
@recipes = ["core", "git", "railsapps", "setup", "readme", "gems", "testing", "email", "models", "controllers", "views", "routes", "frontend", "init", "prelaunch", "saas", "extras"]
@prefs = {:railsapps=>"rails-prelaunch-signup", :dev_webserver=>"webrick", :prod_webserver=>"same", :templates=>"erb", :ban_spiders=>true, :jsruntime=>false, :rvmrc=>true, :github=>false, :quiet_assets=>true}
@gems = []
@diagnostics_recipes = [["example"], ["setup"], ["railsapps"], ["gems", "setup"], ["gems", "readme", "setup"], ["extras", "gems", "readme", "setup"], ["example", "git"], ["git", "setup"], ["git", "railsapps"], ["gems", "git", "setup"], ["gems", "git", "readme", "setup"], ["extras", "gems", "git", "readme", "setup"], ["controllers", "email", "extras", "frontend", "gems", "git", "init", "models", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "core", "email", "extras", "frontend", "gems", "git", "init", "models", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "core", "email", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "core", "email", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "saas", "setup", "testing", "views"], ["controllers", "email", "example", "extras", "frontend", "gems", "git", "init", "models", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "email", "example", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "email", "example", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "saas", "setup", "testing", "views"]]
@diagnostics_prefs = [{:railsapps=>"rails-stripe-membership-saas", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form"}, {:railsapps=>"rails-stripe-membership-saas", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"mandrill", :authentication=>"devise", :devise_modules=>"confirmable", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form"}, {:railsapps=>"rails-prelaunch-signup", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"mandrill", :authentication=>"devise", :devise_modules=>"confirmable", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form"}, {:railsapps=>"rails3-bootstrap-devise-cancan", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form"}, {:railsapps=>"rails3-devise-rspec-cucumber", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"none", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"none", :starter_app=>"users_app", :form_builder=>"none"}, {:railsapps=>"rails3-mongoid-devise", :database=>"mongodb", :orm=>"mongoid", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"none", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"none", :starter_app=>"users_app", :form_builder=>"none"}, {:railsapps=>"rails3-mongoid-omniauth", :database=>"mongodb", :orm=>"mongoid", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"none", :email=>"none", :authentication=>"omniauth", :omniauth_provider=>"twitter", :authorization=>"none", :starter_app=>"users_app", :form_builder=>"none"}, {:railsapps=>"rails3-subdomains", :database=>"mongodb", :orm=>"mongoid", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"none", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"none", :starter_app=>"subdomains_app", :form_builder=>"none"}, {:railsapps=>"none", :database=>"sqlite", :unit_test=>"rspec", :integration=>"rspec-capybara", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"none", :authentication=>"omniauth", :omniauth_provider=>"twitter", :authorization=>"cancan", :form_builder=>"none", :starter_app=>"admin_app"}, {:railsapps=>"none", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"none", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"invitable", :authorization=>"cancan", :form_builder=>"simple_form", :starter_app=>"admin_app"}, {:railsapps=>"none", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :form_builder=>"none", :starter_app=>"admin_app"}, {:railsapps=>"none", :database=>"sqlite", :unit_test=>"test_unit", :integration=>"none", :fixtures=>"none", :frontend=>"bootstrap", :bootstrap=>"less", :email=>"sendgrid", :authentication=>"devise", :devise_modules=>"confirmable", :authorization=>"cancan", :form_builder=>"none", :starter_app=>"admin_app"}]
diagnostics = {}
def recipes; @recipes end
def recipe?(name); @recipes.include?(name) end
def prefs; @prefs end
def prefer(key, value); @prefs[key].eql? value end
def gems; @gems end
def diagnostics_recipes; @diagnostics_recipes end
def diagnostics_prefs; @diagnostics_prefs end
def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
def say_wizard(text); say_custom(@current_recipe || 'composer', text) end
def ask_wizard(question)
ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[1m\033[36m" + " #{question}\033[0m"
end
def yes_wizard?(question)
answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
case answer.downcase
when "yes", "y"
true
when "no", "n"
false
else
yes_wizard?(question)
end
end
def no_wizard?(question); !yes_wizard?(question) end
def multiple_choice(question, choices)
say_custom('question', question)
values = {}
choices.each_with_index do |choice,i|
values[(i + 1).to_s] = choice[1]
say_custom( (i + 1).to_s + ')', choice[0] )
end
answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
values[answer]
end
@current_recipe = nil
@configs = {}
@after_blocks = []
def after_bundler(&block); @after_blocks << [@current_recipe, block]; end
@after_everything_blocks = []
def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end
@before_configs = {}
def before_config(&block); @before_configs[@current_recipe] = block; end
def copy_from(source, destination)
begin
remove_file destination
get source, destination
rescue OpenURI::HTTPError
say_wizard "Unable to obtain #{source}"
end
end
def copy_from_repo(filename, opts = {})
repo = 'https://raw.github.com/RailsApps/rails-composer/master/files/'
repo = opts[:repo] unless opts[:repo].nil?
if (!opts[:prefs].nil?) && (!prefs.has_value? opts[:prefs])
return
end
source_filename = filename
destination_filename = filename
unless opts[:prefs].nil?
if filename.include? opts[:prefs]
destination_filename = filename.gsub(/\-#{opts[:prefs]}/, '')
end
end
if (prefer :templates, 'haml') && (filename.include? 'views')
remove_file destination_filename
destination_filename = destination_filename.gsub(/.erb/, '.haml')
end
if (prefer :templates, 'slim') && (filename.include? 'views')
remove_file destination_filename
destination_filename = destination_filename.gsub(/.erb/, '.slim')
end
begin
remove_file destination_filename
if (prefer :templates, 'haml') && (filename.include? 'views')
create_file destination_filename, html_to_haml(repo + source_filename)
elsif (prefer :templates, 'slim') && (filename.include? 'views')
create_file destination_filename, html_to_slim(repo + source_filename)
else
get repo + source_filename, destination_filename
end
rescue OpenURI::HTTPError
say_wizard "Unable to obtain #{source_filename} from the repo #{repo}"
end
end
def html_to_haml(source)
html = open(source) {|input| input.binmode.read }
Haml::HTML.new(html, :erb => true, :xhtml => true).render
end
def html_to_slim(source)
html = open(source) {|input| input.binmode.read }
haml = Haml::HTML.new(html, :erb => true, :xhtml => true).render
Haml2Slim.convert!(haml)
end
if diagnostics_recipes.sort.include? recipes.sort
diagnostics[:recipes] = 'success'
say_wizard("WOOT! The recipes you've selected are known to work together.")
else
diagnostics[:recipes] = 'fail'
say_wizard("\033[1m\033[36m" + "WARNING! The recipes you've selected might not work together." + "\033[0m")
say_wizard("Help us out by reporting whether this combination works or fails.")
say_wizard("Please open an issue for rails_apps_composer on GitHub.")
say_wizard("Your new application will contain diagnostics in its README file.")
say_wizard("Continuing...")
end
# this application template only supports Rails version 3.1 and newer
case Rails::VERSION::MAJOR.to_s
when "3"
case Rails::VERSION::MINOR.to_s
when "0"
say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer."
raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer."
end
else
say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer."
raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer."
end
say_wizard "Using rails_apps_composer recipes to generate an application."
# >---------------------------[ Autoload Modules/Classes ]-----------------------------<
inject_into_file 'config/application.rb', :after => 'config.autoload_paths += %W(#{config.root}/extras)' do <<-'RUBY'
config.autoload_paths += %W(#{config.root}/lib)
RUBY
end
# >---------------------------------[ Recipes ]----------------------------------<
# >---------------------------------[ core ]----------------------------------<
@current_recipe = "core"
@before_configs["core"].call if @before_configs["core"]
say_recipe 'core'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/core.rb
## Git
say_wizard "selected all core recipes"
# >----------------------------------[ git ]----------------------------------<
@current_recipe = "git"
@before_configs["git"].call if @before_configs["git"]
say_recipe 'git'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/git.rb
## Git
say_wizard "initialize git"
prefs[:git] = true unless prefs.has_key? :git
if prefer :git, true
copy_from 'https://raw.github.com/RailsApps/rails-composer/master/files/gitignore.txt', '.gitignore'
git :init
git :add => '-A'
git :commit => '-qm "rails_apps_composer: initial commit"'
end
# >-------------------------------[ railsapps ]-------------------------------<
@current_recipe = "railsapps"
@before_configs["railsapps"].call if @before_configs["railsapps"]
say_recipe 'railsapps'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/railsapps.rb
prefs[:railsapps] = multiple_choice "Install an example application?",
[["I want to build my own application", "none"],
["rails-stripe-membership-saas", "rails-stripe-membership-saas"],
["rails-prelaunch-signup", "rails-prelaunch-signup"],
["rails3-bootstrap-devise-cancan", "rails3-bootstrap-devise-cancan"],
["rails3-devise-rspec-cucumber", "rails3-devise-rspec-cucumber"],
["rails3-mongoid-devise", "rails3-mongoid-devise"],
["rails3-mongoid-omniauth", "rails3-mongoid-omniauth"],
["rails3-subdomains", "rails3-subdomains"]] unless prefs.has_key? :railsapps
case prefs[:railsapps]
when 'rails-stripe-membership-saas'
prefs[:git] = true
prefs[:database] = 'sqlite'
prefs[:unit_test] = 'rspec'
prefs[:integration] = 'cucumber'
prefs[:fixtures] = 'factory_girl'
prefs[:frontend] = 'bootstrap'
prefs[:bootstrap] = 'sass'
prefs[:email] = 'gmail'
prefs[:authentication] = 'devise'
prefs[:devise_modules] = 'default'
prefs[:authorization] = 'cancan'
prefs[:starter_app] = 'admin_app'
prefs[:form_builder] = 'simple_form'
prefs[:quiet_assets] = true
when 'rails-prelaunch-signup'
prefs[:git] = true
prefs[:database] = 'sqlite'
prefs[:unit_test] = 'rspec'
prefs[:integration] = 'cucumber'
prefs[:fixtures] = 'factory_girl'
prefs[:frontend] = 'bootstrap'
prefs[:bootstrap] = 'sass'
prefs[:email] = 'mandrill'
prefs[:authentication] = 'devise'
prefs[:devise_modules] = 'confirmable'
prefs[:authorization] = 'cancan'
prefs[:starter_app] = 'admin_app'
prefs[:form_builder] = 'simple_form'
prefs[:quiet_assets] = true
if prefer :git, true
prefs[:prelaunch_branch] = multiple_choice "Git branch for the prelaunch app?", [["wip (work-in-progress)", "wip"], ["master", "master"], ["prelaunch", "prelaunch"], ["staging", "staging"]]
if prefs[:prelaunch_branch] == 'master'
prefs[:main_branch] = multiple_choice "Git branch for the main app?", [["None", "none"], ["wip (work-in-progress)", "wip"], ["edge", "edge"]]
else
prefs[:main_branch] = 'master'
end
end
when 'rails3-bootstrap-devise-cancan'
prefs[:git] = true
prefs[:database] = 'sqlite'
prefs[:unit_test] = 'rspec'
prefs[:integration] = 'cucumber'
prefs[:fixtures] = 'factory_girl'
prefs[:frontend] = 'bootstrap'
prefs[:bootstrap] = 'sass'
prefs[:email] = 'gmail'
prefs[:authentication] = 'devise'
prefs[:devise_modules] = 'default'
prefs[:authorization] = 'cancan'
prefs[:starter_app] = 'admin_app'
prefs[:form_builder] = 'simple_form'
prefs[:quiet_assets] = true
when 'rails3-devise-rspec-cucumber'
prefs[:git] = true
prefs[:database] = 'sqlite'
prefs[:unit_test] = 'rspec'
prefs[:integration] = 'cucumber'
prefs[:fixtures] = 'factory_girl'
prefs[:frontend] = 'none'
prefs[:email] = 'gmail'
prefs[:authentication] = 'devise'
prefs[:devise_modules] = 'default'
prefs[:authorization] = 'none'
prefs[:starter_app] = 'users_app'
prefs[:form_builder] = 'none'
prefs[:quiet_assets] = true
when 'rails3-devise-rspec-cucumber-fabrication'
prefs[:git] = true
prefs[:database] = 'sqlite'
prefs[:unit_test] = 'rspec'
prefs[:integration] = 'cucumber'
prefs[:fixtures] = 'fabrication'
prefs[:frontend] = 'none'
prefs[:email] = 'gmail'
prefs[:authentication] = 'devise'
prefs[:devise_modules] = 'default'
prefs[:authorization] = 'none'
prefs[:starter_app] = 'users_app'
prefs[:form_builder] = 'none'
prefs[:quiet_assets] = true
when 'rails3-mongoid-devise'
prefs[:git] = true
prefs[:database] = 'mongodb'
prefs[:orm] = 'mongoid'
prefs[:unit_test] = 'rspec'
prefs[:integration] = 'cucumber'
prefs[:fixtures] = 'factory_girl'
prefs[:frontend] = 'none'
prefs[:email] = 'gmail'
prefs[:authentication] = 'devise'
prefs[:devise_modules] = 'default'
prefs[:authorization] = 'none'
prefs[:starter_app] = 'users_app'
prefs[:form_builder] = 'none'
prefs[:quiet_assets] = true
when 'rails3-mongoid-omniauth'
prefs[:git] = true
prefs[:database] = 'mongodb'
prefs[:orm] = 'mongoid'
prefs[:unit_test] = 'rspec'
prefs[:integration] = 'cucumber'
prefs[:fixtures] = 'factory_girl'
prefs[:frontend] = 'none'
prefs[:email] = 'none'
prefs[:authentication] = 'omniauth'
prefs[:omniauth_provider] = 'twitter'
prefs[:authorization] = 'none'
prefs[:starter_app] = 'users_app'
prefs[:form_builder] = 'none'
prefs[:quiet_assets] = true
when 'rails3-subdomains'
prefs[:git] = true
prefs[:database] = 'mongodb'
prefs[:orm] = 'mongoid'
prefs[:unit_test] = 'rspec'
prefs[:integration] = 'cucumber'
prefs[:fixtures] = 'factory_girl'
prefs[:frontend] = 'none'
prefs[:email] = 'gmail'
prefs[:authentication] = 'devise'
prefs[:devise_modules] = 'default'
prefs[:authorization] = 'none'
prefs[:starter_app] = 'subdomains_app'
prefs[:form_builder] = 'none'
prefs[:quiet_assets] = true
end
# >---------------------------------[ setup ]---------------------------------<
@current_recipe = "setup"
@before_configs["setup"].call if @before_configs["setup"]
say_recipe 'setup'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/setup.rb
## Ruby on Rails
HOST_OS = RbConfig::CONFIG['host_os']
say_wizard "Your operating system is #{HOST_OS}."
say_wizard "You are using Ruby version #{RUBY_VERSION}."
say_wizard "You are using Rails version #{Rails::VERSION::STRING}."
## Is sqlite3 in the Gemfile?
gemfile = File.read(destination_root() + '/Gemfile')
sqlite_detected = gemfile.include? 'sqlite3'
## Web Server
prefs[:dev_webserver] = multiple_choice "Web server for development?", [["WEBrick (default)", "webrick"],
["Thin", "thin"], ["Unicorn", "unicorn"], ["Puma", "puma"]] unless prefs.has_key? :dev_webserver
webserver = multiple_choice "Web server for production?", [["Same as development", "same"],
["Thin", "thin"], ["Unicorn", "unicorn"], ["Puma", "puma"]] unless prefs.has_key? :prod_webserver
if webserver == 'same'
case prefs[:dev_webserver]
when 'thin'
prefs[:prod_webserver] = 'thin'
when 'unicorn'
prefs[:prod_webserver] = 'unicorn'
when 'puma'
prefs[:prod_webserver] = 'puma'
end
else
prefs[:prod_webserver] = webserver
end
## Database Adapter
prefs[:database] = multiple_choice "Database used in development?", [["SQLite", "sqlite"], ["PostgreSQL", "postgresql"],
["MySQL", "mysql"], ["MongoDB", "mongodb"]] unless prefs.has_key? :database
case prefs[:database]
when 'mongodb'
unless sqlite_detected
prefs[:orm] = multiple_choice "How will you connect to MongoDB?", [["Mongoid","mongoid"]] unless prefs.has_key? :orm
else
say_wizard "WARNING! SQLite gem detected in the Gemfile"
say_wizard "If you wish to use MongoDB you must skip Active Record."
say_wizard "If using rails_apps_composer, choose 'skip Active Record'."
say_wizard "If using Rails Composer or an application template, use the '-O' flag as in 'rails new foo -O'."
prefs[:fail] = multiple_choice "Abort or continue?", [["abort", "abort"], ["continue", "continue"]]
if prefer :fail, 'abort'
raise StandardError.new "SQLite detected in the Gemfile. Use '-O' or '--skip-activerecord' as in 'rails new foo -O' if you don't want ActiveRecord and SQLite"
end
end
end
## Template Engine
prefs[:templates] = multiple_choice "Template engine?", [["ERB", "erb"], ["Haml", "haml"], ["Slim (experimental)", "slim"]] unless prefs.has_key? :templates
## Testing Framework
if recipes.include? 'testing'
prefs[:unit_test] = multiple_choice "Unit testing?", [["Test::Unit", "test_unit"], ["RSpec", "rspec"], ["MiniTest", "minitest"]] unless prefs.has_key? :unit_test
prefs[:integration] = multiple_choice "Integration testing?", [["None", "none"], ["RSpec with Capybara", "rspec-capybara"],
["Cucumber with Capybara", "cucumber"], ["Turnip with Capybara", "turnip"], ["MiniTest with Capybara", "minitest-capybara"]] unless prefs.has_key? :integration
prefs[:fixtures] = multiple_choice "Fixture replacement?", [["None","none"], ["Factory Girl","factory_girl"], ["Machinist","machinist"], ["Fabrication","fabrication"]] unless prefs.has_key? :fixtures
end
## Front-end Framework
if recipes.include? 'frontend'
prefs[:frontend] = multiple_choice "Front-end framework?", [["None", "none"], ["Twitter Bootstrap", "bootstrap"],
["Zurb Foundation", "foundation"], ["Skeleton", "skeleton"], ["Just normalize CSS for consistent styling", "normalize"]] unless prefs.has_key? :frontend
if prefer :frontend, 'bootstrap'
case HOST_OS
when /mswin|windows/i
prefs[:bootstrap] = multiple_choice "Twitter Bootstrap version?", [["Twitter Bootstrap (Sass)", "sass"]] unless prefs.has_key? :bootstrap
else
prefs[:bootstrap] = multiple_choice "Twitter Bootstrap version?", [["Twitter Bootstrap (Less)", "less"],
["Twitter Bootstrap (Sass)", "sass"]] unless prefs.has_key? :bootstrap
end
end
end
## Email
if recipes.include? 'email'
prefs[:email] = multiple_choice "Add support for sending email?", [["None", "none"], ["Gmail","gmail"], ["SMTP","smtp"],
["SendGrid","sendgrid"], ["Mandrill","mandrill"]] unless prefs.has_key? :email
else
prefs[:email] = 'none'
end
## Authentication and Authorization
if recipes.include? 'models'
prefs[:authentication] = multiple_choice "Authentication?", [["None", "none"], ["Devise", "devise"], ["OmniAuth", "omniauth"]] unless prefs.has_key? :authentication
case prefs[:authentication]
when 'devise'
if prefer :orm, 'mongoid'
prefs[:devise_modules] = multiple_choice "Devise modules?", [["Devise with default modules","default"]] unless prefs.has_key? :devise_modules
else
prefs[:devise_modules] = multiple_choice "Devise modules?", [["Devise with default modules","default"], ["Devise with Confirmable module","confirmable"],
["Devise with Confirmable and Invitable modules","invitable"]] unless prefs.has_key? :devise_modules
end
when 'omniauth'
prefs[:omniauth_provider] = multiple_choice "OmniAuth provider?", [["Facebook", "facebook"], ["Twitter", "twitter"], ["GitHub", "github"],
["LinkedIn", "linkedin"], ["Google-Oauth-2", "google_oauth2"], ["Tumblr", "tumblr"]] unless prefs.has_key? :omniauth_provider
end
prefs[:authorization] = multiple_choice "Authorization?", [["None", "none"], ["CanCan with Rolify", "cancan"]] unless prefs.has_key? :authorization
end
## Form Builder
prefs[:form_builder] = multiple_choice "Use a form builder gem?", [["None", "none"], ["SimpleForm", "simple_form"]] unless prefs.has_key? :form_builder
## MVC
if (recipes.include? 'models') && (recipes.include? 'controllers') && (recipes.include? 'views') && (recipes.include? 'routes')
if prefer :authorization, 'cancan'
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
["Home Page, User Accounts", "users_app"], ["Home Page, User Accounts, Admin Dashboard", "admin_app"]] unless prefs.has_key? :starter_app
elsif prefer :authentication, 'devise'
if prefer :orm, 'mongoid'
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
["Home Page, User Accounts", "users_app"], ["Home Page, User Accounts, Subdomains", "subdomains_app"]] unless prefs.has_key? :starter_app
else
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
["Home Page, User Accounts", "users_app"]] unless prefs.has_key? :starter_app
end
elsif prefer :authentication, 'omniauth'
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
["Home Page, User Accounts", "users_app"]] unless prefs.has_key? :starter_app
else
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"]] unless prefs.has_key? :starter_app
end
end
# save diagnostics before anything can fail
create_file "README", "RECIPES\n#{recipes.sort.inspect}\n"
append_file "README", "PREFERENCES\n#{prefs.inspect}"
# >--------------------------------[ readme ]---------------------------------<
@current_recipe = "readme"
@before_configs["readme"].call if @before_configs["readme"]
say_recipe 'readme'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/readme.rb
after_everything do
say_wizard "recipe running after everything"
# remove default READMEs
%w{
README
README.rdoc
doc/README_FOR_APP
}.each { |file| remove_file file }
# add placeholder READMEs and humans.txt file
copy_from_repo 'public/humans.txt'
copy_from_repo 'README'
copy_from_repo 'README.textile'
gsub_file "README", /App_Name/, "#{app_name.humanize.titleize}"
gsub_file "README.textile", /App_Name/, "#{app_name.humanize.titleize}"
# Diagnostics
gsub_file "README.textile", /recipes that are known/, "recipes that are NOT known" if diagnostics[:recipes] == 'fail'
gsub_file "README.textile", /preferences that are known/, "preferences that are NOT known" if diagnostics[:prefs] == 'fail'
gsub_file "README.textile", /RECIPES/, recipes.sort.inspect
gsub_file "README.textile", /PREFERENCES/, prefs.inspect
gsub_file "README", /RECIPES/, recipes.sort.inspect
gsub_file "README", /PREFERENCES/, prefs.inspect
# Ruby on Rails
gsub_file "README.textile", /\* Ruby/, "* Ruby version #{RUBY_VERSION}"
gsub_file "README.textile", /\* Rails/, "* Rails version #{Rails::VERSION::STRING}"
# Database
gsub_file "README.textile", /SQLite/, "PostgreSQL" if prefer :database, 'postgresql'
gsub_file "README.textile", /SQLite/, "MySQL" if prefer :database, 'mysql'
gsub_file "README.textile", /SQLite/, "MongoDB" if prefer :database, 'mongodb'
gsub_file "README.textile", /ActiveRecord/, "the Mongoid ORM" if prefer :orm, 'mongoid'
# Template Engine
gsub_file "README.textile", /ERB/, "Haml" if prefer :templates, 'haml'
gsub_file "README.textile", /ERB/, "Slim" if prefer :templates, 'slim'
# Testing Framework
gsub_file "README.textile", /Test::Unit/, "RSpec" if prefer :unit_test, 'rspec'
gsub_file "README.textile", /RSpec/, "RSpec and Cucumber" if prefer :integration, 'cucumber'
gsub_file "README.textile", /RSpec/, "RSpec and Factory Girl" if prefer :fixtures, 'factory_girl'
gsub_file "README.textile", /RSpec/, "RSpec and Machinist" if prefer :fixtures, 'machinist'
# Front-end Framework
gsub_file "README.textile", /Front-end Framework: None/, "Front-end Framework: Twitter Bootstrap (Sass)" if prefer :bootstrap, 'sass'
gsub_file "README.textile", /Front-end Framework: None/, "Front-end Framework: Twitter Bootstrap (Less)" if prefer :bootstrap, 'less'
gsub_file "README.textile", /Front-end Framework: None/, "Front-end Framework: Zurb Foundation" if prefer :frontend, 'foundation'
gsub_file "README.textile", /Front-end Framework: None/, "Front-end Framework: Skeleton" if prefer :frontend, 'skeleton'
gsub_file "README.textile", /Front-end Framework: None/, "Front-end Framework: Normalized CSS" if prefer :frontend, 'normalize'
# Form Builder
gsub_file "README.textile", /Form Builder: None/, "Form Builder: SimpleForm" if prefer :form_builder, 'simple_form'
# Email
unless prefer :email, 'none'
gsub_file "README.textile", /Gmail/, "SMTP" if prefer :email, 'smtp'
gsub_file "README.textile", /Gmail/, "SendGrid" if prefer :email, 'sendgrid'
gsub_file "README.textile", /Gmail/, "Mandrill" if prefer :email, 'mandrill'
else
gsub_file "README.textile", /h2. Email/, ""
gsub_file "README.textile", /The application is configured to send email using a Gmail account./, ""
end
# Authentication and Authorization
gsub_file "README.textile", /Authentication: None/, "Authentication: Devise" if prefer :authentication, 'devise'
gsub_file "README.textile", /Authentication: None/, "Authentication: OmniAuth" if prefer :authentication, 'omniauth'
gsub_file "README.textile", /Authorization: None/, "Authorization: CanCan" if prefer :authorization, 'cancan'
git :add => '-A' if prefer :git, true
git :commit => '-qm "rails_apps_composer: add README files"' if prefer :git, true
end # after_everything
# >---------------------------------[ gems ]----------------------------------<
@current_recipe = "gems"
@before_configs["gems"].call if @before_configs["gems"]
say_recipe 'gems'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/gems.rb
### GEMFILE ###
## Ruby on Rails
insert_into_file 'Gemfile', "ruby '1.9.3'\n", :before => "gem 'rails', '3.2.6'" if prefer :deploy, 'heroku'
## Web Server
if (prefs[:dev_webserver] == prefs[:prod_webserver])
gem 'thin', '>= 1.5.0' if prefer :dev_webserver, 'thin'
gem 'unicorn', '>= 4.3.1' if prefer :dev_webserver, 'unicorn'
gem 'puma', '>= 1.6.3' if prefer :dev_webserver, 'puma'
else
gem 'thin', '>= 1.5.0', :group => [:development, :test] if prefer :dev_webserver, 'thin'
gem 'unicorn', '>= 4.3.1', :group => [:development, :test] if prefer :dev_webserver, 'unicorn'
gem 'puma', '>= 1.6.3', :group => [:development, :test] if prefer :dev_webserver, 'puma'
gem 'thin', '>= 1.5.0', :group => :production if prefer :prod_webserver, 'thin'
gem 'unicorn', '>= 4.3.1', :group => :production if prefer :prod_webserver, 'unicorn'
gem 'puma', '>= 1.6.3', :group => :production if prefer :prod_webserver, 'puma'
end
## Database Adapter
gsub_file 'Gemfile', /gem 'sqlite3'\n/, '' unless prefer :database, 'sqlite'
gem 'mongoid', '>= 3.0.9' if prefer :orm, 'mongoid'
gem 'pg', '>= 0.14.1' if prefer :database, 'postgresql'
gem 'mysql2', '>= 0.3.11' if prefer :database, 'mysql'
## Template Engine
if prefer :templates, 'haml'
gem 'haml', '>= 3.1.7'
gem 'haml-rails', '>= 0.3.5', :group => :development
# hpricot and ruby_parser are needed for conversion of HTML to Haml
gem 'hpricot', '>= 0.8.6', :group => :development
gem 'ruby_parser', '>= 2.3.1', :group => :development
end
if prefer :templates, 'slim'
gem 'slim', '>= 1.3.3'
gem 'haml2slim', '>= 0.4.6', :group => :development
# Haml is needed for conversion of HTML to Slim
gem 'haml', '>= 3.1.6', :group => :development
gem 'haml-rails', '>= 0.3.5', :group => :development
gem 'hpricot', '>= 0.8.6', :group => :development
gem 'ruby_parser', '>= 2.3.1', :group => :development
end
## Testing Framework
if prefer :unit_test, 'rspec'
gem 'rspec-rails', '>= 2.11.4', :group => [:development, :test]
gem 'capybara', '>= 1.1.2', :group => :test if prefer :integration, 'rspec-capybara'
if prefer :orm, 'mongoid'
# use the database_cleaner gem to reset the test database
gem 'database_cleaner', '>= 0.9.1', :group => :test
# include RSpec matchers from the mongoid-rspec gem
gem 'mongoid-rspec', '>= 1.4.6', :group => :test
end
gem 'email_spec', '>= 1.2.1', :group => :test
end
if prefer :unit_test, 'minitest'
gem 'minitest-spec-rails', '>= 3.0.7', :group => :test
gem 'minitest-wscolor', '>= 0.0.3', :group => :test
gem 'capybara', '>= 1.1.2', :group => :test if prefer :integration, 'minitest-capybara'
end
if prefer :integration, 'cucumber'
gem 'cucumber-rails', '>= 1.3.0', :group => :test, :require => false
gem 'database_cleaner', '>= 0.9.1', :group => :test unless prefer :orm, 'mongoid'
gem 'launchy', '>= 2.1.2', :group => :test
gem 'capybara', '>= 1.1.2', :group => :test
end
gem 'turnip', '>= 1.0.0', :group => :test if prefer :integration, 'turnip'
gem 'factory_girl_rails', '>= 4.1.0', :group => [:development, :test] if prefer :fixtures, 'factory_girl'
gem 'fabrication', '>= 2.3.0', :group => [:development, :test] if prefer :fixtures, 'fabrication'
gem 'machinist', '>= 2.0', :group => :test if prefer :fixtures, 'machinist'
## Front-end Framework
gem 'bootstrap-sass', '>= 2.1.0.1' if prefer :bootstrap, 'sass'
gem 'compass-rails', '>= 1.0.3', :group => :assets if prefer :frontend, 'foundation'
gem 'zurb-foundation', '>= 3.2.0', :group => :assets if prefer :frontend, 'foundation'
if prefer :bootstrap, 'less'
gem 'twitter-bootstrap-rails', '>= 2.1.4', :group => :assets
# install gem 'therubyracer' to use Less
gem 'therubyracer', '>= 0.10.2', :group => :assets, :platform => :ruby
end
## Email
gem 'sendgrid', '>= 1.0.1' if prefer :email, 'sendgrid'
gem 'hominid', '>= 3.0.5' if prefer :email, 'mandrill'
## Authentication (Devise)
gem 'devise', '>= 2.1.2' if prefer :authentication, 'devise'
gem 'devise_invitable', '>= 1.1.1' if prefer :devise_modules, 'invitable'
## Authentication (OmniAuth)
gem 'omniauth', '>= 1.1.1' if prefer :authentication, 'omniauth'
gem 'omniauth-twitter' if prefer :omniauth_provider, 'twitter'
gem 'omniauth-facebook' if prefer :omniauth_provider, 'facebook'
gem 'omniauth-github' if prefer :omniauth_provider, 'github'
gem 'omniauth-linkedin' if prefer :omniauth_provider, 'linkedin'
gem 'omniauth-google-oauth2' if prefer :omniauth_provider, 'google_oauth2'
gem 'omniauth-tumblr' if prefer :omniauth_provider, 'tumblr'
## Authorization
if prefer :authorization, 'cancan'
gem 'cancan', '>= 1.6.8'
gem 'rolify', '>= 3.2.0'
end
## Form Builder
gem 'simple_form', '>= 2.0.4' if prefer :form_builder, 'simple_form'
## Membership App
if prefer :railsapps, 'rails-stripe-membership-saas'
gem 'stripe', '>= 1.7.4'
gem 'stripe_event', '>= 0.4.0'
end
## Signup App
if prefer :railsapps, 'rails-prelaunch-signup'
gem 'google_visualr', '>= 2.1.2'
gem 'jquery-datatables-rails', '>= 1.11.1'
end
## Gems from a defaults file or added interactively
gems.each do |g|
gem g
end
## Git
git :add => '-A' if prefer :git, true
git :commit => '-qm "rails_apps_composer: Gemfile"' if prefer :git, true
### CREATE DATABASE ###
after_bundler do
copy_from_repo 'config/database-postgresql.yml', :prefs => 'postgresql'
copy_from_repo 'config/database-mysql.yml', :prefs => 'mysql'
generate 'mongoid:config' if prefer :orm, 'mongoid'
remove_file 'config/database.yml' if prefer :orm, 'mongoid'
if prefer :database, 'postgresql'
begin
pg_username = ask_wizard("Username for PostgreSQL? (leave blank to use the app name)")
if pg_username.blank?
say_wizard "Creating a user named '#{app_name}' for PostgreSQL"
run "createuser #{app_name}" if prefer :database, 'postgresql'
gsub_file "config/database.yml", /username: .*/, "username: #{app_name}"
else
gsub_file "config/database.yml", /username: .*/, "username: #{pg_username}"
pg_password = ask_wizard("Password for PostgreSQL user #{pg_username}?")
gsub_file "config/database.yml", /password:/, "password: #{pg_password}"
say_wizard "set config/database.yml for username/password #{pg_username}/#{pg_password}"
end
rescue StandardError => e
raise "unable to create a user for PostgreSQL, reason: #{e}"
end
gsub_file "config/database.yml", /database: myapp_development/, "database: #{app_name}_development"
gsub_file "config/database.yml", /database: myapp_test/, "database: #{app_name}_test"
gsub_file "config/database.yml", /database: myapp_production/, "database: #{app_name}_production"
end
if prefer :database, 'mysql'
mysql_username = ask_wizard("Username for MySQL? (leave blank to use the app name)")
if mysql_username.blank?
gsub_file "config/database.yml", /username: .*/, "username: #{app_name}"
else
gsub_file "config/database.yml", /username: .*/, "username: #{mysql_username}"
mysql_password = ask_wizard("Password for MySQL user #{mysql_username}?")
gsub_file "config/database.yml", /password:/, "password: #{mysql_password}"
say_wizard "set config/database.yml for username/password #{mysql_username}/#{mysql_password}"
end
gsub_file "config/database.yml", /database: myapp_development/, "database: #{app_name}_development"
gsub_file "config/database.yml", /database: myapp_test/, "database: #{app_name}_test"
gsub_file "config/database.yml", /database: myapp_production/, "database: #{app_name}_production"
end
unless prefer :database, 'sqlite'
affirm = yes_wizard? "Drop any existing databases named #{app_name}?"
if affirm
run 'bundle exec rake db:drop'
else
raise "aborted at user's request"
end
end
run 'bundle exec rake db:create:all' unless prefer :orm, 'mongoid'
run 'bundle exec rake db:create' if prefer :orm, 'mongoid'
## Git
git :add => '-A' if prefer :git, true
git :commit => '-qm "rails_apps_composer: create database"' if prefer :git, true
end # after_bundler
### GENERATORS ###
after_bundler do
## Front-end Framework
generate 'foundation:install' if prefer :frontend, 'foundation'
## Form Builder
if prefer :form_builder, 'simple_form'
if prefer :frontend, 'bootstrap'
say_wizard "recipe installing simple_form for use with Twitter Bootstrap"
generate 'simple_form:install --bootstrap'
else
say_wizard "recipe installing simple_form"
generate 'simple_form:install'
end
end
## Git
git :add => '-A' if prefer :git, true
git :commit => '-qm "rails_apps_composer: generators"' if prefer :git, true
end # after_bundler
# >--------------------------------[ testing ]--------------------------------<
@current_recipe = "testing"
@before_configs["testing"].call if @before_configs["testing"]
say_recipe 'testing'
@configs[@current_recipe] = config
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/testing.rb
after_bundler do
say_wizard "recipe running after 'bundle install'"
### TEST/UNIT ###
if prefer :unit_test, 'test_unit'
inject_into_file 'config/application.rb', :after => "Rails::Application\n" do <<-RUBY
config.generators do |g|
#{"g.test_framework :test_unit, fixture_replacement: :fabrication" if prefer :fixtures, 'fabrication'}
#{"g.fixture_replacement :fabrication, dir: 'test/fabricators'" if prefer :fixtures, 'fabrication'}
end
RUBY
end
end
### RSPEC ###
if prefer :unit_test, 'rspec'
say_wizard "recipe installing RSpec"
generate 'rspec:install'
copy_from_repo 'spec/spec_helper.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
generate 'email_spec:steps'
inject_into_file 'spec/spec_helper.rb', "require 'email_spec'\n", :after => "require 'rspec/rails'\n"
inject_into_file 'spec/spec_helper.rb', :after => "RSpec.configure do |config|\n" do <<-RUBY
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
RUBY
end
run 'rm -rf test/' # Removing test folder (not needed for RSpec)
inject_into_file 'config/application.rb', :after => "Rails::Application\n" do <<-RUBY
# don't generate RSpec tests for views and helpers
config.generators do |g|
#{"g.test_framework :rspec" if prefer :fixtures, 'none'}
#{"g.test_framework :rspec, fixture: true" unless prefer :fixtures, 'none'}
#{"g.fixture_replacement :factory_girl" if prefer :fixtures, 'factory_girl'}
#{"g.fixture_replacement :machinist" if prefer :fixtures, 'machinist'}
#{"g.fixture_replacement :fabrication" if prefer :fixtures, 'fabrication'}
g.view_specs false
g.helper_specs false
end
RUBY
end
## RSPEC AND MONGOID
if prefer :orm, 'mongoid'
# remove ActiveRecord artifacts
gsub_file 'spec/spec_helper.rb', /config.fixture_path/, '# config.fixture_path'
gsub_file 'spec/spec_helper.rb', /config.use_transactional_fixtures/, '# config.use_transactional_fixtures'
# remove either possible occurrence of "require rails/test_unit/railtie"
gsub_file 'config/application.rb', /require 'rails\/test_unit\/railtie'/, '# require "rails/test_unit/railtie"'
gsub_file 'config/application.rb', /require "rails\/test_unit\/railtie"/, '# require "rails/test_unit/railtie"'
# configure RSpec to use matchers from the mongoid-rspec gem
create_file 'spec/support/mongoid.rb' do
<<-RUBY
RSpec.configure do |config|
config.include Mongoid::Matchers
end
RUBY
end
end
## RSPEC AND DEVISE
if prefer :authentication, 'devise'
# add Devise test helpers
create_file 'spec/support/devise.rb' do
<<-RUBY
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
RUBY
end
end
end
### CUCUMBER ###
if prefer :integration, 'cucumber'
say_wizard "recipe installing Cucumber"
generate "cucumber:install --capybara#{' --rspec' if prefer :unit_test, 'rspec'}#{' -D' if prefer :orm, 'mongoid'}"
# make it easy to run Cucumber for single features without adding "--require features" to the command line
gsub_file 'config/cucumber.yml', /std_opts = "/, 'std_opts = "-r features/support/ -r features/step_definitions '
create_file 'features/support/email_spec.rb' do <<-RUBY
require 'email_spec/cucumber'
RUBY
end
## CUCUMBER AND MONGOID
if prefer :orm, 'mongoid'
gsub_file 'features/support/env.rb', /transaction/, "truncation"
inject_into_file 'features/support/env.rb', :after => 'begin' do
"\n DatabaseCleaner.orm = 'mongoid'"
end
end
generate 'fabrication:cucumber_steps' if prefer :fixtures, 'fabrication'
end
## TURNIP
if prefer :integration, 'turnip'
append_file '.rspec', '-r turnip/rspec'
inject_into_file 'spec/spec_helper.rb', "require 'turnip/capybara'\n", :after => "require 'rspec/rails'\n"
create_file 'spec/acceptance/steps/.gitkeep'
end
## FIXTURE REPLACEMENTS
if prefer :fixtures, 'machinist'
say_wizard "generating blueprints file for 'machinist'"
generate 'machinist:install'
end
### GIT ###
git :add => '-A' if prefer :git, true
git :commit => '-qm "rails_apps_composer: testing framework"' if prefer :git, true
end # after_bundler
after_everything do
say_wizard "recipe running after everything"
### RSPEC ###
if prefer :unit_test, 'rspec'
if (prefer :authentication, 'devise') && (prefer :starter_app, 'users_app')
say_wizard "copying RSpec files from the rails3-devise-rspec-cucumber examples"
repo = 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
copy_from_repo 'spec/factories/users.rb', :repo => repo
gsub_file 'spec/factories/users.rb', /# confirmed_at/, "confirmed_at" if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
remove_file 'spec/views/home/index.html.erb_spec.rb'
remove_file 'spec/views/home/index.html.haml_spec.rb'
remove_file 'spec/views/users/show.html.erb_spec.rb'
remove_file 'spec/views/users/show.html.haml_spec.rb'
remove_file 'spec/helpers/home_helper_spec.rb'
remove_file 'spec/helpers/users_helper_spec.rb'
end
if (prefer :authentication, 'devise') && (prefer :starter_app, 'admin_app')
say_wizard "copying RSpec files from the rails3-bootstrap-devise-cancan examples"
repo = 'https://raw.github.com/RailsApps/rails3-bootstrap-devise-cancan/master/'
copy_from_repo 'spec/factories/users.rb', :repo => repo
gsub_file 'spec/factories/users.rb', /# confirmed_at/, "confirmed_at" if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
remove_file 'spec/views/home/index.html.erb_spec.rb'
remove_file 'spec/views/home/index.html.haml_spec.rb'
remove_file 'spec/views/users/show.html.erb_spec.rb'
remove_file 'spec/views/users/show.html.haml_spec.rb'
remove_file 'spec/helpers/home_helper_spec.rb'
remove_file 'spec/helpers/users_helper_spec.rb'
end
## RSPEC AND OMNIAUTH
if (prefer :authentication, 'omniauth') && (prefer :starter_app, 'users_app')
say_wizard "copying RSpec files from the rails3-mongoid-omniauth examples"
repo = 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
copy_from_repo 'spec/factories/users.rb', :repo => repo
copy_from_repo 'spec/controllers/sessions_controller_spec.rb', :repo => repo
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
end
## SUBDOMAINS
if (prefer :authentication, 'devise') && (prefer :starter_app, 'subdomains_app')
say_wizard "copying RSpec files from the rails3-subdomains examples"
repo = 'https://raw.github.com/RailsApps/rails3-subdomains/master/'
copy_from_repo 'spec/factories/users.rb', :repo => repo
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
end
## GIT
git :add => '-A' if prefer :git, true
git :commit => '-qm "rails_apps_composer: rspec files"' if prefer :git, true
end
### CUCUMBER ###
if prefer :integration, 'cucumber'
## CUCUMBER AND DEVISE (USERS APP)
if (prefer :authentication, 'devise') && (prefer :starter_app, 'users_app')
say_wizard "copying Cucumber scenarios from the rails3-devise-rspec-cucumber examples"
repo = 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
copy_from_repo 'features/users/sign_in.feature', :repo => repo