mech (owner)

Fork Of

gist: 145676 by ffmike MOVED TO http://github.com/...

Revisions

  • 73f061 ffmike Sun Jul 12 08:58:28 -0700 2009
gist: 145914 Download_button fork
public
Public Clone URL: git://gist.github.com/145914.git
Embed All Files: show embed
lark_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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
 
require 'open-uri'
 
def download(from, to = from.split("/").last)
  #run "curl -s -L #{from} > #{to}"
  file to, open(from).read
rescue
  puts "Can't get #{from} - Internet down?"
  exit!
end
 
def from_repo(github_user, from, to = from.split("/").last)
  download("http://github.com/#{github_user}/rails-template/raw/master/#{from}", to)
end
 
def commit_state(comment)
  git :add => "."
  git :commit => "-am '#{comment}'"
end
 
# piston methods out of my own head
# TODO: Lock pistoned repos
def piston_plugin(name, options)
  log 'plugin installed with piston', name
 
  if options[:git] || options[:svn]
    in_root do
      run("piston import #{options[:svn] || options[:git]} vendor/plugins/#{name}")
      commit_state("Added pistoned #{name}")
    end
  else
    log "! no git or svn provided for #{name}. skipping..."
  end
end
 
def piston_rails(options)
  log 'rails installed with piston', options[:branch]
 
  in_root do
    run("piston import --commit #{options[:branch]} git://github.com/rails/rails.git vendor/rails")
  end
end
 
# TODO Core really should handle this
current_app_name = ask("What is the application name?")
 
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
 
# Set up git repository
# must do before running piston
git :init
 
# plugins
piston_plugin 'admin_data',
  :git => 'git://github.com/neerajdotname/admin_data.git'
piston_plugin 'db-populate',
  :git => 'git://github.com/ffmike/db-populate.git'
piston_plugin 'exceptional',
  :git => 'git://github.com/contrast/exceptional.git'
piston_plugin 'fast_remote_cache',
  :git => 'git://github.com/37signals/fast_remote_cache.git'
piston_plugin 'live-validations',
  :git => 'git://github.com/augustl/live-validations.git'
plugin 'newrelic_rpm',
  :svn => 'http://newrelic.rubyforge.org/svn/newrelic_rpm'
piston_plugin 'object_daddy',
  :git => 'git://github.com/flogic/object_daddy.git'
piston_plugin 'paperclip',
  :git => 'git://github.com/thoughtbot/paperclip.git'
piston_plugin 'parallel_test',
  :git => 'git://github.com/jasonm/parallel_test.git'
piston_plugin 'rack-bug',
  :git => 'git://github.com/brynary/rack-bug.git'
piston_plugin 'rubaidhstrano',
  :git => 'git://github.com/rubaidh/rubaidhstrano.git'
piston_plugin 'shmacros',
  :git => 'git://github.com/maxim/shmacros.git'
piston_plugin 'stringex',
  :git => 'git://github.com/rsl/stringex.git'
piston_plugin 'superdeploy',
  :git => 'git://github.com/saizai/superdeploy.git'
  
# gems
gem 'authlogic',
  :version => '~> 2.0'
gem 'mislav-will_paginate',
  :version => '~> 2.2',
  :lib => 'will_paginate',
  :source => 'http://gems.github.com'
gem 'jscruggs-metric_fu',
  :version => '~> 1.1',
  :lib => 'metric_fu',
  :source => 'http://gems.github.com'
gem "binarylogic-searchlogic",
  :lib => 'searchlogic',
  :source => 'http://gems.github.com',
  :version => '~> 2.0'
# development only
gem "cwninja-inaction_mailer",
  :lib => 'inaction_mailer/force_load',
  :source => 'http://gems.github.com',
  :env => 'development'
 
# assume gems are already on dev box, so don't install
# rake("gems:install", :sudo => true)
 
# Set up gitignore and commit base state
file '.gitignore', <<-END
log/*.log
tmp/**/*
.DS\_Store
.DS_Store
db/test.sqlite3
db/development.sqlite3
/log/*.pid
/coverage/*
public/system/*
.idea/*
tmp/metric_fu/*
tmp/sent_mails/*
END
 
commit_state "Base application with plugins and gems"
 
# some files for app
download "http://livevalidation.com/javascripts/src/1.3/livevalidation_prototype.js", "public/javascripts/livevalidation.js"
 
file 'app/views/layouts/_flashes.html.erb', <<-END
<div id="flash">
<% flash.each do |key, value| -%>
<div id="flash_<%= key %>"><%=h value %></div>
<% end -%>
</div>
END
 
file 'app/views/layouts/application.html.erb', <<-END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title><%= @page_title || controller.action_name %></title>
<%= stylesheet_link_tag 'application', :media => 'all', :cache => true %>
<%= javascript_include_tag :defaults, "livevalidation", :cache => true %>
<%= yield :head %>
</head>
<body>
<%= render :partial => 'layouts/flashes' -%>
<%= yield %>
</body>
</html>
END
 
file 'public/stylesheets/application.css', <<-END
/* @group Browser Reset */
 
html, body {
font-size: 12.5px; }
 
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-family: helvetica, verdana, arial, sans-serif;
font-style: inherit;
font-weight: inherit;
line-height: 1.25em;
text-align: left;
vertical-align: baseline; }
 
html {
overflow-y: scroll; }
 
a img, :link img, :visited img {
border: 0; }
 
strong {
font-weight: bold; }
 
em {
font-style: italic; }
 
table {
border-collapse: collapse;
border-spacing: 0; }
 
ul {
list-style: none; }
 
/* @end */
/* @group Live Validations */
 
.LV_validation_message {
font-weight: bold;
margin-left: 5px;
}
 
.LV_valid {
background:#E6EFC2;
color:#264409;
border-color:#C6D880;
}
 
.LV_invalid {
background:#FBE3E4;
color:#8a1f11;
border-color:#FBC2C4;
}
 
.LV_invalid_field {
border-color: red;
border-width: 1px;
}
 
/* @end */
END
 
file 'app/controllers/application_controller.rb', <<-END
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
 
class ApplicationController < ActionController::Base
 
helper :all # include all helpers, all the time
# make methods available to views
helper_method :logged_in?, :admin_logged_in?, :current_user_session, :current_user
# See ActionController::RequestForgeryProtection for details
protect_from_forgery
# See ActionController::Base for details
# Uncomment this to filter the contents of submitted sensitive data parameters
# from your application log (in this case, all fields with names like "password").
filter_parameter_logging :password, :confirm_password, :password_confirmation, :creditcard
def logged_in?
!current_user_session.nil?
end
def admin_required
unless current_user && current_user.admin?
flash[:error] = "Sorry, you don't have access to that."
redirect_to root_url and return false
end
end
def admin_logged_in?
logged_in? && current_user.admin?
end
 
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
 
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user
end
 
def require_user
unless current_user
store_location
flash[:notice] = "You must be logged in to access this page"
redirect_to new_user_session_url
return false
end
end
 
def require_no_user
if current_user
store_location
flash[:notice] = "You must be logged out to access this page"
redirect_to account_url
return false
end
end
def store_location
session[:return_to] = request.request_uri
end
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
end
END
 
file 'app/helpers/application_helper.rb', <<-END
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
# Block method that creates an area of the view that
# is only rendered if the request is coming from an
# anonymous user.
def anonymous_only(&block)
if !logged_in?
block.call
end
end
# Block method that creates an area of the view that
# only renders if the request is coming from an
# authenticated user.
def authenticated_only(&block)
if logged_in?
block.call
end
end
# Block method that creates an area of the view that
# only renders if the request is coming from an
# administrative user.
def admin_only(&block)
role_only("admin", &block)
end
 
def state_options
[[ "Alabama", "AL" ], [ "Alaska", "AK" ], [ "Arizona", "AZ" ], [ "Arkansas", "AR" ], [ "California", "CA" ], [ "Colorado", "CO" ], [ "Connecticut", "CT" ], [ "Delaware", "DE" ], [ "District Of Columbia", "DC" ], [ "Florida", "FL" ], [ "Georgia", "GA" ], [ "Hawaii", "HI" ], [ "Idaho", "ID" ], [ "Illinois", "IL" ], [ "Indiana", "IN" ], [ "Iowa", "IA" ], [ "Kansas", "KS" ], [ "Kentucky", "KY" ], [ "Louisiana", "LA" ], [ "Maine", "ME" ], [ "Maryland", "MD" ], [ "Massachusetts", "MA" ], [ "Michigan", "MI" ], [ "Minnesota", "MN" ], [ "Mississippi", "MS" ], [ "Missouri", "MO" ], [ "Montana", "MT" ], [ "Nebraska", "NE" ], [ "Nevada", "NV" ], [ "New Hampshire", "NH" ], [ "New Jersey", "NJ" ], [ "New Mexico", "NM" ], [ "New York", "NY" ], [ "North Carolina", "NC" ], [ "North Dakota", "ND" ], [ "Ohio", "OH" ], [ "Oklahoma", "OK" ], [ "Oregon", "OR" ], [ "Pennsylvania", "PA" ], [ "Rhode Island", "RI" ], [ "South Carolina", "SC" ], [ "South Dakota", "SD" ], [ "Tennessee", "TN" ], [ "Texas", "TX" ], [ "Utah", "UT" ], [ "Vermont", "VT" ], [ "Virginia", "VA" ], [ "Washington", "WA" ], [ "West Virginia", "WV" ], [ "Wisconsin", "WI" ], [ "Wyoming", "WY" ]]
end
 
def state_options_with_blank(label = "")
state_options.unshift([label, ""])
end
 
def full_state_name(state_abbrev)
state_options.each do |full_name, abbrev|
return full_name if abbrev == state_abbrev
end
nil
end
 
private
 
def role_only(rolename, &block)
if not current_user.blank? and current_user.has_role?(rolename)
block.call
end
end
end
END
 
# initializers
initializer 'requires.rb', <<-END
Dir[File.join(RAILS_ROOT, 'lib', '*.rb')].each do |f|
require f
end
END
 
initializer 'admin_data.rb', <<-END
ADMIN_DATA_VIEW_AUTHORIZATION = Proc.new { |controller| controller.send("admin_logged_in?") }
ADMIN_DATA_UPDATE_AUTHORIZATION = Proc.new { |controller| return false }
END
 
initializer 'live_validations.rb', <<-END
LiveValidations.use :livevalidation_dot_com, :default_valid_message => "", :validate_on_blur => true
END
 
initializer 'mail.rb', <<-END
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "111.111.111.111",
:port => 25,
:domain => "example.com",
:authentication => :login,
:user_name => "mikeg1@example.com",
:password => "password"
}
END
 
initializer 'date_time_formats.rb', <<-END
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:us => '%m/%d/%y',
:us_with_time => '%m/%d/%y, %l:%M %p',
:short_day => '%e %B %Y',
:long_day => '%A, %e %B %Y'
)
 
Date::DATE_FORMATS[:human] = "%B %e, %Y"
END
 
commit_state "application files and initializers"
 
# deployment
capify!
 
file 'config/deploy.rb', <<-END
set :application, "#{current_app_name}"
set :repository, "git@gitosis_sever:#{current_app_name}.git"
set :user, "webadmin"
set :deploy_via, :fast_remote_cache
set :scm, :git
 
# Customise the deployment
set :tag_on_deploy, false # turn off deployment tagging, we have our own tagging strategy
 
set :keep_releases, 6
after "deploy:update", "deploy:cleanup"
 
# directories to preserve between deployments
# set :asset_directories, ['public/system/logos', 'public/system/uploads']
 
# re-linking for config files on public repos
# namespace :deploy do
# desc "Re-link config files"
# task :link_config, :roles => :app do
# run "ln -nsf \#{shared_path}/config/database.yml \#{current_path}/config/database.yml"
# end
end
END
 
file 'config/deploy/production.rb', <<-END
set :host, "111.111.111.111"
set :branch, "master"
END
 
file 'config/deploy/staging.rb', <<-END
set :host, "111.111.111.111"
set :branch, "staging"
END
 
commit_state "deployment files"
 
# error tracking
file 'config/exceptional.yml', <<-END
# here are the settings that are common to all environments
common: &default_settings
# You must specify your Exceptional API key here.
api-key: PASTE_YOUR_API_KEY_HERE
# Exceptional creates a separate log file from your application's logs
# available levels are debug, info, warn, error, fatal
log-level: info
# The exceptional agent sends data via regular http by default
# Setting this value to true will send data over SSL, increasing security
# There will be an additional CPU overhead in encrypting the data, however
# as long as your deployment environment is not Passenger (mod_rails), this
# happens in the background so as not to incur a page wait for your users.
ssl: false
development:
<<: *default_settings
# Normally no reason to collect exceptions in development
# NOTE: for trial purposes you may want to enable exceptional in development
enabled: false
test:
<<: *default_settings
# No reason to collect exceptions when running tests by default
enabled: false
 
test2:
<<: *default_settings
# No reason to collect exceptions when running tests by default
enabled: false
 
test3:
<<: *default_settings
# No reason to collect exceptions when running tests by default
enabled: false
 
test4:
<<: *default_settings
# No reason to collect exceptions when running tests by default
enabled: false
 
production:
<<: *default_settings
enabled: true
 
staging:
# It's common development practice to have a staging environment that closely
# mirrors production, by default catch errors in this environment too.
<<: *default_settings
enabled: true
END
 
# performance
file 'config/newrelic.yml', <<-END
#
# This file configures the NewRelic RPM Agent, NewRelic RPM monitors Rails
# applications with deep visibility and low overhead. For more information,
# visit www.newrelic.com.
#
# This configuration file is custom generated for Lark Group Lite Account
#
# here are the settings that are common to all environments
common: &default_settings
# ============================== LICENSE KEY ===============================
# You must specify the licence key associated with your New Relic account.
# This key binds your Agent's data to your account in the New Relic RPM service.
license_key: 'LICENSE_KEY_HERE'
# Application Name
# Set this to be the name of your application as you'd like it show up in RPM.
# RPM will then auto-map instances of your application into a RPM "application"
# on your home dashboard page. This setting does not prevent you from manually
# defining applications.
app_name: #{current_app_name}
 
# the 'enabled' setting is used to turn on the NewRelic Agent. When false,
# your application is not instrumented and the Agent does not start up or
# collect any data; it is a complete shut-off.
#
# when turned on, the agent collects performance data by inserting lightweight
# tracers on key methods inside the rails framework and asynchronously aggregating
# and reporting this performance data to the NewRelic RPM service at NewRelic.com.
# below.
enabled: false
 
# The newrelic agent generates its own log file to keep its logging information
# separate from that of your application. Specify its log level here.
log_level: info
# The newrelic agent communicates with the RPM service via http by default.
# If you want to communicate via https to increase security, then turn on
# SSL by setting this value to true. Note, this will result in increased
# CPU overhead to perform the encryption involved in SSL communication, but this
# work is done asynchronously to the threads that process your application code, so
# it should not impact response times.
ssl: false
# Set your application's Apdex threshold value with the 'apdex_t' setting, in seconds. The
# apdex_t value determines the buckets used to compute your overall Apdex score. Requests
# that take less than apdex_t seconds to process will be classified as Satisfying transactions;
# more than apdex_t seconds as Tolerating transactions; and more than four times the apdex_t
# value as Frustrating transactions. For more
# about the Apdex standard, see http://support.newrelic.com/faqs/general/apdex
apdex_t: 0.5
 
# Proxy settings for connecting to the RPM server.
#
# If a proxy is used, the host setting is required. Other settings are optional. Default
# port is 8080.
#
# proxy_host: hostname
# proxy_port: 8080
# proxy_user:
# proxy_pass:
 
# Tells transaction tracer and error collector (when enabled) whether or not to capture HTTP params.
# When true, the RoR filter_parameters mechanism is used so that sensitive parameters are not recorded
capture_params: false
 
 
# Transaction tracer captures deep information about slow
# transactions and sends this to the RPM service once a minute. Included in the
# transaction is the exact call sequence of the transactions including any SQL statements
# issued.
transaction_tracer:
# Transaction tracer is enabled by default. Set this to false to turn it off. This feature
# is only available at the Silver and above product levels.
enabled: true
# When transaction tracer is on, SQL statements can optionally be recorded. The recorder
# has three modes, "off" which sends no SQL, "raw" which sends the SQL statement in its
# original form, and "obfuscated", which strips out numeric and string literals
record_sql: obfuscated
# Threshold in seconds for when to collect stack trace for a SQL call. In other words,
# when SQL statements exceed this threshold, then capture and send to RPM the current
# stack trace. This is helpful for pinpointing where long SQL calls originate from
stack_trace_threshold: 0.500
# Error collector captures information about uncaught exceptions and sends them to RPM for
# viewing
error_collector:
# Error collector is enabled by default. Set this to false to turn it off. This feature
# is only available at the Silver and above product levels
enabled: true
# Tells error collector whether or not to capture a source snippet around the place of the
# error when errors are View related.
capture_source: true
# To stop specific errors from reporting to RPM, set this property to comma separated
# values
#
#ignore_errors: ActionController::RoutingError, ...
 
 
# override default settings based on your application's environment
 
# NOTE if your application has other named environments, you should
# provide newrelic conifguration settings for these enviromnents here.
 
development:
<<: *default_settings
# turn off communication to RPM service in development mode.
# NOTE: for initial evaluation purposes, you may want to temporarily turn
# the agent on in development mode.
enabled: false
 
# When running in Developer Mode, the New Relic Agent will present
# performance information on the last 100 transactions you have
# executed since starting the mongrel. to view this data, go to
# http://localhost:3000/newrelic
developer: true
 
test:
<<: *default_settings
# it almost never makes sense to turn on the agent when running unit, functional or
# integration tests or the like.
enabled: false
 
test2:
<<: *default_settings
# it almost never makes sense to turn on the agent when running unit, functional or
# integration tests or the like.
enabled: false
 
test3:
<<: *default_settings
# it almost never makes sense to turn on the agent when running unit, functional or
# integration tests or the like.
enabled: false
 
test4:
<<: *default_settings
# it almost never makes sense to turn on the agent when running unit, functional or
# integration tests or the like.
enabled: false
 
# Turn on the agent in production for 24x7 monitoring. NewRelic testing shows
# an average performance impact of < 5 ms per transaction, you you can leave this on
# all the time without incurring any user-visible performance degredation.
production:
<<: *default_settings
enabled: true
 
# many applications have a staging environment which behaves identically to production.
# Support for that environment is provided here. By default, the staging environment has
# the agent turned on.
staging:
<<: *default_settings
enabled: true
app_name: #{current_app_name} (Staging)
END
 
# database
file 'config/database.yml', <<-END
# PostgreSQL. Versions 7.4 and 8.x are supported.
#
# Install the ruby-postgres driver:
# gem install ruby-postgres
# On Mac OS X:
# gem install ruby-postgres -- --include=/usr/local/pgsql
# On Windows:
# gem install ruby-postgres
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
development:
adapter: postgresql
encoding: unicode
database: #{current_app_name}_development
pool: 5
username: postgres
password:
 
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
#port: 5432
 
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
 
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# The server defaults to notice.
#min_messages: warning
 
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: #{current_app_name}_test
pool: 5
username: postgres
password:
 
test2:
adapter: postgresql
encoding: unicode
database: #{current_app_name}_test
pool: 5
username: postgres
password:
 
test3:
adapter: postgresql
encoding: unicode
database: #{current_app_name}_test
pool: 5
username: postgres
password:
 
test4:
adapter: postgresql
encoding: unicode
database: #{current_app_name}_test
pool: 5
username: postgres
password:
 
production:
adapter: postgresql
encoding: unicode
database: #{current_app_name}_production
pool: 5
username: postgres
password: the_password
 
staging:
adapter: postgresql
encoding: unicode
database: #{current_app_name}_staging
pool: 5
username: postgres
password: 99Schema@
END
 
file 'db/populate/01_sample_seed.rb', <<-END
# Model.create_or_update(:id => 1, :name => 'sample')
# User db/populate/development/01_file.rb for development-only data
END
 
commit_state "configuration files"
 
# testing
file 'test/exemplars/sample_exemplar.rb', <<-END
class Company < ActiveRecord::Base
generator_for :country => "USA"
generator_for :organization => "Joe's Garage"
generator_for :login, :method => :next_login
generator_for :plan => nil
generator_for (:currency_id) {Currency.generate.id}
 
# don't worry about subscription stuff in test
alias_method :old_valid_plan?, :valid_plan?
def valid_plan?
true
end
 
def self.next_login
@last_login ||= 'joesgarage'
@last_login.succ!
end
end
END
 
file 'test/test_helper.rb', <<-END
ENV["RAILS_ENV"] = "test" if ENV["RAILS_ENV"].nil? || ENV["RAILS_ENV"] == ''
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'shoulda'
require 'mocha'
require 'authlogic/test_case'
 
# skip after_create callback during testing
# class Company < ActiveRecord::Base; def setup_default_categories; end; end
 
class ActiveSupport::TestCase
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
 
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
#fixtures :all
 
# Add more helper methods to be used by all tests here...
end
 
class ActionController::TestCase
setup :activate_authlogic
end
END
 
file 'test/unit/notifier_test.rb', <<-END
require 'test_helper'
 
class NotifierTest < ActionMailer::TestCase
should "send password reset instructions" do
user = User.generate!
Notifier.deliver_password_reset_instructions(user)
assert_sent_email do |email|
email.subject = "Password Reset Instructions"
email.from.include?('Lark Group <noreply@larkfarm.com>')
email.to.include?(user.email)
email.body =~ Regexp.new(user.perishable_token)
end
end
end
END
 
file 'test/unit/user_test.rb', <<-END
require 'test_helper'
 
class UserTest < ActiveSupport::TestCase
 
context "using authlogic" do
setup do
activate_authlogic
end
should_be_authentic
context "serialize roles" do
setup do
@user = User.generate
end
should "default to an empty array" do
assert_equal [], @user.roles
end
should "allow saving and retrieving roles array" do
@user.roles = ["soldier", "sailor", "spy"]
@user.save
user_id = @user.id
user2 = User.find(user_id)
assert_equal ["soldier", "sailor", "spy"], user2.roles
end
should "not allow non-array data" do
assert_raise ActiveRecord::SerializationTypeMismatch do
@user.roles = "snakeskin shoes"
@user.save
end
end
end
should_callback :make_default_roles, :before_validation_on_create
should_allow_mass_assignment_of :login, :password, :password_confirmation, :first_name, :last_name, :email
should_not_allow_mass_assignment_of :crypted_password, :password_salt, :persistence_token, :login_count, :last_request_at, :last_login_at,
:current_login_at, :last_login_ip, :current_login_ip, :roles, :created_at, :updated_at, :id
context "#deliver_password_reset_instructions!" do
setup do
@user = User.generate!
Notifier.stubs(:deliver_password_reset_instructions)
end
should "reset the perishable token" do
@user.expects(:reset_perishable_token!)
@user.deliver_password_reset_instructions!
end
should "send the reset mail" do
Notifier.expects(:deliver_password_reset_instructions).with(@user)
@user.deliver_password_reset_instructions!
end
end
context "#admin?" do
setup do
@user = User.generate
end
should "return true if the user has the admin role" do
@user.add_role("admin")
assert @user.admin?
end
should "return false if the user does not have the admin role" do
@user.clear_roles
assert !@user.admin?
end
end
context "#has_role?" do
setup do
@user = User.generate
end
should "return true if the user has the specified role" do
@user.add_role("saint")
assert @user.has_role?("saint")
end
should "return false if the user does not have the specified role" do
@user.clear_roles
assert !@user.has_role?("saint")
end
end
 
context "#add_role" do
should "add the specified role" do
@user = User.generate
@user.add_role("wombat")
assert @user.roles.include?("wombat")
end
end
context "#remove_role" do
should "remove the specified role" do
@user = User.generate
@user.add_role("omnivore")
@user.remove_role("omnivore")
assert !@user.roles.include?("omnivore")
end
end
context "#clear_roles" do
should "have no roles after clearing" do
@user = User.generate
@user.add_role("cat")
@user.add_role("dog")
@user.add_role("goldfish")
@user.clear_roles
assert_equal [], @user.roles
end
end
context "#kaboom!" do
should "blow up predictably" do
assert_raise NameError do
@user = User.generate!
@user.kaboom!
end
end
end
end
end
END
 
file 'test/shoulda_macros/authlogic.rb', <<-END
module Authlogic
module ShouldaMacros
class Test::Unit::TestCase
def self.should_be_authentic
klass = model_class
should "acts as authentic" do
assert klass.new.respond_to?(:password=)
assert klass.new.respond_to?(:valid_password?)
end
end
end
end
end
END
 
file 'test/shoulda_macros/filter.rb', <<-END
class ActionController::TestCase
def self.should_have_before_filter(expected_method, options = {})
should_have_filter('before', expected_method, options)
end
 
def self.should_have_after_filter(expected_method, options = {})
should_have_filter('after', expected_method, options)
end
 
def self.should_have_filter(filter_type, expected_method, options)
description = "have \#{filter_type}_filter :\#{expected_method}"
description << " with \#{options.inspect}" unless options.empty?
 
should description do
klass = "action_controller/filters/\#{filter_type}_filter".classify.constantize
expected = klass.new(:filter, expected_method.to_sym, options)
assert_equal 1, @controller.class.filter_chain.select { |filter|
filter.method == expected.method && filter.kind == expected.kind &&
filter.options == expected.options && filter.class == expected.class
}.size
end
end
end
END
 
file 'test/exemplars/user_exemplar.rb', <<-END
class User < ActiveRecord::Base
generator_for :login, :method => :next_login
generator_for :password => 'bobby'
generator_for :password_confirmation => 'bobby'
generator_for :email, :method => :next_email
def self.next_login
@last_login ||= 'bobby'
@last_login.succ!
end
def self.next_email
@base ||= 'BobDobbs'
@base.succ!
"\#{@base}@example.com"
end
end
END
 
file 'test/unit/user_session_test.rb', <<-END
require 'test_helper'
 
class UserSessionTest < ActiveSupport::TestCase
# note - not an AR class
should "derive from Authlogic::Session::Base" do
Authlogic::Session::Base.controller = stub('controller')
us = UserSession.new
assert us.is_a?(Authlogic::Session::Base)
end
end
END
 
file 'test/unit/helpers/application_helper_test.rb', <<-END
require 'test_helper'
 
class ApplicationHelperTest < ActionView::TestCase
context "#anonymous_only" do
should "call the supplied block if the current user is anonymous" do
self.stubs(:logged_in?).returns(false)
assert_equal "result", anonymous_only {"result"}
end
 
should "not call the supplied block if the current user is logged in" do
self.stubs(:logged_in?).returns(true)
assert_nil anonymous_only {"result"}
end
end
context "#authenticated_only" do
should "call the supplied block if the current user is logged in" do
self.stubs(:logged_in?).returns(true)
assert_equal "result", authenticated_only {"result"}
end
 
should "not call the supplied block if the current user is anonymous" do
self.stubs(:logged_in?).returns(false)
assert_nil authenticated_only {"result"}
end
end
context "#admin_only" do
setup do
@current_user = User.generate
end
should "call the supplied block if the current user is logged in and an admin" do
@current_user.add_role("admin")
self.stubs(:current_user).returns(@current_user)
assert_equal "result", admin_only {"result"}
end
 
should "not call the supplied block if the current user is anonymous" do
self.stubs(:current_user).returns(nil)
assert_nil admin_only {"result"}
end
 
should "not call the supplied block if the current user is logged in but not an admin" do
self.stubs(:current_user).returns(@current_user)
assert_nil admin_only {"result"}
end
end
should "provide an array of U.S. states" do
assert_equal [[ "Alabama", "AL" ], [ "Alaska", "AK" ], [ "Arizona", "AZ" ], [ "Arkansas", "AR" ], [ "California", "CA" ], [ "Colorado", "CO" ], [ "Connecticut", "CT" ], [ "Delaware", "DE" ], [ "District Of Columbia", "DC" ], [ "Florida", "FL" ], [ "Georgia", "GA" ], [ "Hawaii", "HI" ], [ "Idaho", "ID" ], [ "Illinois", "IL" ], [ "Indiana", "IN" ], [ "Iowa", "IA" ], [ "Kansas", "KS" ], [ "Kentucky", "KY" ], [ "Louisiana", "LA" ], [ "Maine", "ME" ], [ "Maryland", "MD" ], [ "Massachusetts", "MA" ], [ "Michigan", "MI" ], [ "Minnesota", "MN" ], [ "Mississippi", "MS" ], [ "Missouri", "MO" ], [ "Montana", "MT" ], [ "Nebraska", "NE" ], [ "Nevada", "NV" ], [ "New Hampshire", "NH" ], [ "New Jersey", "NJ" ], [ "New Mexico", "NM" ], [ "New York", "NY" ], [ "North Carolina", "NC" ], [ "North Dakota", "ND" ], [ "Ohio", "OH" ], [ "Oklahoma", "OK" ], [ "Oregon", "OR" ], [ "Pennsylvania", "PA" ], [ "Rhode Island", "RI" ], [ "South Carolina", "SC" ], [ "South Dakota", "SD" ], [ "Tennessee", "TN" ], [ "Texas", "TX" ], [ "Utah", "UT" ], [ "Vermont", "VT" ], [ "Virginia", "VA" ], [ "Washington", "WA" ], [ "West Virginia", "WV" ], [ "Wisconsin", "WI" ], [ "Wyoming", "WY" ]], state_options
end
should "provide an array of U.S. states plus blank" do
assert_equal [["the label", ""], [ "Alabama", "AL" ], [ "Alaska", "AK" ], [ "Arizona", "AZ" ], [ "Arkansas", "AR" ], [ "California", "CA" ], [ "Colorado", "CO" ], [ "Connecticut", "CT" ], [ "Delaware", "DE" ], [ "District Of Columbia", "DC" ], [ "Florida", "FL" ], [ "Georgia", "GA" ], [ "Hawaii", "HI" ], [ "Idaho", "ID" ], [ "Illinois", "IL" ], [ "Indiana", "IN" ], [ "Iowa", "IA" ], [ "Kansas", "KS" ], [ "Kentucky", "KY" ], [ "Louisiana", "LA" ], [ "Maine", "ME" ], [ "Maryland", "MD" ], [ "Massachusetts", "MA" ], [ "Michigan", "MI" ], [ "Minnesota", "MN" ], [ "Mississippi", "MS" ], [ "Missouri", "MO" ], [ "Montana", "MT" ], [ "Nebraska", "NE" ], [ "Nevada", "NV" ], [ "New Hampshire", "NH" ], [ "New Jersey", "NJ" ], [ "New Mexico", "NM" ], [ "New York", "NY" ], [ "North Carolina", "NC" ], [ "North Dakota", "ND" ], [ "Ohio", "OH" ], [ "Oklahoma", "OK" ], [ "Oregon", "OR" ], [ "Pennsylvania", "PA" ], [ "Rhode Island", "RI" ], [ "South Carolina", "SC" ], [ "South Dakota", "SD" ], [ "Tennessee", "TN" ], [ "Texas", "TX" ], [ "Utah", "UT" ], [ "Vermont", "VT" ], [ "Virginia", "VA" ], [ "Washington", "WA" ], [ "West Virginia", "WV" ], [ "Wisconsin", "WI" ], [ "Wyoming", "WY" ]], state_options_with_blank("the label")
end
context "#full_state_name" do
should "look up a state name" do
assert_equal "North Carolina", full_state_name("NC")
end
should "return nil if no match" do
assert_nil full_state_name("XX")
end
end
end
END
 
file 'test/functional/application_controller_test.rb', <<-END
require 'test_helper'
 
class ApplicationControllerTest < ActionController::TestCase
# should_helper :all
# should_have_helper_method :logged_in?, :admin_logged_in?, :current_user_session, :current_user
# should_protect_from_forgery
 
should_filter_params :password, :confirm_password, :password_confirmation, :creditcard
context "#logged_in?" do
should "return true if there is a user session" do
@the_user = User.generate!
UserSession.create(@the_user)
assert controller.logged_in?
end
should "return false if there is no session" do
assert !controller.logged_in?
end
end
context "#admin_logged_in?" do
should "return true if there is a user session for an admin" do
@the_user = User.generate!
@the_user.roles << "admin"
UserSession.create(@the_user)
assert controller.admin_logged_in?
end
should "return false if there is a user session for a non-admin" do
@the_user = User.generate!
@the_user.roles = []
UserSession.create(@the_user)
assert !controller.admin_logged_in?
end
should "return false if there is no session" do
assert !controller.admin_logged_in?
end
end
# TODO: Test filter methods
end
END
 
file 'test/functional/user_controller_test.rb', <<-END
require 'test_helper'
 
class UsersControllerTest < ActionController::TestCase
should_have_before_filter :require_no_user, :only => [:new, :create]
should_have_before_filter :require_user, :only => [:show, :edit, :update]
should_have_before_filter :admin_required, :only => [:index, :destroy]
context "on GET to :index" do
setup do
controller.stubs(:admin_required).returns(true)
@the_user = User.generate!
User.stubs(:all).returns([@the_user])
get :index
end
should_assign_to(:users) { [@the_user] }
should_assign_to(:page_title) { "All Users" }
should_respond_with :success
should_render_template :index
should_not_set_the_flash
end
context "on GET to :new" do
setup do
controller.stubs(:require_no_user).returns(true)
@the_user = User.generate!
User.stubs(:new).returns(@the_user)
get :new
end
should_assign_to(:user) { @the_user }
should_assign_to(:page_title) { "Create Account" }
should_respond_with :success
should_render_template :new
should_not_set_the_flash
end
 
context "on POST to :create" do
setup do
controller.stubs(:require_no_user).returns(true)
@the_user = User.generate!
User.stubs(:new).returns(@the_user)
end
context "with successful creation" do
setup do
@the_user.stubs(:save).returns(true)
post :create, :user => { :login => "bobby", :password => "bobby", :password_confirmation => "bobby" }
end
 
should_assign_to(:user) { @the_user }
should_respond_with :redirect
should_set_the_flash_to "Account registered!"
should_redirect_to("the user's account") { account_url }
end
context "with failed creation" do
setup do
@the_user.stubs(:save).returns(false)
post :create, :user => { :login => "bobby", :password => "bobby", :password_confirmation => "bobby" }
end
should_assign_to(:user) { @the_user }
should_respond_with :success
should_not_set_the_flash
should_render_template :new
end
end
context "with a regular user" do
setup do
@the_user = User.generate!
UserSession.create(@the_user)
end
 
context "on GET to :show" do
setup do
get :show
end
should_assign_to(:user) { @the_user }
should_assign_to(:page_title) { "\#{@the_user.login} details" }
should_respond_with :success
should_not_set_the_flash
should_render_template :show
end
 
context "on GET to :edit" do
setup do
get :edit
end
should_assign_to(:user) { @the_user }
should_assign_to(:page_title) { "Edit \#{@the_user.login}" }
should_respond_with :success
should_not_set_the_flash
should_render_template :edit
end
 
context "on PUT to :update" do
context "with successful update" do
setup do
User.any_instance.stubs(:update_attributes).returns(true)
put :update, :user => { :login => "bill" }
end
should_assign_to(:user) { @the_user }
should_respond_with :redirect
should_set_the_flash_to "Account updated!"
should_redirect_to("the user's account") { account_url }
end
context "with failed update" do
setup do
User.any_instance.stubs(:update_attributes).returns(false)
put :update, :user => { :login => "bill" }
end
should_assign_to(:user) { @the_user }
should_respond_with :success
should_not_set_the_flash
should_render_template :edit
end
end
end
 
context "with an admin user" do
setup do
@admin_user = User.generate!
@admin_user.roles << "admin"
UserSession.create(@admin_user)
@the_user = User.generate!
end
 
context "on GET to :show" do
setup do
get :show, :id => @the_user.id
end
should_assign_to(:user) { @the_user }
should_assign_to(:page_title) { "\#{@the_user.login} details" }
should_respond_with :success
should_not_set_the_flash
should_render_template :show
end
 
context "on GET to :edit" do
setup do
get :edit, :id => @the_user.id
end
should_assign_to(:user) { @the_user }
should_assign_to(:page_title) { "Edit \#{@the_user.login}" }
should_respond_with :success
should_not_set_the_flash
should_render_template :edit
end
 
context "on PUT to :update" do
context "with successful update" do
setup do
User.any_instance.stubs(:update_attributes).returns(true)
put :update, :id => @the_user.id, :user => { :login => "bill" }
end
should_assign_to(:user) { @the_user }
should_respond_with :redirect
should_set_the_flash_to "Account updated!"
should_redirect_to("the user's account") { account_url }
end
context "with failed update" do
setup do
User.any_instance.stubs(:update_attributes).returns(false)
put :update, :id => @the_user.id, :user => { :login => "bill" }
end
should_assign_to(:user) { @the_user }
should_respond_with :success
should_not_set_the_flash
should_render_template :edit
end
end
context "on DELETE to :destroy" do
setup do
delete :destroy, :id => @the_user.id
end
 
should_respond_with :redirect
should_set_the_flash_to "User was deleted."
should_redirect_to("the users page") { users_path }
end
end
end
END
 
file 'test/controllers/user_sessions_controller.rb', <<-END
require 'test_helper'
 
class UserSessionsControllerTest < ActionController::TestCase
should_have_before_filter :require_no_user, :only => [:new, :create]
should_have_before_filter :require_user, :only => :destroy
 
context "on GET to :new" do
setup do
controller.stubs(:require_no_user).returns(true)
@the_user_session = UserSession.new
UserSession.stubs(:new).returns(@the_user_session)
get :new
end
should_assign_to(:user_session) { @the_user_session }
should_assign_to(:page_title) { "Login" }
should_respond_with :success
should_render_template :new
should_not_set_the_flash
end
 
context "on POST to :create" do
setup do
controller.stubs(:require_no_user).returns(true)
@the_user_session = UserSession.new
UserSession.stubs(:new).returns(@the_user_session)
end
context "with successful creation" do
setup do
@the_user_session.stubs(:save).returns(true)
post :create, :user_session => { :login => "bobby", :password => "bobby" }
end
 
should_assign_to(:user_session) { @the_user_session }
should_respond_with :redirect
should_set_the_flash_to "Login successful!"
should_redirect_to("the user's account") { account_url }
end
context "with failed creation" do
setup do
@the_user_session.stubs(:save).returns(false)
post :create, :user_session => { :login => "bobby", :password => "bobby" }
end
should_assign_to(:user_session) { @the_user_session }
should_respond_with :success
should_not_set_the_flash
should_render_template :new
end
end
context "on DELETE to :destroy" do
setup do
@the_user = User.generate!
UserSession.create(@the_user)
delete :destroy
end
should_respond_with :redirect
should_set_the_flash_to "Logout successful!"
should_redirect_to("the login page") { new_user_session_url }
end
end
END
 
file 'test/controllers/pages_controller_test.rb', <<-END
require 'test_helper'
 
class PagesControllerTest < ActionController::TestCase
{:home => '#{current_app_name}',
:css_test => 'CSS Test'}.each do | page, page_title |
context "on GET to :\#{page.to_s}" do
setup do
get page
end
should_assign_to(:page_title) { page_title }
should_respond_with :success
should_not_set_the_flash
should_render_template page
end
end
context "on GET to :kaboom" do
should "blow up predictably" do
assert_raise NameError do
@user = User.generate!
get :kaboom
end
end
end
end
END
 
file 'test/controllers/password_reset_controller_tests.rb', <<-END
require 'test_helper'
 
class PasswordResetsControllerTest < ActionController::TestCase
 
should_have_before_filter :load_user_using_perishable_token, :only => [:edit, :update]
should_have_before_filter :require_no_user
 
context "on GET to :new" do
setup do
controller.stubs(:require_no_user).returns(true)
get :new
end
should_assign_to(:page_title) { "Forgot Password?" }
should_respond_with :success
should_render_template :new
should_not_set_the_flash
end
 
context "on POST to :create" do
setup do
Notifier.stubs(:deliver_password_reset_instructions)
controller.stubs(:require_no_user).returns(true)
end
 
context "with user not found" do
setup do
User.stubs(:find_by_email).returns(nil)
post :create, :email => "foo@example.com"
end
 
should_respond_with :success
should_set_the_flash_to "No user was found with that email address"
should_render_template :new
end
context "with user found" do
setup do
@user = User.generate!(:email => "foo@example.com")
post :create, :email => "foo@example.com"
end
should_respond_with :redirect
should_set_the_flash_to "Instructions to reset your password have been emailed to you. " +
"Please check your email."
should_redirect_to("the home page") { root_url }
end
end
 
context "on GET to :edit" do
setup do
controller.stubs(:require_no_user).returns(true)
@user = User.generate!
User.stubs(:find_using_perishable_token).returns(@user)
get :edit, :id => "the token"
end
should_assign_to(:page_title) { "Select a New Password" }
should_respond_with :success
should_render_template :edit
should_not_set_the_flash
end
 
context "on PUT to :update" do
setup do
controller.stubs(:require_no_user).returns(true)
@user = User.generate!
User.stubs(:find_using_perishable_token).returns(@user)
end
context "with successful save" do
setup do
User.any_instance.stubs(:save).returns(true)
put :update, :id => "the token", :user => {:password => "the new password", :password_confirmation => "the new password"}
end
 
should_respond_with :redirect
should_set_the_flash_to "Password successfully updated"
should_redirect_to("the user's page") { account_url }
end
context "with failed save" do
setup do
User.any_instance.stubs(:save).returns(false)
put :update, :id => "the token", :user => {:password => "the new password", :password_confirmation => "the new password"}
end
 
should_respond_with :success
should_not_set_the_flash
should_render_template :edit
end
end
end
END
 
file 'test/integration/routing_test.rb', <<-END
require 'test_helper'
 
class RoutingTest < ActionController::IntegrationTest
context "routing" do
should_route :get, "/account/new", :controller => "users", :action => "new"
should_route :get, "/account/edit", :action=>"edit", :controller=>"users"
should_route :get, "/account", :action=>"show", :controller=>"users"
should_route :put, "/account", :action=>"update", :controller=>"users"
should_route :delete, "/account", :action=>"destroy", :controller=>"users"
should_route :post, "/account", :action=>"create", :controller=>"users"
should_route :get, "/password_resets", :action=>"index", :controller=>"password_resets"
should_route :post, "/password_resets", :action=>"create", :controller=>"password_resets"
should_route :get, "/password_resets/new", :action=>"new", :controller=>"password_resets"
should_route :get, "/password_resets/1/edit", :action=>"edit", :controller=>"password_resets", :id => 1
should_route :get, "/password_resets/1", :action=>"show", :controller=>"password_resets", :id => 1
should_route :put, "/password_resets/1", :action=>"update", :controller=>"password_resets", :id => 1
should_route :delete, "/password_resets/1", :action=>"destroy", :controller=>"password_resets", :id => 1
should_route :get, "/users", :action=>"index", :controller=>"users"
should route(:post, "/users").to(:action=>"create", :controller=>"users")
should route(:get, "/users/new").to(:action=>"new", :controller=>"users")
should_route :get, "/users/1/edit", :action=>"edit", :controller=>"users", :id => 1
should_route :get, "/users/1", :action=>"show", :controller=>"users", :id => 1
should_route :put, "/users/1", :action=>"update", :controller=>"users", :id => 1
should_route :delete, "/users/1", :action=>"destroy", :controller=>"users", :id => 1
should_route :get, "/user_session/new", :action=>"new", :controller=>"user_sessions"
should_route :get, "/user_session/edit", :action=>"edit", :controller=>"user_sessions"
should_route :get, "/user_session", :action=>"show", :controller=>"user_sessions"
should_route :put, "/user_session", :action=>"update", :controller=>"user_sessions"
should_route :delete, "/user_session", :action=>"destroy", :controller=>"user_sessions"
should_route :post, "/user_session", :action=>"create", :controller=>"user_sessions"
should_route :get, "/", :action=>"home", :controller=>"pages"
should route(:get, "/home").to(:action=>"home", :controller=>"pages")
should route(:get, "/login").to(:action=>"new", :controller=>"user_sessions")
should route(:get, "/logout").to(:action=>"destroy", :controller=>"user_sessions")
should route(:get, "/register").to(:action=>"new", :controller=>"users")
should_route :get, "/pages/foo", :controller=>"pages", :action => "foo"
 
end
end
END
 
commit_state "basic tests"
 
# authlogic setup
file 'app/controllers/password_resets_controller.rb', <<-END
class PasswordResetsController < ApplicationController
before_filter :load_user_using_perishable_token, :only => [:edit, :update]
before_filter :require_no_user
def new
@page_title = "Forgot Password?"
end
def create
@user = User.find_by_email(params[:email])
if @user
@user.deliver_password_reset_instructions!
flash[:notice] = "Instructions to reset your password have been emailed to you. " +
"Please check your email."
redirect_to root_url
else
flash[:notice] = "No user was found with that email address"
render :action => :new
end
end
def edit
@page_title = "Select a New Password"
end
 
def update
@user.password = params[:user][:password]
@user.password_confirmation = params[:user][:password_confirmation]
if @user.save
flash[:notice] = "Password successfully updated"
redirect_to account_url
else
render :action => :edit
end
end
 
private
def load_user_using_perishable_token
@user = User.find_using_perishable_token(params[:id])
unless @user
flash[:notice] = "We're sorry, but we could not locate your account." +
"If you are having issues try copying and pasting the URL " +
"from your email into your browser or restarting the " +
"reset password process."
redirect_to root_url
end
end
end
END
 
file 'app/controllers/user_sessions_controller.rb', <<-END
class UserSessionsController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => :destroy
def new
@page_title = "Login"
@user_session = UserSession.new
end
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Login successful!"
redirect_back_or_default account_url
else
render :action => :new
end
end
def destroy
current_user_session.destroy
flash[:notice] = "Logout successful!"
redirect_back_or_default new_user_session_url
end
end
END
 
file 'app/controllers/users_controller.rb', <<-END
class UsersController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => [:show, :edit, :update]
before_filter :admin_required, :only => [:index, :destroy]
def index
@users = User.all
@page_title = "All Users"
end
def new
@user = User.new
@page_title = "Create Account"
end
def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = "Account registered!"
redirect_back_or_default account_url
else
render :action => :new
end
end
def show
find_user
@page_title = "\#{@user.login} details"
end
 
def edit
find_user
@page_title = "Edit \#{@user.login}"
end
def update
find_user
if @user.update_attributes(params[:user])
flash[:notice] = "Account updated!"
redirect_to account_url
else
render :action => :edit
end
end
 
def destroy
find_user
@user.destroy
flash[:notice] = 'User was deleted.'
redirect_to(users_url)
end
 
private
 
def find_user
if @current_user.admin? && params[:id]
@user = User.find(params[:id])
else
@user = @current_user
end
end
end
END
 
file 'app/models/notifier.rb', <<-END
class Notifier < ActionMailer::Base
default_url_options[:host] = "larkfarm.com"
def password_reset_instructions(user)
subject "Password Reset Instructions"
from "Administrator <noreply@example.com>"
recipients user.email
sent_on Time.now
body :edit_password_reset_url => edit_password_reset_url(user.perishable_token)
end
end
END
 
file 'app/models/user.rb', <<-END
class User < ActiveRecord::Base
acts_as_authentic
serialize :roles, Array
before_validation_on_create :make_default_roles
attr_accessible :login, :password, :password_confirmation, :email, :first_name, :last_name
def deliver_password_reset_instructions!
reset_perishable_token!
Notifier.deliver_password_reset_instructions(self)
end
def admin?
has_role?("admin")
end
def has_role?(role)
roles.include?(role)
end
def add_role(role)
self.roles << role
end
def remove_role(role)
self.roles.delete(role)
end
def clear_roles
self.roles = []
end
def kaboom!
r = RegExp.new("foo")
end
 
private
def make_default_roles
clear_roles if roles.nil?
end
end
END
 
file 'app/models/user_session.rb', <<-END
class UserSession < Authlogic::Session::Base
end
END
 
file 'app/views/notifier/password_reset_instructions.erb', <<-END
A request to reset your password has been made. If you did not make this request, simply ignore this email. If you did make this request just click the link below:
 
<%= @edit_password_reset_url %>
 
If the above URL does not work try copying and pasting it into your browser. If you continue to have problem please feel free to contact us.
END
 
file 'app/views/password_resets/edit.html.erb', <<-END
<h1>Change My Password</h1>
 
<% form_for @user, :url => password_reset_path, :method => :put, :live_validations => true do |f| %>
<%= f.error_messages %>
<%= f.label :password %><br />
<%= f.password_field :password %><br />
<br />
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %><br />
<br />
<%= f.submit "Update my password and log me in" %>
<% end %>
END
 
file 'app/views/password_resets/new.html.erb', <<-END
<h1>Forgot Password</h1>
 
Fill out the form below and instructions to reset your password will be emailed to you:<br />
<br />
 
<% form_tag password_resets_path do %>
<label>Email:</label><br />
<%= text_field_tag "email" %><br />
<br />
<%= submit_tag "Reset my password" %>
<% end %>
END
 
file 'app/views/user_sessions/new.html.erb', <<-END
<h1>Login</h1>
 
<% form_for @user_session, :url => user_session_path, :live_validations => true do |f| %>
<%= f.error_messages %>
<%= f.label :login %><br />
<%= f.text_field :login %><br />
<br />
<%= f.label :password %><br />
<%= f.password_field :password %><br />
<br />
<%= f.check_box :remember_me %><%= f.label :remember_me %><br />
<br />
<%= f.submit "Login" %>
<% end %>
END
 
file 'app/views/users/index.html.erb', <<-END
<h1>Listing users</h1>
 
<table>
<tr>
<th>Login</th>
<th colspan="3"></th>
</tr>
 
<% @users.each do |user| %>
<tr>
<td><%=h user.login %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
 
<br />
 
<%= link_to 'New user', new_user_path %>
END
 
file 'app/views/users/_form.html.erb', <<-END
<%= form.label :first_name %><br />
<%= form.text_field :first_name %><br />
<br />
<%= form.label :last_name %><br />
<%= form.text_field :last_name %><br />
<br />
<%= form.label :login %><br />
<%= form.text_field :login %><br />
<br />
<%= form.label :password, form.object.new_record? ? nil : "Change password" %><br />
<%= form.password_field :password %><br />
<br />
<%= form.label :password_confirmation %><br />
<%= form.password_field :password_confirmation %><br />
<br />
<%= form.label :email %><br />
<%= form.text_field :email %><br />
<br />
END
 
file 'app/views/users/edit.html.erb', <<-END
<h1>Edit My Account</h1>
 
<% form_for @user, :url => account_path, :live_validations => true do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :object => f %>
<%= f.submit "Update" %>
<% end %>
 
<br /><%= link_to "My Profile", account_path %>
END
 
file 'app/views/users/new.html.erb', <<-END
<h1>Register</h1>
 
<% form_for @user, :url => account_path, :live_validations => true do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :object => f %>
<%= f.submit "Register" %>
<% end %>
END
 
file 'app/views/users/show.html.erb', <<-END
<p>
<b>Login:</b>
<%=h @user.login %>
</p>
 
<p>
<b>Email:</b>
<%=h @user.email %>
</p>
 
<p>
<b>Login count:</b>
<%=h @user.login_count %>
</p>
 
<p>
<b>Last request at:</b>
<%=h @user.last_request_at %>
</p>
 
<p>
<b>Last login at:</b>
<%=h @user.last_login_at %>
</p>
 
<p>
<b>Current login at:</b>
<%=h @user.current_login_at %>
</p>
 
<p>
<b>Last login ip:</b>
<%=h @user.last_login_ip %>
</p>
 
<p>
<b>Current login ip:</b>
<%=h @user.current_login_ip %>
</p>
 
 
<%= link_to 'Edit', edit_account_path %>
END
 
file 'db/migrate/01_create_users.rb', <<-END
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.timestamps
t.string :login, :null => false
t.string :crypted_password, :null => false
t.string :password_salt, :null => false
t.string :persistence_token, :null => false
t.integer :login_count, :default => 0, :null => false
t.datetime :last_request_at
t.datetime :last_login_at
t.datetime :current_login_at
t.string :last_login_ip
t.string :current_login_ip
t.string :roles
t.string :first_name
t.string :last_name
t.string :perishable_token, :default => "", :null => false
t.string :email, :default => "", :null => false
end
add_index :users, :login
add_index :users, :persistence_token
add_index :users, :last_request_at
add_index :users, :perishable_token
add_index :users, :email
end
 
def self.down
drop_table :users
end
end
END
 
file 'db/migrate/02_create_sessions.rb', <<-END
class CreateSessions < ActiveRecord::Migration
def self.up
create_table :sessions do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
 
add_index :sessions, :session_id
add_index :sessions, :updated_at
end
 
def self.down
drop_table :sessions
end
end
END
 
commit_state "basic Authlogic setup"
 
# static pages
file 'app/controllers/pages_controller.rb', <<-END
class PagesController < ApplicationController
def home
@page_title = '#{current_app_name}'
end
def css_test
@page_title = "CSS Test"
end
end
END
 
file 'app/views/pages/home.html.erb', <<-END
<div id="top_menu">
<% anonymous_only do %>
<%= link_to "Register", new_account_path %>
<%= link_to "Login", new_user_session_path %>
<% end %>
<% authenticated_only do %>
<%= link_to "Logout", user_session_path, :method => :delete, :confirm => "Are you sure you want to logout?" %>
<% end %>
</div>
 
<div id="main">
<h1>Welcome to #{current_app_name}</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
 
<div id="left_menu">
<% anonymous_only do %>
<%= link_to "Register", new_account_path %>
<%= link_to "Login", new_user_session_path %>
<% end %>
<% authenticated_only do %>
<% end %>
</div>
END
 
file 'app/views/pages/css_test.html.erb', <<-END
<!-- Sample Content to Plugin to Template -->
<h1>CSS Basic Elements</h1>
 
<p>The purpose of this HTML is to help determine what default settings are with CSS and to make sure that all possible HTML Elements are included in this HTML so as to not miss any possible Elements when designing a site.</p>
 
<hr />
 
<h1 id="headings">Headings</h1>
 
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
 
<small><a href="#wrapper">[top]</a></small>
<hr />
 
 
<h1 id="paragraph">Paragraph</h1>
 
<img style="width:250px;height:125px;float:right" src="images/css_gods_language.png" alt="CSS | God's Language" />
<p>Lorem ipsum dolor sit amet, <a href="#" title="test link">test link</a> adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.</p>
 
<p>Lorem ipsum dolor sit amet, <em>emphasis</em> consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.</p>
 
<small><a href="#wrapper">[top]</a></small>
<hr />
 
<h1 id="list_types">List Types</h1>
 
<h3>Definition List</h3>
<dl>
<dt>Definition List Title</dt>
<dd>This is a definition list division.</dd>
</dl>
 
<h3>Ordered List</h3>
<ol>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ol>
 
<h3>Unordered List</h3>
<ul>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>
 
<small><a href="#wrapper">[top]</a></small>
<hr />
 
<h1 id="form_elements">Fieldsets, Legends, and Form Elements</h1>
 
<fieldset>
<legend>Legend</legend>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</p>
<form>
<h2>Form Element</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.</p>
<p><label for="text_field">Text Field:</label><br />
<input type="text" id="text_field" /></p>
<p><label for="text_area">Text Area:</label><br />
<textarea id="text_area"></textarea></p>
<p><label for="select_element">Select Element:</label><br />
<select name="select_element">
<optgroup label="Option Group 1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</optgroup>
<optgroup label="Option Group 2">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</optgroup>
</select></p>
<p><label for="radio_buttons">Radio Buttons:</label><br />
<input type="radio" class="radio" name="radio_button" value="radio_1" /> Radio 1<br/>
<input type="radio" class="radio" name="radio_button" value="radio_2" /> Radio 2<br/>
<input type="radio" class="radio" name="radio_button" value="radio_3" /> Radio 3<br/>
</p>
<p><label for="checkboxes">Checkboxes:</label><br />
<input type="checkbox" class="checkbox" name="checkboxes" value="check_1" /> Radio 1<br/>
<input type="checkbox" class="checkbox" name="checkboxes" value="check_2" /> Radio 2<br/>
<input type="checkbox" class="checkbox" name="checkboxes" value="check_3" /> Radio 3<br/>
</p>
<p><label for="password">Password:</label><br />
<input type="password" class="password" name="password" />
</p>
<p><label for="file">File Input:</label><br />
<input type="file" class="file" name="file" />
</p>
<p><input class="button" type="reset" value="Clear" /> <input class="button" type="submit" value="Submit" />
</p>
 
</form>
</fieldset>
 
<small><a href="#wrapper">[top]</a></small>
<hr />
 
<h1 id="tables">Tables</h1>
 
<table cellspacing="0" cellpadding="0">
<tr>
<th>Table Header 1</th><th>Table Header 2</th><th>Table Header 3</th>
</tr>
<tr>
<td>Division 1</td><td>Division 2</td><td>Division 3</td>
</tr>
<tr class="even">
<td>Division 1</td><td>Division 2</td><td>Division 3</td>
</tr>
<tr>
<td>Division 1</td><td>Division 2</td><td>Division 3</td>
</tr>
 
</table>
 
<small><a href="#wrapper">[top]</a></small>
<hr />
 
<h1 id="misc">Misc Stuff - abbr, acronym, pre, code, sub, sup, etc.</h1>
 
<p>Lorem <sup>superscript</sup> dolor <sub>subscript</sub> amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. <cite>cite</cite>. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. <acronym title="National Basketball Association">NBA</acronym> Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. <abbr title="Avenue">AVE</abbr></p>
 
<pre><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. <acronym title="National Basketball Association">NBA</acronym> Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. <abbr title="Avenue">AVE</abbr></p></pre>
 
<blockquote>
"This stylesheet is going to help so freaking much." <br />-Blockquote
</blockquote>
 
<small><a href="#wrapper">[top]</a></small>
<!-- End of Sample Content -->
END
 
file 'doc/README_FOR_APP', <<-END
TODO after installing:
 
- Set up new app at http://getexceptional.com/apps
- Put the right API key in config/exceptional.yml
- Put the right API key in config/new_relic.yml
- Put the production database password in config/database.yml
- Put mail server information in mail.rb
- Put real IP address and git repo URL in deployment files
- Add app to gitosis config
- git remote add origin git@gitosis server:#{current_app_name}.git
- git push origin master:refs/heads/master
- create databases for parallel_test (rake db:create:all)
 
This application includes:
 
Coding Tools
============
- Authlogic for user authentication, including password resets,
anonymous_only, authenticated_only, admin_only application helpers
- World's simplest authorization system: manage multiple string roles on users with User#add_role, User#remove_role, User#clear_roles, and User#has_role?
- Date formats: :us, :us_with_time, :short_day, :long_day
- live-validations for client-side JavaScript data entry validation. Add :live_validations => true to form_for declarations to hook this up.
- Paperclip for attachment management
- /pages/css_test will show most CSS styles in action
- Searchlogic for magic named scopes and search forms - http://rdoc.info/projects/binarylogic/searchlogic
attribute_equals, attribute_does_not_equal, attribute_begins_with, attribute_like, attribute_ends_with, attribute_greater_than,
attribute_null, attribute_blank etc. etc.
- Stringex for extra string functionality
acts_as_url, String#to_ascii, String#to_html, String#to_url, String#remove_formatting, String.random
- US State application helpers
- will-paginate for pagination
 
 
Database Tools
==============
- Hooked up for PostgreSQL
- admin-data plugin for administrative UI. http://localhost:3000/admin_data will get you to the application's data. On production,
only admin can view data, no one can edit (modify config/initializers/admin_data.rb to adjust this)
- db-populate for seed data
 
 
Deployment Tools
================
- fast_remote_cache strategy for deployment
- rubiadhstrano for deployment recipes
automatically uses multiple targets, so: cap production deploy for deployment to production
- superdeploy for additional Capistrano tasks. cap -T for full list.
 
 
External Services
=================
- Exceptional for error tracking. Go to /pages/kaboom to test after finishing Exceptional setup.
- New Relic for performance tracking
 
 
Testing Tools
=============
- Shoulda and Test::Unit for testing
- Mocha for mocking
- Object Daddy for factories
- Generated code is already covered by tests
- parallel-test for faster testing.
rake test:parallel:prepare[2] to set up two test databases
rake test:parallel[2] to distribute tests across two cores
- rack-bug for request/response/perf analysis. http://localhost:3000/__rack_bug__/bookmarklet.html to add bookmarklet to browser.
- shmacros for additional Shoulda macros
should_accept_nested_attributes_for, should_act_as_taggable_on, should_callback, should_delegate, more
- More extra shoulda macros:
should_have_before_filter, should_have_after_filter
- metric-fu for static code analysis. rake metrics:all, configure in Rakefile
- inaction-mailer is installed for development environment, so mails sent during dev will end up as files in /tmp/sent_mails
END
 
commit_state "static pages"
 
# simple default routing
file 'config/routes.rb', <<-END
ActionController::Routing::Routes.draw do |map|
map.resource :account, :controller => "users"
map.resources :password_resets
map.resources :users
map.resource :user_session
map.login 'login', :controller => "user_sessions", :action => "new"
map.login 'logout', :controller => "user_sessions", :action => "destroy"
map.register 'register', :controller => "users", :action => "new"
map.root :controller => "pages", :action => "home"
map.pages 'pages/:action', :controller => "pages"
end
END
 
commit_state "routing"
 
# databases
rake('db:create')
rake('db:migrate')
 
# rakefile for metric_fu
file 'Rakefile', <<-END
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
 
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
 
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
 
require 'tasks/rails'
 
require 'metric_fu'
MetricFu::Configuration.run do |config|
# not doing saikuro at the moment
config.metrics = [:churn, :stats, :flog, :flay, :reek, :roodi, :rcov]
config.rcov[:rcov_opts] << "-Itest"
# config.flay = { :dirs_to_flay => ['app', 'lib'] }
# config.flog = { :dirs_to_flog => ['app', 'lib'] }
# config.reek = { :dirs_to_reek => ['app', 'lib'] }
# config.roodi = { :dirs_to_roodi => ['app', 'lib'] }
# config.saikuro = { :output_directory => 'scratch_directory/saikuro',
# :input_directory => ['app', 'lib'],
# :cyclo => "",
# :filter_cyclo => "0",
# :warn_cyclo => "5",
# :error_cyclo => "7",
# :formater => "text"} #this needs to be set to "text"
# config.churn = { :start_date => "1 year ago", :minimum_churn_count => 10}
# config.rcov = { :test_files => ['test/**/*_test.rb',
# 'spec/**/*_spec.rb'],
# :rcov_opts => ["--sort coverage",
# "--no-html",
# "--text-coverage",
# "--no-color",
# "--profile",
# "--rails",
# "--exclude /gems/,/Library/,spec"]}
end
END
 
commit_state "metric_fu setup"
 
# vendor rails
# take the edge of 2.3 for now
# TODO: piston_rails failing
# piston_rails :branch => '2-3-stable'
inside("vendor") do
  Git.run("clone git://github.com/rails/rails.git")
end
inside("vendor/rails") do
  Git.run("branch --track 2-3-stable origin/2-3-stable")
  Git.run("checkout 2-3-stable")
  run("rm -Rf .git")
end
 
commit_state("added rails 2-3-stable edge")
 
# Success!
puts "SUCCESS!"
puts ' Set up new app at http://getexceptional.com/apps'
puts ' Put the right API key in config/exceptional.yml'
puts ' Put the right API key in config/new_relic.yml'
puts ' Put the production database password in config/database.yml'
puts ' Put mail server information in mail.rb'
puts ' Put real IP address and git repo URL in deployment files'
puts ' Add app to gitosis config'
puts " git remote add origin git@gitosis_server:#{current_app_name}.git"
puts ' git push origin master:refs/heads/master'
puts ' create databases for parallel_test'