jinda 0.7.7.2 → 0.7.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (226) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -1
  3. data/app/config/routes.rb +44 -0
  4. data/lib/generators/jinda/templates/README.md +3 -1
  5. data/lib/generators/jinda/templates/app/assets/stylesheets/application.css.scss +2 -2
  6. data/lib/generators/jinda/templates/app/assets/stylesheets/jinda_jqm.css.scss +32 -0
  7. data/lib/generators/jinda/templates/app/mailers/{application_mailer.rb → application_mailer.rb-org} +0 -0
  8. data/lib/generators/jinda/templates/config/mongoid.yml +3 -3
  9. data/lib/jinda/version.rb +1 -1
  10. data/test/Gemfile +2 -0
  11. data/test/dummy/Dockerfile +26 -0
  12. data/test/dummy/Gemfile +99 -0
  13. data/test/dummy/Gemfile.lock +515 -0
  14. data/test/dummy/{db/development.sqlite3 → README.md} +0 -0
  15. data/test/dummy/README.md.bak +24 -0
  16. data/test/dummy/Rakefile +1 -1
  17. data/test/dummy/app/assets/config/manifest.js +2 -1
  18. data/test/dummy/app/assets/config/manifest.js-rails +2 -0
  19. data/test/dummy/app/assets/javascripts/application.js +15 -0
  20. data/test/dummy/app/assets/stylesheets/{application.css → application.css.bak} +3 -3
  21. data/test/dummy/app/assets/stylesheets/application.css.scss +15 -0
  22. data/test/dummy/app/assets/stylesheets/jinda_jqm.css.scss +32 -0
  23. data/test/dummy/app/controllers/admins_controller.rb +6 -0
  24. data/test/dummy/app/controllers/api/v1/notes_controller.rb +81 -0
  25. data/test/dummy/app/controllers/application_controller.rb +39 -0
  26. data/test/dummy/app/controllers/application_controller.rb.bak +2 -0
  27. data/test/dummy/app/controllers/articles_controller.rb +110 -0
  28. data/test/dummy/app/controllers/comments_controller.rb +31 -0
  29. data/test/dummy/app/controllers/docs_controller.rb +56 -0
  30. data/test/dummy/app/controllers/identities_controller.rb +5 -0
  31. data/test/dummy/app/controllers/notes_controller.rb +84 -0
  32. data/test/dummy/app/controllers/password_resets.rb +28 -0
  33. data/test/dummy/app/controllers/password_resets_controller.rb +34 -0
  34. data/test/dummy/app/controllers/sessions_controller.rb +44 -0
  35. data/test/dummy/app/controllers/sitemap_controller.rb +12 -0
  36. data/test/dummy/app/controllers/users_controller.rb +35 -0
  37. data/test/dummy/app/helpers/admins_helper.rb +2 -0
  38. data/test/dummy/app/helpers/application_helper.rb +31 -0
  39. data/test/dummy/app/helpers/application_helper.rb.bak +2 -0
  40. data/test/dummy/app/helpers/articles_helper.rb +2 -0
  41. data/test/dummy/app/helpers/basic_helper.rb +2 -0
  42. data/test/dummy/app/helpers/comments_helper.rb +2 -0
  43. data/test/dummy/app/helpers/ctrs_helper.rb +2 -0
  44. data/test/dummy/app/helpers/devs_helper.rb +2 -0
  45. data/test/dummy/app/helpers/pictures_helper.rb +2 -0
  46. data/test/dummy/app/helpers/sitemap_helper.rb +2 -0
  47. data/test/dummy/app/helpers/users_helper.rb +2 -0
  48. data/test/dummy/app/jinda/index.mm +486 -0
  49. data/test/dummy/app/jinda/template/index.mm +366 -0
  50. data/test/dummy/app/jinda/template/linkview.haml +21 -0
  51. data/test/dummy/app/jinda/template/view.html.erb +34 -0
  52. data/test/dummy/app/mailers/application_mailer.rb +2 -2
  53. data/test/dummy/app/mailers/application_mailer.rb-org +4 -0
  54. data/test/dummy/app/mailers/jinda_mailer.rb +7 -0
  55. data/test/dummy/app/mailers/note_mailer.rb +10 -0
  56. data/test/dummy/app/mailers/user_mailer.rb +15 -0
  57. data/test/dummy/app/models/address.rb +14 -0
  58. data/test/dummy/app/models/article.rb +14 -0
  59. data/test/dummy/app/models/comment.rb +14 -0
  60. data/test/dummy/app/models/identity.rb +18 -0
  61. data/test/dummy/app/models/jinda/doc.rb +36 -0
  62. data/test/dummy/app/models/jinda/module.rb +11 -0
  63. data/test/dummy/app/models/jinda/notice.rb +14 -0
  64. data/test/dummy/app/models/jinda/role.rb +8 -0
  65. data/test/dummy/app/models/jinda/runseq.rb +24 -0
  66. data/test/dummy/app/models/jinda/service.rb +17 -0
  67. data/test/dummy/app/models/jinda/xmain.rb +38 -0
  68. data/test/dummy/app/models/note.rb +22 -0
  69. data/test/dummy/app/models/param.rb +41 -0
  70. data/test/dummy/app/models/person.rb +14 -0
  71. data/test/dummy/app/models/user.rb +66 -0
  72. data/test/dummy/app/views/adminbsbs/content.haml +241 -0
  73. data/test/dummy/app/views/admins/edit_role/edit_role.html.erb +7 -0
  74. data/test/dummy/app/views/admins/edit_role/select_user.html.erb +4 -0
  75. data/test/dummy/app/views/api/v1/note.haml +0 -0
  76. data/test/dummy/app/views/articles/_report.haml +35 -0
  77. data/test/dummy/app/views/articles/edit.haml +23 -0
  78. data/test/dummy/app/views/articles/edit_article/edit_article.html.erb +15 -0
  79. data/test/dummy/app/views/articles/edit_article/select_article.html.erb +12 -0
  80. data/test/dummy/app/views/articles/index.haml +5 -0
  81. data/test/dummy/app/views/articles/my.haml +5 -0
  82. data/test/dummy/app/views/articles/new_article/form_article.html.erb +16 -0
  83. data/test/dummy/app/views/articles/show.html.haml +58 -0
  84. data/test/dummy/app/views/articles/xedit_article/edit_article.html.erb +13 -0
  85. data/test/dummy/app/views/ctrs/vfolder1/viewfile1.html.erb +23 -0
  86. data/test/dummy/app/views/ctrs/vfolder1/viewfile2.html.erb +23 -0
  87. data/test/dummy/app/views/ctrs/vfolder2/viewfile2.html.erb +23 -0
  88. data/test/dummy/app/views/custom/_adsense.haml +6 -0
  89. data/test/dummy/app/views/docs/doc_edit/doc_edit.html.erb +21 -0
  90. data/test/dummy/app/views/docs/doc_edit/doc_select.html.erb +14 -0
  91. data/test/dummy/app/views/docs/doc_new/doc_form.html.erb +32 -0
  92. data/test/dummy/app/views/docs/doc_new/doc_form.md +36 -0
  93. data/test/dummy/app/views/docs/doc_xedit/doc_edit.html.erb +21 -0
  94. data/test/dummy/app/views/docs/edit/select_note.html.erb +14 -0
  95. data/test/dummy/app/views/docs/index.haml +21 -0
  96. data/test/dummy/app/views/docs/my.haml +27 -0
  97. data/test/dummy/app/views/identities/new.html.haml +32 -0
  98. data/test/dummy/app/views/jinda/_activity.md +10 -0
  99. data/test/dummy/app/views/jinda/_menu.haml +27 -0
  100. data/test/dummy/app/views/jinda/_menu_mm.haml +44 -0
  101. data/test/dummy/app/views/jinda/_model.md +5 -0
  102. data/test/dummy/app/views/jinda/_modul.md +9 -0
  103. data/test/dummy/app/views/jinda/_pending_home.haml +5 -0
  104. data/test/dummy/app/views/jinda/_pending_page.haml +24 -0
  105. data/test/dummy/app/views/jinda/_service.md +24 -0
  106. data/test/dummy/app/views/jinda/_static.haml +13 -0
  107. data/test/dummy/app/views/jinda/doc-thai.md +37 -0
  108. data/test/dummy/app/views/jinda/doc.md +36 -0
  109. data/test/dummy/app/views/jinda/error_logs.haml +22 -0
  110. data/test/dummy/app/views/jinda/feed.rss.builder +27 -0
  111. data/test/dummy/app/views/jinda/help.haml +20 -0
  112. data/test/dummy/app/views/jinda/index.html.haml +53 -0
  113. data/test/dummy/app/views/jinda/logs.haml +22 -0
  114. data/test/dummy/app/views/jinda/notice_logs.haml +18 -0
  115. data/test/dummy/app/views/jinda/pending.haml +1 -0
  116. data/test/dummy/app/views/jinda/run_form.haml +42 -0
  117. data/test/dummy/app/views/jinda/run_output.haml +38 -0
  118. data/test/dummy/app/views/jinda/search.haml +20 -0
  119. data/test/dummy/app/views/jinda/status.haml +61 -0
  120. data/test/dummy/app/views/jinda_mailer/gmail.html.erb +9 -0
  121. data/test/dummy/app/views/layouts/_head.html.erb +10 -0
  122. data/test/dummy/app/views/layouts/_meta_tag.html.erb +19 -0
  123. data/test/dummy/app/views/layouts/application.haml +4 -0
  124. data/test/dummy/app/views/layouts/{application.html.erb → application.html.erb.bak} +2 -1
  125. data/test/dummy/app/views/layouts/bsb/_footer.haml +7 -0
  126. data/test/dummy/app/views/layouts/bsb/_header.haml +147 -0
  127. data/test/dummy/app/views/layouts/bsb/_menu.haml +47 -0
  128. data/test/dummy/app/views/layouts/bsb/_menu_mm.haml +34 -0
  129. data/test/dummy/app/views/layouts/bsb/_rightbar.haml +123 -0
  130. data/test/dummy/app/views/layouts/bsb/_sidebar.haml +155 -0
  131. data/test/dummy/app/views/layouts/bsb/application.haml-bsb +47 -0
  132. data/test/dummy/app/views/layouts/gmail.html.erb +9 -0
  133. data/test/dummy/app/views/layouts/jqm/_full.haml +33 -0
  134. data/test/dummy/app/views/layouts/jqm/_page.haml +16 -0
  135. data/test/dummy/app/views/layouts/jqm/application.haml-jqm +4 -0
  136. data/test/dummy/app/views/layouts/mailer.html.haml +3 -0
  137. data/test/dummy/app/views/layouts/mailer.text.haml +1 -0
  138. data/test/dummy/app/views/layouts/mobile.html.erb +13 -0
  139. data/test/dummy/app/views/layouts/mobilejq.html.erb +31 -0
  140. data/test/dummy/app/views/layouts/print.html.erb +22 -0
  141. data/test/dummy/app/views/layouts/utf8.html.erb +22 -0
  142. data/test/dummy/app/views/note_mailer/gmail.html.haml +7 -0
  143. data/test/dummy/app/views/note_mailer/gmail.text.haml +8 -0
  144. data/test/dummy/app/views/notes/delete/select_note.html.erb +14 -0
  145. data/test/dummy/app/views/notes/edit/edit_note.html.erb +10 -0
  146. data/test/dummy/app/views/notes/edit/select_note.html.erb +14 -0
  147. data/test/dummy/app/views/notes/index.haml +71 -0
  148. data/test/dummy/app/views/notes/mail/display_mail.html.erb +20 -0
  149. data/test/dummy/app/views/notes/mail/select_note.html.erb +19 -0
  150. data/test/dummy/app/views/notes/mail/show.html.haml +13 -0
  151. data/test/dummy/app/views/notes/my.haml +21 -0
  152. data/test/dummy/app/views/notes/new/new_note.html.erb +13 -0
  153. data/test/dummy/app/views/notes/show.haml +10 -0
  154. data/test/dummy/app/views/notes/xedit/edit_note.html.erb +10 -0
  155. data/test/dummy/app/views/password_resets/edit.html.erb +21 -0
  156. data/test/dummy/app/views/password_resets/new.html.haml +11 -0
  157. data/test/dummy/app/views/sessions/new.html.haml +22 -0
  158. data/test/dummy/app/views/sitemap/index.xml.haml +10 -0
  159. data/test/dummy/app/views/user_mailer/password_reset.html.haml +3 -0
  160. data/test/dummy/app/views/user_mailer/password_reset.text.erb +3 -0
  161. data/test/dummy/app/views/user_mailer/password_reset.text.haml +3 -0
  162. data/test/dummy/app/views/users/index.haml +13 -0
  163. data/test/dummy/app/views/users/pwd/enter.html.erb +6 -0
  164. data/test/dummy/app/views/users/user/enter_user.html.erb +10 -0
  165. data/test/dummy/bin/rails +3 -3
  166. data/test/dummy/bin/rake +2 -2
  167. data/test/dummy/bin/setup +9 -17
  168. data/test/dummy/config/application.rb +51 -9
  169. data/test/dummy/config/boot.rb +3 -4
  170. data/test/dummy/config/cloudinary.yml +9 -0
  171. data/test/dummy/config/credentials.yml.enc +1 -0
  172. data/test/dummy/config/environment.rb +7 -1
  173. data/test/dummy/config/environments/development.rb +20 -20
  174. data/test/dummy/config/environments/production.rb +16 -40
  175. data/test/dummy/config/environments/test.rb +19 -11
  176. data/test/dummy/config/initializers/assets.rb +1 -1
  177. data/test/dummy/config/initializers/content_security_policy.rb +21 -24
  178. data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -2
  179. data/test/dummy/config/initializers/fix_mongoid_generator.rb-org +14 -0
  180. data/test/dummy/config/initializers/inflections.rb +4 -4
  181. data/test/dummy/config/initializers/jinda.rb +14 -0
  182. data/test/dummy/config/initializers/mongoid.rb +10 -0
  183. data/test/dummy/config/initializers/omniauth.rb +17 -0
  184. data/test/dummy/config/initializers/permissions_policy.rb +11 -0
  185. data/test/dummy/config/locales/en.yml +3 -3
  186. data/test/dummy/config/mongoid.yml +196 -0
  187. data/test/dummy/config/mongoid.yml-docker +182 -0
  188. data/test/dummy/config/mongoid.yml-localhost +182 -0
  189. data/test/dummy/config/puma.rb +7 -2
  190. data/test/dummy/config/routes.rb +5 -1
  191. data/test/dummy/config.ru +2 -1
  192. data/test/dummy/db/seeds.rb +6 -0
  193. data/test/dummy/docker-compose.yml +19 -0
  194. data/test/dummy/dot/dot.env +2 -0
  195. data/test/dummy/entrypoint.sh +13 -0
  196. data/test/dummy/log/development.log +697 -6
  197. data/test/dummy/public/robots.txt +1 -0
  198. data/test/dummy/spec/controllers/api/v1_get_index_spec.rb +23 -0
  199. data/test/dummy/spec/controllers/api/v1_get_my_spec.rb +14 -0
  200. data/test/dummy/spec/controllers/api/v1_post_spec.rb +19 -0
  201. data/test/dummy/spec/controllers/sessions_controller_spec.rb +98 -0
  202. data/test/dummy/spec/features/userlogins_spec.rb +23 -0
  203. data/test/dummy/spec/mailers/note_spec.rb +24 -0
  204. data/test/dummy/spec/mailers/previews/note_preview.rb +9 -0
  205. data/test/dummy/spec/models/note_spec.rb +41 -0
  206. data/test/dummy/spec/models/user_spec.rb +12 -0
  207. data/test/dummy/spec/rails_helper.rb +42 -0
  208. data/test/dummy/spec/spec_helper.rb +80 -0
  209. data/test/dummy/spec/support/authentication_helper.rb +20 -0
  210. data/test/dummy/spec/support/databasecleaner.rb +13 -0
  211. data/test/dummy/spec/support/factory_bot.rb +12 -0
  212. data/test/dummy/spec/support/omniauth_macros.rb +38 -0
  213. data/test/dummy/spec/support/request_spec_helper.rb +8 -0
  214. data/test/dummy/spec/views/articles/_article.html.erb_spec.rbx +14 -0
  215. data/test/dummy/tmp/development_secret.txt +1 -1
  216. metadata +188 -17
  217. data/test/dummy/app/javascript/packs/application.js +0 -15
  218. data/test/dummy/app/models/application_record.rb +0 -3
  219. data/test/dummy/config/database.yml +0 -25
  220. data/test/dummy/config/initializers/application_controller_renderer.rb +0 -8
  221. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  222. data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  223. data/test/dummy/config/initializers/mime_types.rb +0 -4
  224. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  225. data/test/dummy/config/spring.rb +0 -6
  226. data/test/dummy/config/storage.yml +0 -34
@@ -0,0 +1 @@
1
+ # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
@@ -0,0 +1,23 @@
1
+ require 'rails_helper'
2
+ # describe Api::V1::NotesController, '#index', type: :request do
3
+ RSpec.describe 'Notes API', type: :request do
4
+ # let(:notes) { create_list(:note,1)}
5
+ # let!(:notes) {Note.create(title: "dddd", body: "body")}
6
+ let!(:note) {FactoryBot.create_list(:note, 9)}
7
+ let(:note_id) { notes.first.id }
8
+
9
+ describe 'GET /api/v1/notes' do
10
+ before { get api_v1_notes_path }
11
+
12
+ it 'returns notes size as expected' do
13
+ expect(json).not_to be_empty
14
+ expect(json.size).to eq(9)
15
+ end
16
+
17
+ it 'returns status code 200' do
18
+ expect(response).to have_http_status(:success)
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,14 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe 'Notes API', type: :request do
4
+ let!(:note) {FactoryBot.create_list(:note, 9)}
5
+ before {get api_v1_notes_my_path}
6
+
7
+ it 'returns all notes' do
8
+ expect(json.size).to eq(9)
9
+ end
10
+ it 'returns status code 200' do
11
+ expect(response).to have_http_status(:success)
12
+ end
13
+ end
14
+
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+ describe Api::V1::NotesController , type: :controller do
3
+
4
+ before do
5
+ create_and_sign_in_user
6
+ post :create , params: { :body => 'test_body', :title => 'test_title', :user => User.first}
7
+ end
8
+
9
+ it 'returns the title' do
10
+ expect(JSON.parse(@response.body)['title']).to eq('test_title')
11
+ end
12
+ it 'returns the body' do
13
+ expect(JSON.parse(@response.body)['body']).to eq('test_body')
14
+ end
15
+
16
+ it 'returns a created status' do
17
+ expect(response).to have_http_status(:created)
18
+ end
19
+ end
@@ -0,0 +1,98 @@
1
+ # sessions_controller_spec.rb
2
+ # 1. Set up the mock
3
+ # 2. Make the request
4
+ # 3. Test whatever code is attached to the callback
5
+ # require 'spec_helper'
6
+ require 'rails_helper'
7
+ describe SessionsController, type: :controller do
8
+
9
+ describe "Google" do
10
+
11
+ before do
12
+
13
+ @request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:google_oauth2]
14
+ visit '/auth/google_oauth2'
15
+ end
16
+
17
+ describe "#create" do
18
+
19
+ it "should successfully create a session" do
20
+ session[:user_id].should be_nil
21
+ post :create, params: {provider: :google_oauth2}
22
+ session[:user_id].should_not be_nil
23
+ end
24
+
25
+ it "should redirect the user to root_path " do
26
+ post :create, params: {provider: :google_oauth2}
27
+ response.should redirect_to root_path
28
+ end
29
+
30
+ end
31
+
32
+ #describe "#destroy", js: true do
33
+ describe "#destroy" do
34
+ before do
35
+ post :create, params: {provider: :google_oauth2}
36
+ end
37
+
38
+ it "should clear the session" do
39
+ session[:user_id].should_not be_nil
40
+ delete :destroy
41
+ session[:user_id].should be_nil
42
+ end
43
+
44
+ it "should redirect to the home page" do
45
+ delete :destroy
46
+ # response.should redirect_to root_url
47
+ # https://stackoverflow.com/questions/5144758/how-to-test-a-javascript-redirect-with-rspec
48
+ response.body.should include("window.location")
49
+ end
50
+ end
51
+ end
52
+
53
+ skip describe "Facebook" do
54
+ # skip or finish at config facebook
55
+
56
+ before do
57
+ @request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:facebook]
58
+ visit '/auth/facebook'
59
+ end
60
+
61
+ describe "#create" do
62
+
63
+ it "should successfully create a session" do
64
+ session[:user_id].should be_nil
65
+ post :create, params: {provider: :facebook}
66
+ session[:user_id].should_not be_nil
67
+ end
68
+
69
+ it "should redirect the user to the articles/my url" do
70
+ post :create, params: {provider: :facebook}
71
+ response.should redirect_to articles_my_path
72
+ end
73
+
74
+ end
75
+
76
+ describe "#destroy" do
77
+ before do
78
+ post :create, params: {provider: :facebook}
79
+ end
80
+
81
+ it "should clear the session" do
82
+ session[:user_id].should_not be_nil
83
+ delete :destroy
84
+ session[:user_id].should be_nil
85
+ end
86
+
87
+ it "should redirect to the home page" do
88
+ delete :destroy
89
+ # response.should redirect_to root_url
90
+ # https://stackoverflow.com/questions/5144758/how-to-test-a-javascript-redirect-with-rspec
91
+ response.body.should include("window.location")
92
+ end
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+
@@ -0,0 +1,23 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.feature "Userlogins", type: :feature do
4
+ scenario "Admin User Sign In" do
5
+ skip visit "/sessions/new"
6
+
7
+ fill_in "User name", :with => "admin"
8
+ fill_in "Password", :with => "secret1"
9
+ click_button "Sign In"
10
+
11
+ xexpect(page).to have_text("My Articles")
12
+ end
13
+
14
+ scenario "Google User Sign In" do
15
+ visit "/auth/google_oauth2"
16
+ expect(page).to have_text("My Articles")
17
+ end
18
+
19
+
20
+
21
+
22
+
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe NoteMailer do
4
+
5
+
6
+ describe 'gmail' do
7
+
8
+ let(:mail) {NoteMailer.gmail("Test Body", "receiver@email.com", "Test title", "from@example.com")}
9
+
10
+
11
+ it 'renders the subject' do
12
+ expect(mail.subject).to eql('Test title')
13
+ end
14
+
15
+ it 'renders the receiver email' do
16
+ expect(mail.to).to eql(['receiver@email.com'])
17
+ end
18
+
19
+ it 'renders the sender email' do
20
+ expect(mail.from).to eql(['from@example.com'])
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,9 @@
1
+ # Preview all emails at http://localhost:3000/rails/mailers/note
2
+ class NotePreview < ActionMailer::Preview
3
+
4
+ # Preview this email at http://localhost:3000/rails/mailers/note/gmail
5
+ def gmail
6
+ NoteMailer.gmail
7
+ end
8
+
9
+ end
@@ -0,0 +1,41 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Note, type: :model do
4
+ describe "Required only title (Maximum 30)" do
5
+
6
+ it "valid with both title and body" do
7
+ before_count = Note.count
8
+ Note.create(title: "dddd", body: "body")
9
+ expect(Note.count).not_to eq(before_count)
10
+ end
11
+
12
+ it "valid with only title" do
13
+ before_count = Note.count
14
+ Note.create(title: "Title")
15
+ expect(Note.count).not_to eq(before_count)
16
+ end
17
+
18
+ it "invalid with only body" do
19
+ before_count = Note.count
20
+ Note.new(body: "body")
21
+ expect(Note.count).to eq(before_count)
22
+ end
23
+
24
+ it "invalid body length more than 1000" do
25
+ before_count = Note.count
26
+ title_max = "x"*30
27
+ body_max = "y"*1001
28
+ Note.create(title: title_max, body: body_max)
29
+ expect(Note.count).to eq(before_count)
30
+ end
31
+ end
32
+
33
+ describe "title data blank" do
34
+ it "auto fill from body" do
35
+ note = Note.create(:title => "", :body => "Body content")
36
+ note.title.should == "Body content"
37
+ end
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,12 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "User", :type => :model do
4
+ it "prevents duplicates " do
5
+ user1 = create(:user, code: 'abc', email: 'test@email.com')
6
+ user2 = build(:user, code: 'abc', email: 'test@email.com')
7
+
8
+ user1.should be_valid
9
+ #user2.should be_valid
10
+ user2.should_not have_valid(:code)
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+ require File.expand_path('../../config/environment', __FILE__)
4
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } # Add this at top of file
5
+ # Prevent database truncation if the environment is production
6
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
7
+ require 'rspec/rails'
8
+ require 'spec_helper'
9
+
10
+ RSpec.configure do |config|
11
+
12
+ # Add create_and_sign_in_user
13
+ config.include AuthenticationHelper, type: :controller
14
+
15
+ # To include RequestSpecHelper
16
+ config.include RequestSpecHelper, type: :request
17
+
18
+ # config.infer_spec_type_from_file_location!
19
+
20
+ # Filter lines from Rails gems in backtraces.
21
+ config.filter_rails_from_backtrace!
22
+ # arbitrary gems may also be filtered via:
23
+ # config.filter_gems_from_backtrace("gem name")
24
+
25
+
26
+
27
+ # Added to make factorybot work
28
+ # FactoryBot.allow_class_lookup = false
29
+ config.use_transactional_fixtures = false
30
+ config.include FactoryBot::Syntax::Methods
31
+ config.before do
32
+ FactoryBot.find_definitions
33
+ end
34
+ # configure shoulda matchers to use rspec as the test framework and full matcher libraries for rails
35
+ Shoulda::Matchers.configure do |config|
36
+ config.integrate do |with|
37
+ with.test_framework :rspec
38
+ with.library :rails
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,80 @@
1
+ # https://www.natashatherobot.com/rails-test-omniauth-sessions-controller/
2
+ # spec_helper.rb
3
+ require 'rubygems'
4
+ require 'capybara/rspec'
5
+ # Set up the mock
6
+ require 'support/omniauth_macros'
7
+ require 'valid_attribute'
8
+
9
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
+ RSpec.configure do |config|
11
+ config.filter_run focus: true
12
+ config.run_all_when_everything_filtered = true
13
+
14
+ # config.include SpecTestHelper, :type => :controller
15
+ config.expect_with :rspec do |expectations|
16
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
17
+ expectations.syntax = [:expect, :should]
18
+ end
19
+ config.mock_with :rspec do |mocks|
20
+ mocks.verify_partial_doubles = true
21
+ end
22
+ config.shared_context_metadata_behavior = :apply_to_host_groups
23
+
24
+ # https://github.com/DatabaseCleaner/database_cleaner #
25
+ # config.use_transactional_fixtures = false
26
+ # https://stackoverflow.com/questions/15148585/undefined-method-visit-when-using-rspec-and-capybara-in-rails
27
+ config.include Capybara::DSL
28
+
29
+ # https://stackoverflow.com/questions/21445164/set-chrome-as-default-browser-for-rspec-capybara/30551595
30
+ Capybara.register_driver :chrome do |app|
31
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
32
+ end
33
+ Capybara.javascript_driver = :chrome
34
+
35
+ config.before(:suite) do
36
+ if config.use_transactional_fixtures?
37
+ raise(<<-MSG)
38
+ Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
39
+ (or set it to false) to prevent uncommitted transactions being used in
40
+ JavaScript-dependent specs.
41
+
42
+ During testing, the app-under-test that the browser driver connects to
43
+ uses a different database connection to the database connection used by
44
+ the spec. The app's database connection would not be able to access
45
+ uncommitted transaction data setup over the spec's database connection.
46
+ MSG
47
+ end
48
+ DatabaseCleaner.clean_with(:deletion)
49
+ end
50
+
51
+ config.before(:each, :js => true) do
52
+ #DatabaseCleaner.strategy = :transaction
53
+ DatabaseCleaner.strategy = :deletion
54
+ end
55
+
56
+ config.before(:each, type: :feature) do
57
+ # :rack_test driver's Rack app under test shares database connection
58
+ # with the specs, so continue to use transaction strategy for speed.
59
+ driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
60
+
61
+ unless driver_shares_db_connection_with_specs
62
+ # Driver is probably for an external browser with an app
63
+ # under test that does *not* share a database connection with the
64
+ # specs, so use truncation strategy.
65
+ # DatabaseCleaner.strategy = :truncation
66
+ DatabaseCleaner[:mongoid].strategy = :deletion
67
+
68
+ end
69
+ end
70
+
71
+ config.before(:each) do
72
+ DatabaseCleaner.start
73
+ end
74
+
75
+ config.append_after(:each) do
76
+ DatabaseCleaner.clean
77
+ end
78
+ # https://github.com/DatabaseCleaner/database_cleaner #
79
+
80
+ end
@@ -0,0 +1,20 @@
1
+ module AuthenticationHelper
2
+ # controller return 1. Session 2. Cookies ==> user.id
3
+ def sign_in(user)
4
+ @user = user
5
+ current_ma_user
6
+ end
7
+
8
+ def create_and_sign_in_user
9
+ user = FactoryBot.create(:user)
10
+ sign_in(user)
11
+ return user
12
+ end
13
+ # from Jinda::Helpers
14
+ def current_ma_user
15
+ @user ||= User.where(:auth_token => user.auth_token)
16
+ return @user
17
+ end
18
+
19
+ end
20
+
@@ -0,0 +1,13 @@
1
+ RSpec.configure do |config|
2
+ config.before(:suite) do
3
+ DatabaseCleaner[:mongoid].strategy = :deletion
4
+ end
5
+
6
+ config.before(:each) do
7
+ DatabaseCleaner[:mongoid].start
8
+ end
9
+
10
+ config.after(:each) do
11
+ DatabaseCleaner[:mongoid].clean
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ FactoryBot.define do
2
+ factory :user, class: 'User' do
3
+ code {Faker::Name.unique.name}
4
+ email {Faker::Internet.email}
5
+ role {"Admin"}
6
+ end
7
+ factory :note, class: 'Note' do
8
+ title { Faker::Lorem.sentence[0..29] }
9
+ body { Faker::Lorem.sentence[0..999] }
10
+ user { User.first }
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ # in spec/support/omniauth_macro.rb
2
+ module OmniauthMacros
3
+ require 'omniauth'
4
+ #To enable all request to OmniAuth short circuited to use below mock authentication hash the /auth/provider will redirect immediately to /auth/provider/call back
5
+ # https://github.com/omniauth/omniauth/wiki/Integration-Testing
6
+ OmniAuth.config.test_mode = true
7
+
8
+ omniauth_hash = { 'provider' => 'google_oauth2',
9
+ 'uid' => '105362273761620533373',
10
+ 'info' => {
11
+ 'name' => 'Kulsoft',
12
+ 'email' => 'kulsoft.net@gmail.com',
13
+ 'nickname' => 'kulsoft'
14
+ },
15
+ 'extra' => {'raw_info' =>
16
+ { 'location' => 'San Francisco',
17
+ 'gravatar_id' => '123456789'
18
+ }
19
+ }
20
+ }
21
+ OmniAuth.config.add_mock(:google_oauth2, omniauth_hash)
22
+
23
+ omniauth_hash = { 'provider' => 'facebook',
24
+ 'uid' => '105362273761620533373',
25
+ 'info' => {
26
+ 'name' => 'Peter Colling',
27
+ 'email' => '1.0@kul.asia',
28
+ 'nickname' => 'Peter C'
29
+ },
30
+ 'extra' => {'raw_info' =>
31
+ {'location' => 'LA',
32
+ 'gravatar_id' => '13'
33
+ }
34
+ }
35
+ }
36
+ OmniAuth.config.add_mock(:facebook, omniauth_hash)
37
+ end
38
+
@@ -0,0 +1,8 @@
1
+ #request_spec_helper.rb
2
+
3
+ module RequestSpecHelper
4
+ # Parse JSON response to ruby hash
5
+ def json
6
+ JSON.parse(response.body)
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ let login_as_admin
2
+
3
+ describe 'articles/_article.html.erb' do
4
+ context 'when the article has a url' do
5
+ it 'display the url' do
6
+ assign(:article, Article.build(:article, url: 'http://localhost:3000/jinda/init?s=articles:new_article'))
7
+
8
+ render
9
+
10
+ expect(rendered).to have_link 'Article', href: 'http://localhost:3000/jinda/init?s=articles:new_article'
11
+ end
12
+ end
13
+ end
14
+
@@ -1 +1 @@
1
- ed037445cbae00e522e0ae7084e3ae3eab071d24f0fba72dbb378200933e6236f4b34dfefa6ab52f5f8706866e1d5375f4a333492676885e0ecc1ad289ed4cd8
1
+ a6747a3d62d47f33fa1801293541d77b45499aae94910fa3febf6b0b53d136fac5e3e811f2275211f59d39ba077033477a8f0717459bffde0e1654237986f97e