attorney 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +19 -3
  3. data/app/assets/config/attorney_manifest.js +2 -0
  4. data/app/assets/javascripts/attorney/application.js +16 -0
  5. data/app/assets/javascripts/attorney/form_errors.js +13 -0
  6. data/app/assets/javascripts/attorney/rich_editor.js +19 -0
  7. data/app/assets/stylesheets/attorney/application.css +16 -0
  8. data/app/controllers/attorney/admin/documents_controller.rb +49 -0
  9. data/app/controllers/attorney/application_controller.rb +5 -0
  10. data/app/controllers/attorney/documents_controller.rb +11 -0
  11. data/app/helpers/attorney/application_helper.rb +13 -0
  12. data/app/helpers/attorney/documents_helper.rb +11 -0
  13. data/app/jobs/attorney/application_job.rb +4 -0
  14. data/app/mailers/attorney/application_mailer.rb +6 -0
  15. data/app/models/attorney/application_record.rb +5 -0
  16. data/app/models/attorney/document.rb +19 -0
  17. data/app/views/attorney/admin/documents/_form.html.erb +49 -0
  18. data/app/views/attorney/admin/documents/edit.html.erb +3 -0
  19. data/app/views/attorney/admin/documents/index.html.erb +37 -0
  20. data/app/views/attorney/admin/documents/new.html.erb +3 -0
  21. data/app/views/attorney/admin/documents/show.html.erb +13 -0
  22. data/app/views/attorney/documents/show.html.erb +1 -0
  23. data/app/views/layouts/attorney/application.html.erb +25 -0
  24. data/config/routes.rb +9 -0
  25. data/db/migrate/20180205173208_create_attorney_documents.rb +13 -0
  26. data/lib/attorney.rb +12 -2
  27. data/lib/attorney/engine.rb +14 -0
  28. data/lib/attorney/version.rb +1 -1
  29. data/lib/tasks/attorney_tasks.rake +4 -0
  30. data/spec/controllers/attorney/admin/documents_controller_spec.rb +130 -0
  31. data/spec/controllers/attorney/documents_controller_spec.rb +26 -0
  32. data/spec/features/attorney/admin/documents_spec.rb +87 -0
  33. data/spec/features/attorney/documents_spec.rb +19 -0
  34. data/spec/helpers/documents_helper_spec.rb +21 -0
  35. data/spec/lib/attorney_spec.rb +6 -0
  36. data/spec/models/attorney/document_spec.rb +28 -0
  37. data/spec/rails_helper.rb +109 -0
  38. data/spec/spec_helper.rb +96 -0
  39. data/spec/support/capybara.rb +1 -0
  40. data/spec/support/dummy/rails5_0/Rakefile +6 -0
  41. data/spec/support/dummy/rails5_0/app/assets/config/manifest.js +5 -0
  42. data/spec/support/dummy/rails5_0/app/assets/images/.keep +0 -0
  43. data/spec/support/dummy/rails5_0/app/assets/javascripts/application.js +13 -0
  44. data/spec/support/dummy/rails5_0/app/assets/javascripts/cable.js +13 -0
  45. data/spec/support/dummy/rails5_0/app/assets/javascripts/channels/.keep +0 -0
  46. data/spec/support/dummy/rails5_0/app/assets/stylesheets/application.css +15 -0
  47. data/spec/support/dummy/rails5_0/app/channels/application_cable/channel.rb +4 -0
  48. data/spec/support/dummy/rails5_0/app/channels/application_cable/connection.rb +4 -0
  49. data/spec/support/dummy/rails5_0/app/controllers/application_controller.rb +3 -0
  50. data/spec/support/dummy/rails5_0/app/controllers/concerns/.keep +0 -0
  51. data/spec/support/dummy/rails5_0/app/helpers/application_helper.rb +2 -0
  52. data/spec/support/dummy/rails5_0/app/jobs/application_job.rb +2 -0
  53. data/spec/support/dummy/rails5_0/app/mailers/application_mailer.rb +4 -0
  54. data/spec/support/dummy/rails5_0/app/models/application_record.rb +3 -0
  55. data/spec/support/dummy/rails5_0/app/models/concerns/.keep +0 -0
  56. data/spec/support/dummy/rails5_0/app/views/layouts/application.html.erb +15 -0
  57. data/spec/support/dummy/rails5_0/app/views/layouts/mailer.html.erb +13 -0
  58. data/spec/support/dummy/rails5_0/app/views/layouts/mailer.text.erb +1 -0
  59. data/spec/support/dummy/rails5_0/bin/bundle +3 -0
  60. data/spec/support/dummy/rails5_0/bin/rails +4 -0
  61. data/spec/support/dummy/rails5_0/bin/rake +4 -0
  62. data/spec/support/dummy/rails5_0/bin/setup +34 -0
  63. data/spec/support/dummy/rails5_0/bin/update +29 -0
  64. data/spec/support/dummy/rails5_0/config.ru +5 -0
  65. data/spec/support/dummy/rails5_0/config/application.rb +15 -0
  66. data/spec/support/dummy/rails5_0/config/boot.rb +5 -0
  67. data/spec/support/dummy/rails5_0/config/cable.yml +9 -0
  68. data/spec/support/dummy/rails5_0/config/database.yml +25 -0
  69. data/spec/support/dummy/rails5_0/config/environment.rb +5 -0
  70. data/spec/support/dummy/rails5_0/config/environments/development.rb +54 -0
  71. data/spec/support/dummy/rails5_0/config/environments/production.rb +86 -0
  72. data/spec/support/dummy/rails5_0/config/environments/test.rb +42 -0
  73. data/spec/support/dummy/rails5_0/config/initializers/application_controller_renderer.rb +8 -0
  74. data/spec/support/dummy/rails5_0/config/initializers/assets.rb +11 -0
  75. data/spec/support/dummy/rails5_0/config/initializers/backtrace_silencers.rb +7 -0
  76. data/spec/support/dummy/rails5_0/config/initializers/cookies_serializer.rb +5 -0
  77. data/spec/support/dummy/rails5_0/config/initializers/filter_parameter_logging.rb +4 -0
  78. data/spec/support/dummy/rails5_0/config/initializers/inflections.rb +16 -0
  79. data/spec/support/dummy/rails5_0/config/initializers/mime_types.rb +4 -0
  80. data/spec/support/dummy/rails5_0/config/initializers/new_framework_defaults.rb +26 -0
  81. data/spec/support/dummy/rails5_0/config/initializers/session_store.rb +3 -0
  82. data/spec/support/dummy/rails5_0/config/initializers/wrap_parameters.rb +14 -0
  83. data/spec/support/dummy/rails5_0/config/locales/en.yml +23 -0
  84. data/spec/support/dummy/rails5_0/config/puma.rb +47 -0
  85. data/spec/support/dummy/rails5_0/config/routes.rb +3 -0
  86. data/spec/support/dummy/rails5_0/config/secrets.yml +22 -0
  87. data/spec/support/dummy/rails5_0/config/spring.rb +6 -0
  88. data/spec/support/dummy/rails5_0/db/schema.rb +24 -0
  89. data/spec/support/dummy/rails5_0/lib/assets/.keep +0 -0
  90. data/spec/support/dummy/rails5_0/log/.keep +0 -0
  91. data/spec/support/dummy/rails5_0/public/404.html +67 -0
  92. data/spec/support/dummy/rails5_0/public/422.html +67 -0
  93. data/spec/support/dummy/rails5_0/public/500.html +66 -0
  94. data/spec/support/dummy/rails5_0/public/apple-touch-icon-precomposed.png +0 -0
  95. data/spec/support/dummy/rails5_0/public/apple-touch-icon.png +0 -0
  96. data/spec/support/dummy/rails5_0/public/favicon.ico +0 -0
  97. data/spec/support/dummy/rails5_1/Rakefile +6 -0
  98. data/spec/support/dummy/rails5_1/app/assets/config/manifest.js +5 -0
  99. data/spec/support/dummy/rails5_1/app/assets/images/.keep +0 -0
  100. data/spec/support/dummy/rails5_1/app/assets/javascripts/application.js +13 -0
  101. data/spec/support/dummy/rails5_1/app/assets/javascripts/cable.js +13 -0
  102. data/spec/support/dummy/rails5_1/app/assets/javascripts/channels/.keep +0 -0
  103. data/spec/support/dummy/rails5_1/app/assets/stylesheets/application.css +15 -0
  104. data/spec/support/dummy/rails5_1/app/channels/application_cable/channel.rb +4 -0
  105. data/spec/support/dummy/rails5_1/app/channels/application_cable/connection.rb +4 -0
  106. data/spec/support/dummy/rails5_1/app/controllers/application_controller.rb +4 -0
  107. data/spec/support/dummy/rails5_1/app/controllers/concerns/.keep +0 -0
  108. data/spec/support/dummy/rails5_1/app/helpers/application_helper.rb +2 -0
  109. data/spec/support/dummy/rails5_1/app/jobs/application_job.rb +2 -0
  110. data/spec/support/dummy/rails5_1/app/mailers/application_mailer.rb +4 -0
  111. data/spec/support/dummy/rails5_1/app/models/application_record.rb +3 -0
  112. data/spec/support/dummy/rails5_1/app/models/concerns/.keep +0 -0
  113. data/spec/support/dummy/rails5_1/app/views/layouts/mailer.html.erb +13 -0
  114. data/spec/support/dummy/rails5_1/app/views/layouts/mailer.text.erb +1 -0
  115. data/spec/support/dummy/rails5_1/app/views/layouts/main.html.erb +15 -0
  116. data/spec/support/dummy/rails5_1/bin/bundle +3 -0
  117. data/spec/support/dummy/rails5_1/bin/rails +4 -0
  118. data/spec/support/dummy/rails5_1/bin/rake +4 -0
  119. data/spec/support/dummy/rails5_1/bin/setup +38 -0
  120. data/spec/support/dummy/rails5_1/bin/update +29 -0
  121. data/spec/support/dummy/rails5_1/bin/yarn +11 -0
  122. data/spec/support/dummy/rails5_1/config.ru +5 -0
  123. data/spec/support/dummy/rails5_1/config/application.rb +18 -0
  124. data/spec/support/dummy/rails5_1/config/boot.rb +5 -0
  125. data/spec/support/dummy/rails5_1/config/cable.yml +10 -0
  126. data/spec/support/dummy/rails5_1/config/database.yml +25 -0
  127. data/spec/support/dummy/rails5_1/config/environment.rb +5 -0
  128. data/spec/support/dummy/rails5_1/config/environments/development.rb +54 -0
  129. data/spec/support/dummy/rails5_1/config/environments/production.rb +91 -0
  130. data/spec/support/dummy/rails5_1/config/environments/test.rb +42 -0
  131. data/spec/support/dummy/rails5_1/config/initializers/application_controller_renderer.rb +8 -0
  132. data/spec/support/dummy/rails5_1/config/initializers/assets.rb +14 -0
  133. data/spec/support/dummy/rails5_1/config/initializers/attorney.rb +1 -0
  134. data/spec/support/dummy/rails5_1/config/initializers/backtrace_silencers.rb +7 -0
  135. data/spec/support/dummy/rails5_1/config/initializers/cookies_serializer.rb +5 -0
  136. data/spec/support/dummy/rails5_1/config/initializers/filter_parameter_logging.rb +4 -0
  137. data/spec/support/dummy/rails5_1/config/initializers/inflections.rb +16 -0
  138. data/spec/support/dummy/rails5_1/config/initializers/mime_types.rb +4 -0
  139. data/spec/support/dummy/rails5_1/config/initializers/wrap_parameters.rb +14 -0
  140. data/spec/support/dummy/rails5_1/config/locales/en.yml +33 -0
  141. data/spec/support/dummy/rails5_1/config/puma.rb +56 -0
  142. data/spec/support/dummy/rails5_1/config/routes.rb +3 -0
  143. data/spec/support/dummy/rails5_1/config/secrets.yml +32 -0
  144. data/spec/support/dummy/rails5_1/config/spring.rb +6 -0
  145. data/spec/support/dummy/rails5_1/db/schema.rb +24 -0
  146. data/spec/support/dummy/rails5_1/lib/assets/.keep +0 -0
  147. data/spec/support/dummy/rails5_1/log/.keep +0 -0
  148. data/spec/support/dummy/rails5_1/package.json +5 -0
  149. data/spec/support/dummy/rails5_1/public/404.html +67 -0
  150. data/spec/support/dummy/rails5_1/public/422.html +67 -0
  151. data/spec/support/dummy/rails5_1/public/500.html +66 -0
  152. data/spec/support/dummy/rails5_1/public/apple-touch-icon-precomposed.png +0 -0
  153. data/spec/support/dummy/rails5_1/public/apple-touch-icon.png +0 -0
  154. data/spec/support/dummy/rails5_1/public/favicon.ico +0 -0
  155. data/spec/support/helpers/auth.rb +12 -0
  156. data/spec/support/shoulda_matchers.rb +8 -0
  157. data/vendor/assets/javascripts/attorney/bootstrap.bundle.min.js +7 -0
  158. data/vendor/assets/stylesheets/attorney/bootstrap.min.css +7 -0
  159. metadata +401 -28
  160. data/.gitignore +0 -13
  161. data/.rspec +0 -3
  162. data/.travis.yml +0 -5
  163. data/Gemfile +0 -6
  164. data/LICENSE.txt +0 -21
  165. data/README.md +0 -39
  166. data/attorney.gemspec +0 -25
  167. data/bin/console +0 -14
  168. data/bin/setup +0 -8
@@ -1,3 +1,3 @@
1
1
  module Attorney
2
- VERSION = "0.0.0"
2
+ VERSION = '1.0.0'
3
3
  end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :attorney do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,130 @@
1
+ require 'rails_helper'
2
+
3
+ module Attorney
4
+ RSpec.describe Admin::DocumentsController, type: :controller do
5
+
6
+ let(:valid_attributes) do
7
+ {
8
+ slug: 'terms',
9
+ published: true,
10
+ content: 'Lorem ipsum dolor sit amet'
11
+ }
12
+ end
13
+
14
+ let(:invalid_attributes) {
15
+ {
16
+ slug: nil,
17
+ published: true,
18
+ content: 'Lorem ipsum dolor sit amet'
19
+ }
20
+ }
21
+
22
+ before do
23
+ @routes = Engine.routes
24
+ @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('attorney', 'secret')
25
+ end
26
+
27
+ describe 'GET #index' do
28
+ it 'returns a success response' do
29
+ Document.create! valid_attributes
30
+ get :index
31
+ expect(response).to be_success
32
+ end
33
+ end
34
+
35
+ describe 'GET #show' do
36
+ it 'returns a success response' do
37
+ document = Document.create! valid_attributes
38
+ get :show, params: { id: document.to_param }
39
+ expect(response).to be_success
40
+ end
41
+ end
42
+
43
+ describe 'GET #new' do
44
+ it 'returns a success response' do
45
+ get :new
46
+ expect(response).to be_success
47
+ end
48
+ end
49
+
50
+ describe 'GET #edit' do
51
+ it 'returns a success response' do
52
+ document = Document.create! valid_attributes
53
+ get :edit, params: { id: document.to_param }
54
+ expect(response).to be_success
55
+ end
56
+ end
57
+
58
+ describe 'POST #create' do
59
+ context 'with valid params' do
60
+ it 'creates a new Document' do
61
+ expect {
62
+ post :create, params: { document: valid_attributes }
63
+ }.to change(Document, :count).by(1)
64
+ end
65
+
66
+ it 'redirects to the created document' do
67
+ post :create, params: { document: valid_attributes }
68
+ expect(response).to redirect_to(admin_document_path(Document.last))
69
+ end
70
+ end
71
+
72
+ context 'with invalid params' do
73
+ it "returns a success response (i.e. to display the 'new' template)" do
74
+ post :create, params: { document: invalid_attributes }
75
+ expect(response).to be_success
76
+ end
77
+ end
78
+ end
79
+
80
+ describe 'PUT #update' do
81
+ context 'with valid params' do
82
+ let(:new_attributes) do
83
+ {
84
+ slug: 'new_slug',
85
+ published: false,
86
+ content: 'New content'
87
+ }
88
+ end
89
+
90
+ it 'updates the requested document' do
91
+ document = Document.create! valid_attributes
92
+ put :update, params: { id: document.to_param, document: new_attributes }
93
+ document.reload
94
+ expect(document.slug).to eq 'new_slug'
95
+ expect(document.published?).to eq false
96
+ expect(document.content).to eq 'New content'
97
+ end
98
+
99
+ it 'redirects to the document' do
100
+ document = Document.create! valid_attributes
101
+ put :update, params: { id: document.to_param, document: valid_attributes }
102
+ expect(response).to redirect_to(admin_document_path(document))
103
+ end
104
+ end
105
+
106
+ context 'with invalid params' do
107
+ it "returns a success response (i.e. to display the 'edit' template)" do
108
+ document = Document.create! valid_attributes
109
+ put :update, params: { id: document.to_param, document: invalid_attributes }
110
+ expect(response).to be_success
111
+ end
112
+ end
113
+ end
114
+
115
+ describe 'DELETE #destroy' do
116
+ it 'destroys the requested document' do
117
+ document = Document.create! valid_attributes
118
+ expect {
119
+ delete :destroy, params: { id: document.to_param }
120
+ }.to change(Document, :count).by(-1)
121
+ end
122
+
123
+ it 'redirects to the documents list' do
124
+ document = Document.create! valid_attributes
125
+ delete :destroy, params: { id: document.to_param }
126
+ expect(response).to redirect_to(admin_documents_url)
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,26 @@
1
+ require 'rails_helper'
2
+
3
+ module Attorney
4
+ RSpec.describe DocumentsController, type: :controller do
5
+
6
+ let(:valid_attributes) do
7
+ {
8
+ slug: 'terms',
9
+ published: true,
10
+ content: 'Lorem ipsum dolor sit amet'
11
+ }
12
+ end
13
+
14
+ before do
15
+ @routes = Engine.routes
16
+ end
17
+
18
+ describe 'GET #show' do
19
+ it 'returns a success response' do
20
+ document = Document.create! valid_attributes
21
+ get :show, params: { slug: document.slug }
22
+ expect(response).to be_success
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,87 @@
1
+ require 'rails_helper'
2
+
3
+ module Attorney
4
+ describe 'admin documents' do
5
+ include Support::Helpers::Auth
6
+
7
+ before { authenticate }
8
+
9
+ describe 'list documents' do
10
+ before do
11
+ Document.create!(slug: 'terms-and-conditions', published: true, content: 'There is content!')
12
+ Document.create!(slug: 'privacy-policy', published: true, content: 'Private...')
13
+ end
14
+
15
+ it 'displays documents' do
16
+ visit 'attorney/admin/documents'
17
+ expect(page).to have_content 'terms-and-conditions'
18
+ expect(page).to have_content 'privacy-policy'
19
+ end
20
+ end
21
+
22
+ describe 'show document' do
23
+ let(:document) { Document.create!(slug: 'terms-and-conditions', published: true, content: 'There is content!') }
24
+
25
+ it 'shows document fields' do
26
+ visit "attorney/admin/documents/#{document.id}"
27
+ expect(page).to have_content 'terms-and-conditions'
28
+ expect(page).to have_content 'Published'
29
+ expect(page).to have_content 'There is content!'
30
+ end
31
+ end
32
+
33
+ describe 'create document' do
34
+ it 'creates document successfully' do
35
+ visit 'attorney/admin/documents/new'
36
+
37
+ fill_in 'Slug', with: 'terms-and-conditions'
38
+ check 'Publish'
39
+ fill_in 'Content', with: 'Some content!'
40
+ click_button 'Create Document'
41
+
42
+ expect(page).to have_content 'Document was successfully created.'
43
+ expect(page).to have_content 'terms-and-conditions'
44
+ expect(page).to have_content 'Published'
45
+ expect(page).to have_content 'Some content!'
46
+ end
47
+
48
+ it 'shows validation errors when appropriate' do
49
+ Document.create!(slug: 'terms-and-conditions', published: true, content: 'There is content!')
50
+ visit 'attorney/admin/documents/new'
51
+
52
+ fill_in 'Slug', with: 'terms-and-conditions'
53
+ click_button 'Create Document'
54
+
55
+ expect(page).to have_content 'Slug has already been taken'
56
+ end
57
+ end
58
+
59
+ describe 'edit document' do
60
+ let(:document) { Document.create!(slug: 'terms-and-conditions', published: true, content: 'There is content!') }
61
+
62
+ it 'updates document successfully' do
63
+ visit "attorney/admin/documents/#{document.id}/edit"
64
+
65
+ fill_in 'Slug', with: 'terms-and-conditions-new'
66
+ fill_in 'Content', with: 'Some new content!'
67
+ click_button 'Update Document'
68
+
69
+ expect(page).to have_content 'Document was successfully updated.'
70
+ expect(page).to have_content 'terms-and-conditions-new'
71
+ expect(page).to have_content 'Published'
72
+ expect(page).to have_content 'Some new content!'
73
+ end
74
+ end
75
+
76
+ describe 'delete document', js: true do
77
+ before { Document.create!(slug: 'terms-and-conditions', content: 'There is content!') }
78
+
79
+ it 'deletes document successfully' do
80
+ visit 'attorney/admin/documents'
81
+
82
+ click_link 'Destroy'
83
+ expect(page).to have_content 'Document was successfully destroyed.'
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ module Attorney
4
+ describe 'document show screen' do
5
+ before do
6
+ Document.create!(slug: 'terms-and-conditions', published: true, content: 'There is content!')
7
+ end
8
+
9
+ it 'displays document by slug' do
10
+ visit 'attorney/terms-and-conditions'
11
+ expect(page).to have_content 'There is content!'
12
+ end
13
+
14
+ it 'uses application layout' do
15
+ visit 'attorney/terms-and-conditions'
16
+ expect(page).to have_content "Rails #{Rails.version} layout"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails_helper'
2
+
3
+ module Attorney
4
+ describe DocumentsHelper do
5
+ describe '#published_badge' do
6
+ context "when it's published" do
7
+ let(:document) { Document.create!(slug: 'terms-and-conditions', published: true) }
8
+
9
+ it { expect(helper.published_badge(document)).to include 'badge badge-success' }
10
+ it { expect(helper.published_badge(document)).to include 'Published' }
11
+ end
12
+
13
+ context "when it's not published" do
14
+ let(:document) { Document.create!(slug: 'terms-and-conditions', published: false) }
15
+
16
+ it { expect(helper.published_badge(document)).to include 'badge badge-secondary' }
17
+ it { expect(helper.published_badge(document)).to include 'Not published' }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Attorney do
4
+ it { expect(Attorney.http_auth[:name]).to eq 'attorney' }
5
+ it { expect(Attorney.http_auth[:password]).to eq 'secret' }
6
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails_helper'
2
+
3
+ module Attorney
4
+ RSpec.describe Document, type: :model do
5
+ subject(:document) { Document.new(slug: 'terms', content: 'Lorem ipsum dolor sit amet...') }
6
+
7
+ context 'validations' do
8
+ it { is_expected.to validate_uniqueness_of(:slug) }
9
+ it { is_expected.to validate_presence_of(:slug) }
10
+
11
+ context 'slug format' do
12
+ let(:document) { Document.new(slug: 'terms and conditions') }
13
+
14
+ it 'validates format' do
15
+ expect(document).not_to be_valid
16
+ expect(document.errors[:slug]).to eq ["Slug format is invalid, try \"terms-and-conditions\" instead."]
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '.published' do
22
+ let!(:document_1) { Document.create!(slug: 'terms-1', published: true) }
23
+ let!(:document_2) { Document.create!(slug: 'terms-2', published: false) }
24
+
25
+ it { expect(Document.published).to eq [document_1] }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,109 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require 'spec_helper'
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+
5
+ require 'rails'
6
+ if Rails.version.start_with?('5.0')
7
+ require File.expand_path("../support/dummy/rails5_0/config/environment.rb", __FILE__)
8
+ elsif Rails.version.start_with?('5.1')
9
+ require File.expand_path("../support/dummy/rails5_1/config/environment.rb", __FILE__)
10
+ end
11
+
12
+ # Prevent database truncation if the environment is production
13
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
14
+ require 'rspec/rails'
15
+ # Add additional requires below this line. Rails is not loaded until this point!
16
+ require 'capybara-webkit'
17
+ require 'database_cleaner'
18
+ require 'capybara/rspec'
19
+
20
+ # Requires supporting ruby files with custom matchers and macros, etc, in
21
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
22
+ # run as spec files by default. This means that files in spec/support that end
23
+ # in _spec.rb will both be required and run as specs, causing the specs to be
24
+ # run twice. It is recommended that you do not name files matching this glob to
25
+ # end with _spec.rb. You can configure this pattern with the --pattern
26
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
27
+ #
28
+ # The following line is provided for convenience purposes. It has the downside
29
+ # of increasing the boot-up time by auto-requiring all files in the support
30
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
31
+ # require only the support files necessary.
32
+ #
33
+ Dir["#{File.expand_path(File.dirname(__FILE__))}/support/*.rb"].each { |f| require f }
34
+ Dir["#{File.expand_path(File.dirname(__FILE__))}/support/helpers/*.rb"].each { |f| require f }
35
+
36
+ # Checks for pending migrations and applies them before tests are run.
37
+ # If you are not using ActiveRecord, you can remove this line.
38
+ ActiveRecord::Migration.maintain_test_schema!
39
+
40
+ RSpec.configure do |config|
41
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
42
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
43
+
44
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
45
+ # examples within a transaction, remove the following line or assign false
46
+ # instead of true.
47
+ config.use_transactional_fixtures = false
48
+
49
+ config.before(:suite) do
50
+ if config.use_transactional_fixtures?
51
+ raise(<<-MSG)
52
+ Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
53
+ (or set it to false) to prevent uncommitted transactions being used in
54
+ JavaScript-dependent specs.
55
+
56
+ During testing, the app-under-test that the browser driver connects to
57
+ uses a different database connection to the database connection used by
58
+ the spec. The app's database connection would not be able to access
59
+ uncommitted transaction data setup over the spec's database connection.
60
+ MSG
61
+ end
62
+ DatabaseCleaner.clean_with(:truncation)
63
+ end
64
+
65
+ config.before(:each) do
66
+ DatabaseCleaner.strategy = :transaction
67
+ end
68
+
69
+ config.before(:each, type: :feature) do
70
+ # :rack_test driver's Rack app under test shares database connection
71
+ # with the specs, so continue to use transaction strategy for speed.
72
+ driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
73
+
74
+ unless driver_shares_db_connection_with_specs
75
+ # Driver is probably for an external browser with an app
76
+ # under test that does *not* share a database connection with the
77
+ # specs, so use truncation strategy.
78
+ DatabaseCleaner.strategy = :truncation
79
+ end
80
+ end
81
+
82
+ config.before(:each) do
83
+ DatabaseCleaner.start
84
+ end
85
+
86
+ config.append_after(:each) do
87
+ DatabaseCleaner.clean
88
+ end
89
+
90
+ # RSpec Rails can automatically mix in different behaviours to your tests
91
+ # based on their file location, for example enabling you to call `get` and
92
+ # `post` in specs under `spec/controllers`.
93
+ #
94
+ # You can disable this behaviour by removing the line below, and instead
95
+ # explicitly tag your specs with their type, e.g.:
96
+ #
97
+ # RSpec.describe UsersController, :type => :controller do
98
+ # # ...
99
+ # end
100
+ #
101
+ # The different available types are documented in the features, such as in
102
+ # https://relishapp.com/rspec/rspec-rails/docs
103
+ config.infer_spec_type_from_file_location!
104
+
105
+ # Filter lines from Rails gems in backtraces.
106
+ config.filter_rails_from_backtrace!
107
+ # arbitrary gems may also be filtered via:
108
+ # config.filter_gems_from_backtrace("gem name")
109
+ end