attorney 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +19 -3
- data/app/assets/config/attorney_manifest.js +2 -0
- data/app/assets/javascripts/attorney/application.js +16 -0
- data/app/assets/javascripts/attorney/form_errors.js +13 -0
- data/app/assets/javascripts/attorney/rich_editor.js +19 -0
- data/app/assets/stylesheets/attorney/application.css +16 -0
- data/app/controllers/attorney/admin/documents_controller.rb +49 -0
- data/app/controllers/attorney/application_controller.rb +5 -0
- data/app/controllers/attorney/documents_controller.rb +11 -0
- data/app/helpers/attorney/application_helper.rb +13 -0
- data/app/helpers/attorney/documents_helper.rb +11 -0
- data/app/jobs/attorney/application_job.rb +4 -0
- data/app/mailers/attorney/application_mailer.rb +6 -0
- data/app/models/attorney/application_record.rb +5 -0
- data/app/models/attorney/document.rb +19 -0
- data/app/views/attorney/admin/documents/_form.html.erb +49 -0
- data/app/views/attorney/admin/documents/edit.html.erb +3 -0
- data/app/views/attorney/admin/documents/index.html.erb +37 -0
- data/app/views/attorney/admin/documents/new.html.erb +3 -0
- data/app/views/attorney/admin/documents/show.html.erb +13 -0
- data/app/views/attorney/documents/show.html.erb +1 -0
- data/app/views/layouts/attorney/application.html.erb +25 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20180205173208_create_attorney_documents.rb +13 -0
- data/lib/attorney.rb +12 -2
- data/lib/attorney/engine.rb +14 -0
- data/lib/attorney/version.rb +1 -1
- data/lib/tasks/attorney_tasks.rake +4 -0
- data/spec/controllers/attorney/admin/documents_controller_spec.rb +130 -0
- data/spec/controllers/attorney/documents_controller_spec.rb +26 -0
- data/spec/features/attorney/admin/documents_spec.rb +87 -0
- data/spec/features/attorney/documents_spec.rb +19 -0
- data/spec/helpers/documents_helper_spec.rb +21 -0
- data/spec/lib/attorney_spec.rb +6 -0
- data/spec/models/attorney/document_spec.rb +28 -0
- data/spec/rails_helper.rb +109 -0
- data/spec/spec_helper.rb +96 -0
- data/spec/support/capybara.rb +1 -0
- data/spec/support/dummy/rails5_0/Rakefile +6 -0
- data/spec/support/dummy/rails5_0/app/assets/config/manifest.js +5 -0
- data/spec/support/dummy/rails5_0/app/assets/images/.keep +0 -0
- data/spec/support/dummy/rails5_0/app/assets/javascripts/application.js +13 -0
- data/spec/support/dummy/rails5_0/app/assets/javascripts/cable.js +13 -0
- data/spec/support/dummy/rails5_0/app/assets/javascripts/channels/.keep +0 -0
- data/spec/support/dummy/rails5_0/app/assets/stylesheets/application.css +15 -0
- data/spec/support/dummy/rails5_0/app/channels/application_cable/channel.rb +4 -0
- data/spec/support/dummy/rails5_0/app/channels/application_cable/connection.rb +4 -0
- data/spec/support/dummy/rails5_0/app/controllers/application_controller.rb +3 -0
- data/spec/support/dummy/rails5_0/app/controllers/concerns/.keep +0 -0
- data/spec/support/dummy/rails5_0/app/helpers/application_helper.rb +2 -0
- data/spec/support/dummy/rails5_0/app/jobs/application_job.rb +2 -0
- data/spec/support/dummy/rails5_0/app/mailers/application_mailer.rb +4 -0
- data/spec/support/dummy/rails5_0/app/models/application_record.rb +3 -0
- data/spec/support/dummy/rails5_0/app/models/concerns/.keep +0 -0
- data/spec/support/dummy/rails5_0/app/views/layouts/application.html.erb +15 -0
- data/spec/support/dummy/rails5_0/app/views/layouts/mailer.html.erb +13 -0
- data/spec/support/dummy/rails5_0/app/views/layouts/mailer.text.erb +1 -0
- data/spec/support/dummy/rails5_0/bin/bundle +3 -0
- data/spec/support/dummy/rails5_0/bin/rails +4 -0
- data/spec/support/dummy/rails5_0/bin/rake +4 -0
- data/spec/support/dummy/rails5_0/bin/setup +34 -0
- data/spec/support/dummy/rails5_0/bin/update +29 -0
- data/spec/support/dummy/rails5_0/config.ru +5 -0
- data/spec/support/dummy/rails5_0/config/application.rb +15 -0
- data/spec/support/dummy/rails5_0/config/boot.rb +5 -0
- data/spec/support/dummy/rails5_0/config/cable.yml +9 -0
- data/spec/support/dummy/rails5_0/config/database.yml +25 -0
- data/spec/support/dummy/rails5_0/config/environment.rb +5 -0
- data/spec/support/dummy/rails5_0/config/environments/development.rb +54 -0
- data/spec/support/dummy/rails5_0/config/environments/production.rb +86 -0
- data/spec/support/dummy/rails5_0/config/environments/test.rb +42 -0
- data/spec/support/dummy/rails5_0/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/support/dummy/rails5_0/config/initializers/assets.rb +11 -0
- data/spec/support/dummy/rails5_0/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/dummy/rails5_0/config/initializers/cookies_serializer.rb +5 -0
- data/spec/support/dummy/rails5_0/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/support/dummy/rails5_0/config/initializers/inflections.rb +16 -0
- data/spec/support/dummy/rails5_0/config/initializers/mime_types.rb +4 -0
- data/spec/support/dummy/rails5_0/config/initializers/new_framework_defaults.rb +26 -0
- data/spec/support/dummy/rails5_0/config/initializers/session_store.rb +3 -0
- data/spec/support/dummy/rails5_0/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/dummy/rails5_0/config/locales/en.yml +23 -0
- data/spec/support/dummy/rails5_0/config/puma.rb +47 -0
- data/spec/support/dummy/rails5_0/config/routes.rb +3 -0
- data/spec/support/dummy/rails5_0/config/secrets.yml +22 -0
- data/spec/support/dummy/rails5_0/config/spring.rb +6 -0
- data/spec/support/dummy/rails5_0/db/schema.rb +24 -0
- data/spec/support/dummy/rails5_0/lib/assets/.keep +0 -0
- data/spec/support/dummy/rails5_0/log/.keep +0 -0
- data/spec/support/dummy/rails5_0/public/404.html +67 -0
- data/spec/support/dummy/rails5_0/public/422.html +67 -0
- data/spec/support/dummy/rails5_0/public/500.html +66 -0
- data/spec/support/dummy/rails5_0/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/support/dummy/rails5_0/public/apple-touch-icon.png +0 -0
- data/spec/support/dummy/rails5_0/public/favicon.ico +0 -0
- data/spec/support/dummy/rails5_1/Rakefile +6 -0
- data/spec/support/dummy/rails5_1/app/assets/config/manifest.js +5 -0
- data/spec/support/dummy/rails5_1/app/assets/images/.keep +0 -0
- data/spec/support/dummy/rails5_1/app/assets/javascripts/application.js +13 -0
- data/spec/support/dummy/rails5_1/app/assets/javascripts/cable.js +13 -0
- data/spec/support/dummy/rails5_1/app/assets/javascripts/channels/.keep +0 -0
- data/spec/support/dummy/rails5_1/app/assets/stylesheets/application.css +15 -0
- data/spec/support/dummy/rails5_1/app/channels/application_cable/channel.rb +4 -0
- data/spec/support/dummy/rails5_1/app/channels/application_cable/connection.rb +4 -0
- data/spec/support/dummy/rails5_1/app/controllers/application_controller.rb +4 -0
- data/spec/support/dummy/rails5_1/app/controllers/concerns/.keep +0 -0
- data/spec/support/dummy/rails5_1/app/helpers/application_helper.rb +2 -0
- data/spec/support/dummy/rails5_1/app/jobs/application_job.rb +2 -0
- data/spec/support/dummy/rails5_1/app/mailers/application_mailer.rb +4 -0
- data/spec/support/dummy/rails5_1/app/models/application_record.rb +3 -0
- data/spec/support/dummy/rails5_1/app/models/concerns/.keep +0 -0
- data/spec/support/dummy/rails5_1/app/views/layouts/mailer.html.erb +13 -0
- data/spec/support/dummy/rails5_1/app/views/layouts/mailer.text.erb +1 -0
- data/spec/support/dummy/rails5_1/app/views/layouts/main.html.erb +15 -0
- data/spec/support/dummy/rails5_1/bin/bundle +3 -0
- data/spec/support/dummy/rails5_1/bin/rails +4 -0
- data/spec/support/dummy/rails5_1/bin/rake +4 -0
- data/spec/support/dummy/rails5_1/bin/setup +38 -0
- data/spec/support/dummy/rails5_1/bin/update +29 -0
- data/spec/support/dummy/rails5_1/bin/yarn +11 -0
- data/spec/support/dummy/rails5_1/config.ru +5 -0
- data/spec/support/dummy/rails5_1/config/application.rb +18 -0
- data/spec/support/dummy/rails5_1/config/boot.rb +5 -0
- data/spec/support/dummy/rails5_1/config/cable.yml +10 -0
- data/spec/support/dummy/rails5_1/config/database.yml +25 -0
- data/spec/support/dummy/rails5_1/config/environment.rb +5 -0
- data/spec/support/dummy/rails5_1/config/environments/development.rb +54 -0
- data/spec/support/dummy/rails5_1/config/environments/production.rb +91 -0
- data/spec/support/dummy/rails5_1/config/environments/test.rb +42 -0
- data/spec/support/dummy/rails5_1/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/support/dummy/rails5_1/config/initializers/assets.rb +14 -0
- data/spec/support/dummy/rails5_1/config/initializers/attorney.rb +1 -0
- data/spec/support/dummy/rails5_1/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/dummy/rails5_1/config/initializers/cookies_serializer.rb +5 -0
- data/spec/support/dummy/rails5_1/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/support/dummy/rails5_1/config/initializers/inflections.rb +16 -0
- data/spec/support/dummy/rails5_1/config/initializers/mime_types.rb +4 -0
- data/spec/support/dummy/rails5_1/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/dummy/rails5_1/config/locales/en.yml +33 -0
- data/spec/support/dummy/rails5_1/config/puma.rb +56 -0
- data/spec/support/dummy/rails5_1/config/routes.rb +3 -0
- data/spec/support/dummy/rails5_1/config/secrets.yml +32 -0
- data/spec/support/dummy/rails5_1/config/spring.rb +6 -0
- data/spec/support/dummy/rails5_1/db/schema.rb +24 -0
- data/spec/support/dummy/rails5_1/lib/assets/.keep +0 -0
- data/spec/support/dummy/rails5_1/log/.keep +0 -0
- data/spec/support/dummy/rails5_1/package.json +5 -0
- data/spec/support/dummy/rails5_1/public/404.html +67 -0
- data/spec/support/dummy/rails5_1/public/422.html +67 -0
- data/spec/support/dummy/rails5_1/public/500.html +66 -0
- data/spec/support/dummy/rails5_1/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/support/dummy/rails5_1/public/apple-touch-icon.png +0 -0
- data/spec/support/dummy/rails5_1/public/favicon.ico +0 -0
- data/spec/support/helpers/auth.rb +12 -0
- data/spec/support/shoulda_matchers.rb +8 -0
- data/vendor/assets/javascripts/attorney/bootstrap.bundle.min.js +7 -0
- data/vendor/assets/stylesheets/attorney/bootstrap.min.css +7 -0
- metadata +401 -28
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -5
- data/Gemfile +0 -6
- data/LICENSE.txt +0 -21
- data/README.md +0 -39
- data/attorney.gemspec +0 -25
- data/bin/console +0 -14
- data/bin/setup +0 -8
data/lib/attorney/version.rb
CHANGED
@@ -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,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
|