controller_scaffolding 0.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +32 -0
  5. data/lib/controller_scaffolding.rb +7 -0
  6. data/lib/controller_scaffolding/add_generator.rb +8 -0
  7. data/lib/controller_scaffolding/version.rb +3 -0
  8. data/lib/generators/assets/javascripts/ext_index_nav.js +14 -0
  9. data/lib/generators/assets/stylesheets/controller_scaffolding.css.scss +131 -0
  10. data/lib/generators/assets/stylesheets/ext_form_submit.css.scss +0 -0
  11. data/lib/generators/assets/stylesheets/ext_index_nav.css.scss +0 -0
  12. data/lib/generators/controller/concerns/ext_form_submit.rb +17 -0
  13. data/lib/generators/controller/concerns/ext_index_nav.rb +19 -0
  14. data/lib/generators/controller/controller_scaffolding_generator.rb +121 -0
  15. data/lib/generators/haml/controller/controller_scaffolding_generator.rb +166 -0
  16. data/lib/generators/haml/controller/partials/_flash_messages.html.haml +2 -0
  17. data/lib/generators/haml/controller/partials/_pagination.html.haml +10 -0
  18. data/lib/generators/haml/controller/partials/_validation_errors.html.haml +5 -0
  19. data/lib/templates/haml/controller/_form.html.haml +17 -0
  20. data/lib/templates/haml/controller/edit.html.haml +2 -0
  21. data/lib/templates/haml/controller/index.html.haml +37 -0
  22. data/lib/templates/haml/controller/new.html.haml +2 -0
  23. data/lib/templates/haml/controller/view.html.haml +4 -0
  24. data/lib/templates/rails/controller/controller.rb +16 -0
  25. data/test/controller_scaffolding_test.rb +7 -0
  26. data/test/dummy/README.rdoc +28 -0
  27. data/test/dummy/Rakefile +6 -0
  28. data/test/dummy/app/assets/javascripts/application.js +13 -0
  29. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  30. data/test/dummy/app/controllers/application_controller.rb +6 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/models/person.rb +3 -0
  33. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/test/dummy/bin/bundle +3 -0
  35. data/test/dummy/bin/rails +4 -0
  36. data/test/dummy/bin/rake +4 -0
  37. data/test/dummy/config.ru +4 -0
  38. data/test/dummy/config/application.rb +30 -0
  39. data/test/dummy/config/boot.rb +5 -0
  40. data/test/dummy/config/database.yml +25 -0
  41. data/test/dummy/config/environment.rb +5 -0
  42. data/test/dummy/config/environments/development.rb +39 -0
  43. data/test/dummy/config/environments/production.rb +83 -0
  44. data/test/dummy/config/environments/test.rb +39 -0
  45. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  47. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/test/dummy/config/initializers/inflections.rb +16 -0
  49. data/test/dummy/config/initializers/mime_types.rb +4 -0
  50. data/test/dummy/config/initializers/session_store.rb +3 -0
  51. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  52. data/test/dummy/config/locales/en.yml +25 -0
  53. data/test/dummy/config/routes.rb +56 -0
  54. data/test/dummy/config/secrets.yml +22 -0
  55. data/test/dummy/db/development.sqlite3 +0 -0
  56. data/test/dummy/db/migrate/20140711034542_create_people.rb +14 -0
  57. data/test/dummy/db/schema.rb +27 -0
  58. data/test/dummy/db/test.sqlite3 +0 -0
  59. data/test/dummy/lib/tasks/sample_data.rake +18 -0
  60. data/test/dummy/log/development.log +5691 -0
  61. data/test/dummy/log/test.log +81562 -0
  62. data/test/dummy/public/404.html +67 -0
  63. data/test/dummy/public/422.html +67 -0
  64. data/test/dummy/public/500.html +66 -0
  65. data/test/dummy/public/favicon.ico +0 -0
  66. data/test/dummy/spec/factories/factory.rb +12 -0
  67. data/test/dummy/spec/requests/people_spec.rb +227 -0
  68. data/test/dummy/spec/spec_helper.rb +42 -0
  69. data/test/dummy/test/test_helper.rb +15 -0
  70. data/test/dummy/tmp/cache/assets/development/sass/4cc2210c6c3c0fe94891da849ffe7911fc420445/controller_scaffolding.css.scssc +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sass/4cc2210c6c3c0fe94891da849ffe7911fc420445/ext_form_submit.css.scssc +0 -0
  72. data/test/dummy/tmp/cache/assets/development/sass/4cc2210c6c3c0fe94891da849ffe7911fc420445/ext_index_nav.css.scssc +0 -0
  73. data/test/dummy/tmp/cache/assets/development/sprockets/12b145c6de8e8a781d4120a5f29229de +0 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/1406702d7228a8c1a717fc485390c025 +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/5e3a16a7a65151928708d6db358c759b +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/653fdbb8934cfc4411579c8628e7162d +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/705d80fa05052d5d6f269e75d7a11374 +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/7761773b21e56b187ef1ef0faed07f4c +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/8c0b04415ee487129c0d2bc8b098fb8c +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/8e608c74df0c65a289387e25a3881ef6 +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/965093127c5e679a2ffe5f562d7b4662 +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/aee47d2b394353b1f027d1265ce94bec +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/d10aa50bf278b2fcf5727421f422083f +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/d9a48b188723fa8a03d0f673046b0fc7 +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/d9ad301878886b21cb9b44509bb894ee +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/dd3286d35fd64e2653a6197e1a119fe3 +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/e1096456df20861d666f73523b3a56d1 +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/e6f3190c03c1c2b869d131e25d38eb7b +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/e8b18160729bab32f8368174bf32a9ce +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/eb8ff0c9bd29ca1463e355de4819639b +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  97. data/test/dummy/tmp/cache/assets/test/sass/4cc2210c6c3c0fe94891da849ffe7911fc420445/controller_scaffolding.css.scssc +0 -0
  98. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  99. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  100. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  101. data/test/dummy/tmp/cache/assets/test/sprockets/5e3a16a7a65151928708d6db358c759b +0 -0
  102. data/test/dummy/tmp/cache/assets/test/sprockets/7761773b21e56b187ef1ef0faed07f4c +0 -0
  103. data/test/dummy/tmp/cache/assets/test/sprockets/8c0b04415ee487129c0d2bc8b098fb8c +0 -0
  104. data/test/dummy/tmp/cache/assets/test/sprockets/965093127c5e679a2ffe5f562d7b4662 +0 -0
  105. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  106. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  107. data/test/dummy/tmp/cache/assets/test/sprockets/d9a48b188723fa8a03d0f673046b0fc7 +0 -0
  108. data/test/dummy/tmp/cache/assets/test/sprockets/d9ad301878886b21cb9b44509bb894ee +0 -0
  109. data/test/dummy/tmp/cache/assets/test/sprockets/e1096456df20861d666f73523b3a56d1 +0 -0
  110. data/test/dummy/tmp/cache/assets/test/sprockets/e8b18160729bab32f8368174bf32a9ce +0 -0
  111. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  112. data/test/dummy/tmp/pids/server.pid +1 -0
  113. data/test/lib/generators/controller_scaffolding_generator_test.rb +108 -0
  114. data/test/lib/generators/ext_controller_scaffolding_generator_test.rb +52 -0
  115. data/test/test_helper.rb +15 -0
  116. metadata +431 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,12 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :person do
4
+ sequence(:first_name) { |n| "John_#{n}" }
5
+ sequence(:last_name) { |n| "Doe_#{n}" }
6
+ sequence(:email) { |n| "johndoe_#{n}@domain.com"}
7
+ title "Sales Rep"
8
+ dob (Time.now - 30.years)
9
+ is_manager false
10
+ end
11
+
12
+ end
@@ -0,0 +1,227 @@
1
+ require 'spec_helper'
2
+
3
+ describe "People" do
4
+ before(:all) do
5
+ cmd_str = 'rails g controller_scaffolding people index new create edit update destroy'
6
+ cmd_str << ' --template-engine=haml --quiet --force --skip-assets --skip-test-framework --skip-helper'
7
+ puts "\n#{cmd_str}"
8
+ %x(#{cmd_str})
9
+
10
+ #Reload changed resources
11
+ Rails.application.reload_routes!
12
+ load "#{ Rails.root }/app/helpers/application_helper.rb" #reloads helper
13
+ end
14
+
15
+ after(:all) do
16
+ cmd_str = 'rails d controller_scaffolding people index new create edit update destroy'
17
+ cmd_str << ' --template-engine=haml --quiet --force --skip-assets --skip-test-framework --skip-helper'
18
+ puts "\n#{cmd_str}"
19
+ %x(#{cmd_str})
20
+ end
21
+
22
+
23
+ describe "Index" do
24
+ it "displays the correct columns in the correct order" do
25
+ visit people_path
26
+ th_arr = first("table.outer-list").first("thead").all("th")
27
+ th_arr.map { |th| th.text.strip }.reject(&:blank?).should
28
+ eq ["First name", "Last name", "Email", "Title", "Dob", "Is manager"]
29
+ end
30
+ describe "Pagination" do
31
+ describe "page info" do
32
+ describe "multiple items" do
33
+ before(:each) do
34
+ (1..31).each do |i|
35
+ FactoryGirl.create(:person)
36
+ end
37
+ end
38
+
39
+ it "shows the correct page info message" do
40
+ visit people_path
41
+ page.should have_content("Displaying 1 - 15 of 31 People")
42
+ visit people_path(page: "2", per_page: "15")
43
+ page.should have_content("Displaying 16 - 30 of 31 People")
44
+ visit people_path(per_page: "100")
45
+ page.should have_content("Displaying all 31 People")
46
+ end
47
+
48
+ end
49
+
50
+ describe "one item" do
51
+ before { FactoryGirl.create(:person) }
52
+ it "shows the correct page info message" do
53
+ visit people_path
54
+ page.should have_content("Displaying 1 Person")
55
+ end
56
+ end
57
+
58
+ describe "zero items" do
59
+ it "shows the correct page info message" do
60
+ visit people_path
61
+ page.should have_content("No entries found")
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ describe "page navigation" do
68
+ before(:each) do
69
+ (1..31).each do |i|
70
+ FactoryGirl.create(:person)
71
+ end
72
+ end
73
+ describe "items per page" do
74
+ it "displays 15 per page by default" do
75
+ visit people_path
76
+ people_displayed(page).should == 15
77
+ end
78
+
79
+ it "displays 20 items per page when selected by user", :js => true do
80
+ visit people_path
81
+ select("20", from: "People per page:")
82
+ people_displayed(page).should == 20
83
+ expect(page).to have_select("per_page", selected: '20') #Assert js reselects proper val
84
+ end
85
+
86
+ it "displays 10 items per page when selected by user", :js => true do
87
+ visit people_path
88
+ select("10", from: "People per page:")
89
+ people_displayed(page).should == 10
90
+ end
91
+
92
+ it "displays all items per page when selected by user", :js => true do
93
+ visit people_path
94
+ select("All", from: "People per page:")
95
+ people_displayed(page).should == 31
96
+ expect(page).to have_select("per_page", selected: 'All')
97
+ end
98
+ end
99
+
100
+ describe "pagination links" do
101
+ it "responds correctly to user", :js => true do
102
+ visit people_path(page: "1", per_page: "10")
103
+ page.should have_content("Displaying 1 - 10 of 31 People")
104
+ click_link("2")
105
+ page.should have_content("Displaying 11 - 20 of 31 People")
106
+ first("a.previous_page").click #Previous link
107
+ first("table.outer-list").first(:xpath, "tbody/tr/td").text.should eq Person.find(1).first_name
108
+ first("a.next_page").click #Next link
109
+ first("table.outer-list").first(:xpath, "tbody/tr/td").text.should eq Person.find(11).first_name
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+ describe "Links" do
117
+ before { @person = FactoryGirl.create(:person) }
118
+ it "allows user to edit" do
119
+ visit people_path
120
+ click_link("Edit")
121
+ current_path.should eq edit_person_path(@person)
122
+ end
123
+ it "allows user to delete", :js => true do
124
+ visit people_path
125
+ expect {
126
+ click_link("Del")
127
+ page.driver.browser.switch_to.alert.accept
128
+ sleep 1
129
+ }.to change(Person, :count).by(-1)
130
+ end
131
+ end
132
+
133
+ end
134
+
135
+ describe "New/Edit Form" do
136
+
137
+ describe "fields" do
138
+ it "new form has the correct field labels in the correct order" do
139
+ visit new_person_path
140
+ field_labels = page.all(:xpath, "//form[@class='new_person']/table[@class='outer']/tr/td/label").map(&:text)
141
+ field_labels.should eq ["First name", "Last name", "Email", "Title", "Dob", "Is manager"]
142
+ end
143
+ it "edit form has the correct field labels in the correct order" do
144
+ person = FactoryGirl.create(:person)
145
+ visit edit_person_path(person)
146
+ field_labels = page.all(:xpath, "//form[@class='edit_person']/table[@class='outer']/tr/td/label").map(&:text)
147
+ field_labels.should eq ["First name", "Last name", "Email", "Title", "Dob", "Is manager"]
148
+ end
149
+ describe "values" do
150
+ it "adds the correct values to its fields", :js => true do
151
+ visit new_person_path
152
+ fill_in("First name", :with => "Johnathan")
153
+ fill_in("Last name", :with => "Jones")
154
+ fill_in("Email", :with => "jj@domain.com")
155
+ fill_in("Title", :with => "Sales Rep")
156
+ dt = (Time.now - 2.years)
157
+ set_rails_datetime(dt, "person_dob")
158
+ click_button("Save & Back to List")
159
+ page.should have_content("Created Person successfully")
160
+ page.should have_content("Johnathan")
161
+ page.should have_content("Jones")
162
+ page.should have_content("jj@domain.com")
163
+ page.should have_content("Sales Rep")
164
+ #TODO: Pain to test datetime because of UTC...may just wait until datepicker functionality is added
165
+ #page.should have_content(dt.utc)
166
+ end
167
+ it "updates its fields correctly", :js => false do
168
+ person = FactoryGirl.create(:person, dob: (Time.now - 2.years))
169
+ visit edit_person_path(person)
170
+ fill_in("First name", :with => "Jerry")
171
+ fill_in("Last name", :with => "James")
172
+ fill_in("Email", :with => "jjames@domain.com")
173
+ fill_in("Title", :with => "Manager")
174
+ dt = (Time.now - 1.year)
175
+ set_rails_datetime(dt, "person_dob")
176
+ click_button("Save & Back to List")
177
+ page.should have_content("Updated Person successfully")
178
+ page.should have_content("Jerry")
179
+ page.should have_content("James")
180
+ page.should have_content("jjames@domain.com")
181
+ page.should have_content("Manager")
182
+ #TODO: Pain to test datetime because of UTC...may just wait until datepicker functionality is added
183
+ #page.should have_content(dt.utc)
184
+ end
185
+ end
186
+
187
+ end
188
+
189
+
190
+ #Note: if this fails make sure the person model has the "validates :first_name" call
191
+ it "displays validation errors" do
192
+ visit new_person_path
193
+ click_button("Save & Back to List")
194
+ page.should have_content("Unable to create Person for the following 1 reason:")
195
+ page.should have_content("First name can't be blank")
196
+ end
197
+
198
+ describe "form submission landing page and flash messages" do
199
+ it "redirects to the index page with success message" do
200
+ visit new_person_path
201
+ fill_in("First name", :with => "John")
202
+ click_button("Save & Back to List")
203
+ page.should have_content("Created Person successfully")
204
+ current_path.should eq people_path
205
+ end
206
+ it "redirects to the new page with success message" do
207
+ visit new_person_path
208
+ fill_in("First name", :with => "John")
209
+ click_button("Save & Reload")
210
+ page.should have_content("Created Person successfully")
211
+ current_path.should eq new_person_path
212
+ end
213
+ it "redirects to the edit page with success message" do
214
+ person = FactoryGirl.create(:person)
215
+ visit edit_person_path(person)
216
+ fill_in("First name", :with => "John")
217
+ click_button("Save & Reload")
218
+ page.should have_content("Updated Person successfully")
219
+ current_path.should eq edit_person_path(person)
220
+ end
221
+ end
222
+
223
+ #TODO: it has the correct field types (may be tough to test)
224
+ end
225
+
226
+
227
+ end
@@ -0,0 +1,42 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+ require File.expand_path("../../config/environment", __FILE__)
3
+ require 'rspec/rails'
4
+ require 'rspec/autorun'
5
+ require 'capybara/rails'
6
+ require 'capybara/rspec'
7
+ require 'factory_girl_rails'
8
+ require 'database_cleaner'
9
+
10
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
11
+
12
+ ActiveRecord::Migration.maintain_test_schema!
13
+
14
+ RSpec.configure do |config|
15
+
16
+ config.use_transactional_fixtures = false
17
+ config.before(:each) do
18
+ DatabaseCleaner.strategy = :transaction
19
+ DatabaseCleaner.clean_with(:truncation)
20
+ end
21
+ config.infer_base_class_for_anonymous_controllers = false
22
+ config.order = "random"
23
+ config.include Capybara::DSL
24
+ config.include FactoryGirl::Syntax::Methods
25
+ end
26
+
27
+ def people_displayed(page)
28
+ page.first("table.outer-list").first("tbody").all(:xpath, "tr[not(@id='pagination-row')]").count
29
+ end
30
+
31
+ def set_rails_datetime(time, id_prefix)
32
+ select time.year, from: "#{id_prefix}_1i"
33
+ select time.strftime("%B"), from: "#{id_prefix}_2i"
34
+ begin
35
+ select time.day, from: "#{id_prefix}_3i" #This could raise ambiguous match error
36
+ rescue
37
+ puts "set_rails_datetime() rescued an error. Day was #{time.day} not selected."
38
+ end
39
+ #pad with zeros to disambiguate
40
+ select(('%02i' % time.hour), from: "#{id_prefix}_4i")
41
+ select(('%02i' % time.min), from: "#{id_prefix}_5i")
42
+ end