symphonia 2.1.7

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 (188) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +674 -0
  3. data/README.md +16 -0
  4. data/Rakefile +44 -0
  5. data/app/assets/images/bg-checker.png +0 -0
  6. data/app/assets/images/bullet.gif +0 -0
  7. data/app/assets/images/close.png +0 -0
  8. data/app/assets/images/loading.gif +0 -0
  9. data/app/assets/images/next.png +0 -0
  10. data/app/assets/images/prev.png +0 -0
  11. data/app/assets/javascripts/ckeditor/plugins/autogrow/plugin.js +232 -0
  12. data/app/assets/javascripts/ckeditor/plugins/autogrow/samples/autogrow.html +102 -0
  13. data/app/assets/javascripts/ckeditor/plugins/image_chooser/icons/addimage.png +0 -0
  14. data/app/assets/javascripts/ckeditor/plugins/image_chooser/plugin.js +15 -0
  15. data/app/assets/javascripts/symphonia/Sortable.js +1249 -0
  16. data/app/assets/javascripts/symphonia/_core.js +45 -0
  17. data/app/assets/javascripts/symphonia/application.js.erb +147 -0
  18. data/app/assets/javascripts/symphonia/filters.js +44 -0
  19. data/app/assets/javascripts/symphonia/symphonia_bootstrap_dialog.js +136 -0
  20. data/app/assets/javascripts/symphonia/symphonia_ckeditor.js +55 -0
  21. data/app/assets/stylesheets/symphonia/application.css +4 -0
  22. data/app/assets/stylesheets/symphonia/basic.scss +218 -0
  23. data/app/assets/stylesheets/symphonia/filters.scss +19 -0
  24. data/app/assets/stylesheets/symphonia/symphonia_bootstrap.scss +56 -0
  25. data/app/channels/application_cable/channel.rb +5 -0
  26. data/app/controllers/symphonia/accounts_controller.rb +169 -0
  27. data/app/controllers/symphonia/admin_controller.rb +22 -0
  28. data/app/controllers/symphonia/api_controller.rb +64 -0
  29. data/app/controllers/symphonia/application_controller.rb +8 -0
  30. data/app/controllers/symphonia/attachments_controller.rb +37 -0
  31. data/app/controllers/symphonia/filters_controller.rb +23 -0
  32. data/app/controllers/symphonia/images_controller.rb +16 -0
  33. data/app/controllers/symphonia/login_controller.rb +80 -0
  34. data/app/controllers/symphonia/roles_controller.rb +100 -0
  35. data/app/controllers/symphonia/user_sessions_controller.rb +16 -0
  36. data/app/controllers/symphonia/users_controller.rb +168 -0
  37. data/app/helpers/symphonia/application_helper.rb +422 -0
  38. data/app/helpers/symphonia/bootstrap_modal_helper.rb +59 -0
  39. data/app/helpers/symphonia/form_helper.rb +50 -0
  40. data/app/helpers/symphonia/renderer_helper.rb +85 -0
  41. data/app/mailers/symphonia/application_mailer.rb +6 -0
  42. data/app/mailers/symphonia/notifier.rb +42 -0
  43. data/app/models/symphonia/admin_module.rb +18 -0
  44. data/app/models/symphonia/application_record.rb +14 -0
  45. data/app/models/symphonia/attachment.rb +16 -0
  46. data/app/models/symphonia/common_file.rb +9 -0
  47. data/app/models/symphonia/email_preference.rb +5 -0
  48. data/app/models/symphonia/image.rb +46 -0
  49. data/app/models/symphonia/preference.rb +12 -0
  50. data/app/models/symphonia/role.rb +55 -0
  51. data/app/models/symphonia/swagger/error_model.rb +19 -0
  52. data/app/models/symphonia/swagger/responses.rb +27 -0
  53. data/app/models/symphonia/user.rb +141 -0
  54. data/app/models/symphonia/user_session.rb +19 -0
  55. data/app/views/common/403.html.erb +5 -0
  56. data/app/views/common/404.html.erb +2 -0
  57. data/app/views/layouts/symphonia/_modal.html.erb +19 -0
  58. data/app/views/layouts/symphonia/_query.html.erb +51 -0
  59. data/app/views/layouts/symphonia/application.html.erb +45 -0
  60. data/app/views/layouts/symphonia/application.pdf.erb +15 -0
  61. data/app/views/layouts/symphonia/mailer.html.erb +13 -0
  62. data/app/views/symphonia/accounts/_detail.html.erb +65 -0
  63. data/app/views/symphonia/accounts/_form.html.erb +14 -0
  64. data/app/views/symphonia/accounts/edit.html.erb +9 -0
  65. data/app/views/symphonia/accounts/edit.js.erb +5 -0
  66. data/app/views/symphonia/accounts/lost_password.html.erb +6 -0
  67. data/app/views/symphonia/accounts/lost_password.js.erb +3 -0
  68. data/app/views/symphonia/accounts/new_activation.html.erb +11 -0
  69. data/app/views/symphonia/accounts/new_activation.js.erb +6 -0
  70. data/app/views/symphonia/accounts/register.html.erb +20 -0
  71. data/app/views/symphonia/accounts/reset_password.html.erb +18 -0
  72. data/app/views/symphonia/accounts/update.js.erb +1 -0
  73. data/app/views/symphonia/admin/index.html.erb +15 -0
  74. data/app/views/symphonia/attachments/destroy.js.erb +1 -0
  75. data/app/views/symphonia/common/_editable_images_grid.html.erb +12 -0
  76. data/app/views/symphonia/common/_filters.html.erb +23 -0
  77. data/app/views/symphonia/common/_locale_chooser.html.erb +16 -0
  78. data/app/views/symphonia/common/_share_links.html.erb +5 -0
  79. data/app/views/symphonia/filters/options.html.erb +36 -0
  80. data/app/views/symphonia/filters/options.js.erb +9 -0
  81. data/app/views/symphonia/filters/table.html.erb +21 -0
  82. data/app/views/symphonia/login/_form.html.erb +19 -0
  83. data/app/views/symphonia/login/new.html.erb +11 -0
  84. data/app/views/symphonia/login_sessions/new.html.erb +1 -0
  85. data/app/views/symphonia/notifier/activation_user.html.erb +7 -0
  86. data/app/views/symphonia/notifier/activation_user.text.erb +3 -0
  87. data/app/views/symphonia/notifier/reset_password_user.html.erb +7 -0
  88. data/app/views/symphonia/notifier/reset_password_user.text.erb +3 -0
  89. data/app/views/symphonia/notifier/test_mail.html.erb +2 -0
  90. data/app/views/symphonia/notifier/test_mail.text.erb +3 -0
  91. data/app/views/symphonia/notifier/user_change_to_active.html.erb +3 -0
  92. data/app/views/symphonia/notifier/user_change_to_active.text.erb +1 -0
  93. data/app/views/symphonia/notifier/user_registered.html.erb +13 -0
  94. data/app/views/symphonia/notifier/user_registered.text.erb +8 -0
  95. data/app/views/symphonia/roles/_form.html.erb +30 -0
  96. data/app/views/symphonia/roles/edit.html.erb +5 -0
  97. data/app/views/symphonia/roles/index.html.erb +6 -0
  98. data/app/views/symphonia/roles/new.html.erb +4 -0
  99. data/app/views/symphonia/roles/show.html.erb +5 -0
  100. data/app/views/symphonia/users/_form.html.erb +13 -0
  101. data/app/views/symphonia/users/edit.html.erb +26 -0
  102. data/app/views/symphonia/users/edit.js.erb +3 -0
  103. data/app/views/symphonia/users/edit_current.html.erb +7 -0
  104. data/app/views/symphonia/users/index.html.erb +5 -0
  105. data/app/views/symphonia/users/new.html.erb +8 -0
  106. data/app/views/symphonia/users/show.html.erb +63 -0
  107. data/config/locales/cs.yml +233 -0
  108. data/config/locales/en.yml +47 -0
  109. data/config/routes.rb +52 -0
  110. data/db/migrate/20130714140500_create_users.rb +49 -0
  111. data/db/migrate/20130714140501_create_roles.rb +16 -0
  112. data/db/migrate/20130714140502_create_preferences.rb +26 -0
  113. data/db/migrate/20130828175114_create_attachments.rb +20 -0
  114. data/db/migrate/20141213204351_create_admin_modules.rb +20 -0
  115. data/db/seeds.rb +12 -0
  116. data/lib/generators/symphonia/entity_controller/entity_controller_generator.rb +48 -0
  117. data/lib/generators/symphonia/entity_controller/templates/controller.rb +100 -0
  118. data/lib/generators/symphonia/query/query_generator.rb +37 -0
  119. data/lib/generators/symphonia/setup/setup_generator.rb +52 -0
  120. data/lib/generators/symphonia/setup/templates/404.html +26 -0
  121. data/lib/generators/symphonia/setup/templates/500.html +37 -0
  122. data/lib/generators/symphonia/setup/templates/Gemfile +18 -0
  123. data/lib/generators/symphonia/setup/templates/base_layout.html.erb +46 -0
  124. data/lib/generators/symphonia/setup/templates/design.scss +4 -0
  125. data/lib/generators/symphonia/setup/templates/settings.rb +65 -0
  126. data/lib/generators/symphonia/setup/templates/spec_helper.rb +18 -0
  127. data/lib/symphonia/action_cable/connection.rb +31 -0
  128. data/lib/symphonia/admin_constraint.rb +9 -0
  129. data/lib/symphonia/attachable.rb +35 -0
  130. data/lib/symphonia/base_controller.rb +96 -0
  131. data/lib/symphonia/bootstrap_link_render.rb +69 -0
  132. data/lib/symphonia/controller_extensions.rb +200 -0
  133. data/lib/symphonia/engine.rb +137 -0
  134. data/lib/symphonia/form_builder.rb +137 -0
  135. data/lib/symphonia/menu_manager.rb +23 -0
  136. data/lib/symphonia/model_attributes/attribute.rb +137 -0
  137. data/lib/symphonia/model_attributes.rb +102 -0
  138. data/lib/symphonia/model_filters/base.rb +82 -0
  139. data/lib/symphonia/model_filters/boolean_filter.rb +26 -0
  140. data/lib/symphonia/model_filters/date_filter.rb +81 -0
  141. data/lib/symphonia/model_filters/integer_filter.rb +18 -0
  142. data/lib/symphonia/model_filters/select_filter.rb +48 -0
  143. data/lib/symphonia/model_filters/string_filter.rb +18 -0
  144. data/lib/symphonia/model_filters.rb +10 -0
  145. data/lib/symphonia/object.rb +31 -0
  146. data/lib/symphonia/permissions.rb +93 -0
  147. data/lib/symphonia/query.rb +275 -0
  148. data/lib/symphonia/query_columns/attribute_column.rb +43 -0
  149. data/lib/symphonia/query_columns/generic_column.rb +165 -0
  150. data/lib/symphonia/query_columns.rb +8 -0
  151. data/lib/symphonia/spec_helper.rb +4 -0
  152. data/lib/symphonia/user_management.rb +58 -0
  153. data/lib/symphonia/version.rb +4 -0
  154. data/lib/symphonia.rb +20 -0
  155. data/spec/controllers/account_controller_spec.rb +90 -0
  156. data/spec/controllers/admin_controller_spec.rb +35 -0
  157. data/spec/controllers/api_controller_spec.rb +9 -0
  158. data/spec/controllers/filters_controller_spec.rb +35 -0
  159. data/spec/controllers/images_controller_spec.rb +5 -0
  160. data/spec/controllers/login_controller_spec.rb +20 -0
  161. data/spec/controllers/roles_controller_spec.rb +12 -0
  162. data/spec/controllers/users_controller_spec.rb +47 -0
  163. data/spec/factories/factories.rb +52 -0
  164. data/spec/helpers/symphonia/application_helper_spec.rb +62 -0
  165. data/spec/mailers/previews/symphonia/notifier_preview.rb +27 -0
  166. data/spec/mailers/symphonia/notifier_spec.rb +76 -0
  167. data/spec/models/attachment_spec.rb +22 -0
  168. data/spec/models/query/attribute_spec.rb +8 -0
  169. data/spec/models/query/symphonia_query_spec.rb +70 -0
  170. data/spec/models/role_spec.rb +13 -0
  171. data/spec/models/user_spec.rb +10 -0
  172. data/spec/rails_helper.rb +13 -0
  173. data/spec/requests/accounts_spec.rb +118 -0
  174. data/spec/requests/attachments_controller_spec.rb +23 -0
  175. data/spec/requests/login_spec.rb +26 -0
  176. data/spec/requests/roles_spec.rb +10 -0
  177. data/spec/requests/users_spec.rb +50 -0
  178. data/spec/spec_helper.rb +101 -0
  179. data/spec/support/common_file.txt +2 -0
  180. data/spec/support/query.rb +36 -0
  181. data/spec/support/shared.rb +62 -0
  182. data/spec/support/shared_controllers.rb +31 -0
  183. data/spec/support/stub_users.rb +32 -0
  184. data/spec/support/symphonia.jpg +0 -0
  185. data/spec/support/wait_for_ajax.rb +15 -0
  186. data/spec/version_spec.rb +5 -0
  187. data/spec/views/filters/options.html.erb_spec.rb +14 -0
  188. metadata +697 -0
@@ -0,0 +1,9 @@
1
+ module Symphonia
2
+ RSpec.describe ApiController do
3
+ routes { Symphonia::Engine.routes }
4
+
5
+ it "#index" do
6
+ get :index
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ module Symphonia
2
+ RSpec.describe FiltersController do
3
+ routes { Symphonia::Engine.routes }
4
+
5
+ context 'no user' do
6
+
7
+ it '#options' do
8
+ get :options, params: { type: 'User' }
9
+ expect(response).to redirect_to login_path
10
+ end
11
+
12
+ end
13
+
14
+ context 'logged in', logged: true do
15
+
16
+ context 'without valid params' do
17
+
18
+ it '#options' do
19
+ get :options, params: { type: 'User' }
20
+ expect(response).to have_http_status :not_found
21
+ end
22
+
23
+ end
24
+
25
+ context 'correct' do
26
+
27
+ it '#options' do
28
+ get :options, params: { type: 'Symphonia::User' }
29
+ expect(response).to have_http_status :success
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Symphonia
2
+ RSpec.describe ImagesController do
3
+
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ class DummyController < ::ApplicationController
2
+ include Symphonia::ControllerExtensions
3
+ before_action :require_admin
4
+ end
5
+
6
+ RSpec.describe ::DummyController, type: :controller do
7
+
8
+ controller do
9
+ def admin_action
10
+ raise StandardError
11
+ end
12
+ end
13
+
14
+ it "redirect to login form" do
15
+ routes.draw { get "admin_action", to: "dummy#admin_action" }
16
+ get :admin_action
17
+ expect(response).to redirect_to("/login")
18
+ end
19
+
20
+ end
@@ -0,0 +1,12 @@
1
+ # require_relative '../spec_helper.rb'
2
+
3
+ module Symphonia
4
+ describe RolesController, type: 'controller', logged: :admin do
5
+ routes { Symphonia::Engine.routes }
6
+ subject { Symphonia::Role }
7
+
8
+ include_examples 'a controller actions', :role
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,47 @@
1
+ # require_relative '../spec_helper.rb'
2
+ module Symphonia
3
+ describe UsersController, type: 'controller' do
4
+ routes { Symphonia::Engine.routes }
5
+ subject { Symphonia::User }
6
+
7
+ let(:user) { FactoryBot.create(:user) }
8
+
9
+ context 'as admin', logged: :admin do
10
+ include ActiveJob::TestHelper
11
+
12
+ include_examples 'a controller actions', :user
13
+
14
+ context 'not found' do
15
+ it '#show' do
16
+ get :show, params: {id: 0 }
17
+ expect(response).to have_http_status :not_found
18
+ end
19
+ end
20
+
21
+ it '#archive' do
22
+ user.update_columns status: 'active'
23
+ expect ( post :archive, params: { id: user } )
24
+ expect(response).to redirect_to users_url
25
+ expect(user.reload.status).to eq 'archived'
26
+ end
27
+
28
+ it '#unarchive' do
29
+ user.update_columns status: 'archived'
30
+ expect( post :unarchive, params: { id: user } )
31
+ expect(ActionMailer::DeliveryJob).to have_been_enqueued
32
+ expect(response).to redirect_to users_url
33
+ expect(user.reload.status).to eq 'active'
34
+ end
35
+ end
36
+
37
+ context 'as regular use', logged: true do
38
+
39
+ it '#index' do
40
+ get :index
41
+ expect(response).to have_http_status :forbidden
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,52 @@
1
+ FactoryBot.define do
2
+ factory :user, class: 'Symphonia::User' do
3
+ sequence(:first_name) { |n| "#{Faker::Name.first_name} #{n}" }
4
+ sequence(:last_name) { |n| "#{Faker::Name.last_name} #{n}" }
5
+ sequence(:email) { |n| "#{n}" + Faker::Internet.email }
6
+ login { email }
7
+ admin { false }
8
+ password { SecureRandom.hex(16) }
9
+ password_confirmation { password }
10
+ last_request_at { Time.now }
11
+
12
+ trait :admin do
13
+ admin { true }
14
+ end
15
+
16
+ trait :with_preferences do
17
+ transient do
18
+ preference_names { [] }
19
+ end
20
+ after(:build) do |user, evaluator|
21
+ user.preferences = evaluator.preference_names.collect { |pref_name| FactoryBot.create(:email_preference, name: pref_name) }
22
+ end
23
+ end
24
+ factory :admin_user, traits: [:admin]
25
+ end
26
+
27
+ factory :role, class: 'Symphonia::Role' do
28
+ sequence(:name) { |n| "#{Faker::Job.title} #{n}" }
29
+ end
30
+
31
+ factory :attachment, class: 'Symphonia::Attachment' do
32
+ association :attachable, factory: :user
33
+ end
34
+
35
+ factory :file, parent: :attachment, class: 'Symphonia::CommonFile' do
36
+ attachment { File.new(File.expand_path('../../support/common_file.txt', __FILE__)) }
37
+ end
38
+
39
+ factory :image, parent: :attachment, class: 'Symphonia::Image' do
40
+ attachment { File.new(File.expand_path('../../support/symphonia.jpg', __FILE__)) }
41
+ end
42
+
43
+ factory :preference, class: 'Symphonia::Preference' do
44
+
45
+ factory :email_preference, class: 'Symphonia::EmailPreference' do
46
+ trait :user_registered do
47
+ name { :notify_after_user_registered }
48
+ end
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,62 @@
1
+ RSpec.describe Symphonia::ApplicationHelper do
2
+ describe "#title" do
3
+ it "returns the default title" do
4
+ expect(helper.title("Holub")).to match /<(h1)\s.*id=\Wpage_header\W\s.*Holub<\/\1>/
5
+ end
6
+
7
+ it "with symbol" do
8
+ expect(helper.title(:title)).to match /<(h1)\s.*id=\Wpage_header\W\s.*Title<\/\1>/
9
+ end
10
+
11
+ it "with back" do
12
+ expect(helper.title("Head", back: true)).to include "history.back()"
13
+ end
14
+
15
+ it "with custom back" do
16
+ expect(helper.title("Head", back: "/path")).to include "/path"
17
+ end
18
+
19
+ it "xhr without back" do
20
+ allow(helper.request).to receive(:xhr?).and_return true
21
+ expect(helper.title("Head", back: true)).to match /<(h5)\s.*id=\Wpage_header\W\s.*Head<\/\1>/
22
+ end
23
+ end
24
+
25
+ describe "#render_flash_messages" do
26
+ it "render error" do
27
+ r = helper.render_flash_messages(error: "flash message")
28
+ expect(r).to include "danger"
29
+ end
30
+ it "render notice" do
31
+ r = helper.render_flash_messages(notice: "flash message")
32
+ expect(r).to include "success"
33
+ end
34
+ it "render warning" do
35
+ r = helper.render_flash_messages(warning: "flash message")
36
+ expect(r).to include "warning"
37
+ end
38
+ it "render info" do
39
+ r = helper.render_flash_messages(info: "flash message")
40
+ expect(r).to include "info"
41
+ end
42
+ end
43
+
44
+ describe "#format_html" do
45
+ it "plain text" do
46
+ expect(helper.format_html("sojka")).to eq "<div class=\"formatted-text\"><p>sojka</p>\n</div>"
47
+ end
48
+ it "plain text" do
49
+ expect(helper.format_html("# sojka")).to eq "<div class=\"formatted-text\"><h1>sojka</h1>\n</div>"
50
+ end
51
+ end
52
+
53
+ describe "#render_no_data" do
54
+ it "default" do
55
+ expect(helper.render_no_data).to include t(:text_no_data), "nodata"
56
+ end
57
+
58
+ it "custom message" do
59
+ expect(helper.render_no_data("Sorry bro")).to include "Sorry bro", "nodata"
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ module Symphonia
2
+ class NotifierPreview < ::ActionMailer::Preview
3
+
4
+ def test_mail
5
+ Notifier.test_mail(User.last)
6
+ end
7
+
8
+ def user_registered
9
+ Notifier.user_registered(User.last)
10
+ end
11
+
12
+ def reset_password_user
13
+ Notifier.reset_password_user(User.last)
14
+ end
15
+
16
+ def activation_user
17
+ Notifier.activation_user(User.last)
18
+ end
19
+
20
+ def user_change_to_active
21
+ Notifier.user_change_to_active(User.last)
22
+ end
23
+
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,76 @@
1
+ require_relative '../../rails_helper'
2
+
3
+ module Symphonia
4
+ RSpec.describe Notifier do
5
+ let(:user) { FactoryBot.create(:user) }
6
+ before(:each) { I18n.locale = :cs }
7
+
8
+ context '#test_mail' do
9
+ let(:mail) { described_class.test_mail(user) }
10
+
11
+ it 'renders the headers' do
12
+ expect(mail.subject).to eq('Symphonia testing mail')
13
+ expect(mail.to).to eq([user.email])
14
+ end
15
+
16
+ it 'renders the body' do
17
+ expect(mail.body.encoded).to match('Testing mail from Symphonia system')
18
+ end
19
+ end
20
+
21
+ context '#activation_user' do
22
+ let(:mail) { described_class.activation_user(user) }
23
+
24
+ it 'renders the headers' do
25
+ expect(mail.subject).to match 'Aktivace'
26
+ expect(mail.to).to eq([user.email])
27
+ end
28
+
29
+ it 'renders the body' do
30
+ expect(mail.body.encoded).to match user.perishable_token
31
+ end
32
+ end
33
+
34
+ context '#user_change_to_active' do
35
+ let(:mail) { described_class.user_change_to_active(user) }
36
+
37
+ it 'renders the headers' do
38
+ expect(mail.subject).to match 'aktivován'
39
+ expect(mail.to).to eq([user.email])
40
+ end
41
+
42
+ it 'renders the body' do
43
+ expect(mail.body.encoded).to match "users/#{user.id}"
44
+ end
45
+ end
46
+
47
+ context '#reset_password_user' do
48
+ let(:mail) { described_class.reset_password_user(user) }
49
+
50
+ it 'renders the headers' do
51
+ expect(mail.subject).to match 'heslo'
52
+ expect(mail.to).to eq([user.email])
53
+ end
54
+
55
+ it 'renders the body' do
56
+ expect(mail.body.encoded).to match "reset_password/#{user.perishable_token}"
57
+ end
58
+ end
59
+
60
+ context '#user_registered' do
61
+ let(:notify) { FactoryBot.create(:email_preference, :user_registered) }
62
+ let!(:admin) { FactoryBot.create(:user, { preferences: [notify]}) }
63
+ let(:mail) { described_class.user_registered(user) }
64
+
65
+ it 'renders the headers' do
66
+ expect(mail.subject).to match 'nový uživatel'
67
+ expect(mail.to).to eq([admin.email])
68
+ end
69
+
70
+ it 'renders the body' do
71
+ expect(mail.body.encoded).to match user.name
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,22 @@
1
+ describe Symphonia::Attachment do
2
+
3
+ context 'files' do
4
+ let(:file) { FactoryBot.create(:file) }
5
+ it '#create' do
6
+ expect { file }.to change(described_class, :count).by 1
7
+ end
8
+
9
+ it 'just create common file' do
10
+ f = nil
11
+ expect { f = FactoryBot.create(:file, attachable: nil) }.to change(described_class, :count).by 1
12
+ expect(f.attachable).to be_nil
13
+ end
14
+ end
15
+
16
+ context 'images' do
17
+ let(:image) { FactoryBot.create(:image) }
18
+ it '#create' do
19
+ expect { image }.to change(described_class, :count).by 1
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.describe Symphonia::ModelAttributes do
2
+ subject { DummyQueryEntity.query.new }
3
+ context "sort" do
4
+ it "no sort" do
5
+ expect(subject.columns[2].sort?).to eq false
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,70 @@
1
+ RSpec.describe Symphonia::Query do
2
+
3
+ subject do
4
+ q = described_class.new
5
+ q.model = DummyQueryEntity
6
+ q
7
+ end
8
+
9
+ describe "#available_filters" do
10
+ it "include name filter" do
11
+ expect(subject.available_filters.first&.name).to eq :name
12
+ end
13
+ end
14
+
15
+ describe "#initialize" do
16
+ it "empty" do
17
+ q = described_class.new
18
+ q.model = DummyQueryEntity
19
+ expect(q.entity).to eq DummyQueryEntity
20
+ expect(q.filters).to be_blank
21
+ end
22
+
23
+ it "default filters" do
24
+ q = described_class.new(filters: { name: "!cip" })
25
+ q.model = DummyQueryEntity
26
+ expect(q.filters.size).to eq 1
27
+ filter = q.filters.first
28
+ expect(filter.value).to eq "cip"
29
+ end
30
+
31
+ it "legacy fallback" do
32
+ expect(ActiveSupport::Deprecation).to receive(:warn).twice
33
+ described_class.new(spy("Controller"), default_order: "cip")
34
+ end
35
+ end
36
+
37
+ describe "#from_params" do
38
+ it "blank" do
39
+ q = DummyQueryEntity.query.new(filters: { name: "!clip" })
40
+ expect { q.from_params({}) }.not_to raise_error
41
+ expect(q.filters).not_to be_blank
42
+ end
43
+
44
+ it "with filters" do
45
+ q = DummyQueryEntity.query.new(filters: { name: "!clip" })
46
+ expect { q.from_params(set_filter: "1") }.not_to raise_error
47
+ expect(q.filters).to be_blank
48
+ end
49
+
50
+ it "columns" do
51
+ q = DummyQueryEntity.query.new
52
+ expect(q.column_names).to match_array [:name, :status, :author]
53
+ q.from_params(column_names: "name")
54
+ expect(q.column_names).to match_array [:name]
55
+ end
56
+ end
57
+
58
+ describe "#entities" do
59
+ it "get entities" do
60
+ # scope = spy
61
+ # expect(subject).to receive(:scope).and_return(scope)
62
+ Symphonia::User.query.new.entities
63
+ end
64
+ end
65
+
66
+ describe "#columns" do
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,13 @@
1
+ RSpec.describe Symphonia::Role do
2
+ subject { FactoryBot.create :role, permissions: [:view_users] }
3
+
4
+ describe "#allowed_to?" do
5
+ it "false" do
6
+ expect(subject.allowed_to?( :non_exists)).to eq false
7
+ end
8
+
9
+ it "true" do
10
+ expect(subject.allowed_to?(:view_users)).to eq true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ RSpec.describe Symphonia::User do
2
+ subject { FactoryBot.create(:user, email: "test@dummy.com") }
3
+ it "#like" do
4
+ expect(Symphonia::User.like(subject.mail)).to be_all Symphonia::User
5
+ end
6
+
7
+ it "#to_s" do
8
+ expect(subject.to_s).to eq "#{subject.first_name} #{subject.last_name}"
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start 'rails' do
5
+ add_filter "/lib/generators"
6
+ add_filter "/bin"
7
+ end
8
+
9
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
10
+ # Prevent database truncation if the environment is production
11
+ abort('The Rails environment is running in production mode!') if Rails.env.production?
12
+
13
+ require_relative 'spec_helper'
@@ -0,0 +1,118 @@
1
+ describe Symphonia::AccountsController do
2
+
3
+ before(:each) do
4
+ Symphonia.config[:allow_registrations] = true
5
+ end
6
+
7
+ context '#register' do
8
+ it 'GET' do
9
+ get '/register'
10
+ expect(response).to have_http_status :success
11
+ end
12
+
13
+ context 'POST' do
14
+
15
+ it 'pending' do
16
+ expect { post '/register', params: { user: FactoryBot.attributes_for(:user) } }.to change(Symphonia::User, :count).by 1
17
+ expect(response).to have_http_status :redirect
18
+ expect(Symphonia::User.last.status).to eq 'pending'
19
+ end
20
+
21
+ it 'self activation' do
22
+ Symphonia.config[:self_activation_enabled] = true
23
+
24
+ expect { post '/register', params: { user: FactoryBot.attributes_for(:user) } }.to change(Symphonia::User, :count).by 1
25
+ expect(response).to have_http_status :redirect
26
+ expect(Symphonia::User.last.status).to eq 'active'
27
+ end
28
+
29
+ it 'invalid' do
30
+ expect { post '/register', params: { user: { login: Faker::Internet.user_name } } }.to change(Symphonia::User, :count).by 0
31
+ expect(response).to have_http_status :success
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'pending' do
37
+ let(:pending_user) { FactoryBot.create(:user, status: 'pending', password: 'heslo123', password_confirmation: 'heslo123')}
38
+
39
+ it '#login' do
40
+ post symphonia.user_sessions_path, params: { login_session: { login: pending_user.login, password: 'heslo123' }}
41
+ expect(response).to have_http_status :success
42
+ expect(Symphonia::User.current.id).not_to eq pending_user.id
43
+ end
44
+ end
45
+
46
+ context 'with user', logged: true do
47
+
48
+ it '#new_activation' do
49
+ get symphonia.new_activation_account_path
50
+ expect(response).to have_http_status :success
51
+ end
52
+
53
+ end
54
+
55
+ context '#lost_password' do
56
+
57
+ it 'js' do
58
+ get symphonia.lost_password_account_path, xhr: true
59
+ expect(response).to have_http_status :success
60
+ end
61
+
62
+ it 'html' do
63
+ get symphonia.lost_password_account_path
64
+ expect(response).to have_http_status :success
65
+ end
66
+
67
+ end
68
+
69
+ context '#reset_password' do
70
+ let(:token) { SecureRandom.hex(3) }
71
+ let(:password) { SecureRandom.hex(8) }
72
+ let(:user) { FactoryBot.create(:user, status: 'active') }
73
+
74
+ context 'GET' do
75
+
76
+ it 'valid token' do
77
+ user.update_columns(perishable_token: token)
78
+ get symphonia.reset_password_path(id: token)
79
+ expect(response).to have_http_status :success
80
+ end
81
+
82
+ it 'invalid token' do
83
+ user
84
+ get symphonia.reset_password_path(id: token)
85
+ expect(response).to have_http_status :not_found
86
+ end
87
+ end
88
+
89
+ context 'PUT' do
90
+ before { FactoryBot.create(:user, status: 'active'); user.update_columns(perishable_token: token) }
91
+
92
+ it 'valid token' do
93
+ put symphonia.reset_password_account_path(id: token, password: password, password_confirmation: password )
94
+ expect(response).to redirect_to symphonia.user_current_path
95
+ expect(flash[:notice]).not_to be :blank
96
+ end
97
+
98
+ it 'invalid password' do
99
+ put symphonia.reset_password_account_path(id: token, password: '12', password_confirmation: '11' )
100
+ expect(response).to have_http_status :success
101
+ expect(flash[:notice]).to be_nil
102
+ end
103
+
104
+ end
105
+
106
+
107
+
108
+ end
109
+
110
+ context 'form for user', logged: true do
111
+ let(:regular_user) { FactoryBot.create(:user) }
112
+ it '/admin/account' do
113
+ get '/admin/account'
114
+ expect(response).to have_http_status :success
115
+ end
116
+ end
117
+
118
+ end
@@ -0,0 +1,23 @@
1
+ describe Symphonia::AttachmentsController, logged: true do
2
+
3
+ let!(:file) { FactoryBot.create(:file) }
4
+ let(:images) { FactoryBot.create_list(:image, 3, attachable_id: nil, attachable_type: nil) }
5
+
6
+ it '#show' do
7
+ get symphonia.attachment_path(file)
8
+ expect(response.body).to match file.attachment.url(:original)
9
+ end
10
+
11
+ it '#destroy' do
12
+ expect{ delete(symphonia.attachment_path(file)) }.to change(Symphonia::Attachment, :count).by -1
13
+ end
14
+
15
+ it '#reorder' do
16
+ expect { images }.to change(Symphonia::Image, :count).by 3
17
+ patch symphonia.reorder_attachment_path images.last, 1
18
+ expect(response).to have_http_status :success
19
+ imgs = Symphonia::Image.order(:position).to_a
20
+ expect(imgs.first.id).to be > imgs.last.id
21
+ end
22
+
23
+ end
@@ -0,0 +1,26 @@
1
+ describe 'login' do
2
+
3
+ let(:regular_user) { FactoryBot.create(:user, password: 'heslo123', password_confirmation: 'heslo123')}
4
+
5
+ it 'login form' do
6
+ get symphonia.login_path
7
+ expect(response).to have_http_status(:success)
8
+ end
9
+
10
+ it 'login process' do
11
+ expect(Symphonia::User.current).to be_a Symphonia::User::Anonymous
12
+ post symphonia.user_sessions_path, params: { login_session: { login: regular_user.login, password: 'heslo123' }}
13
+ expect(response).to have_http_status :redirect
14
+ expect(Symphonia::User.current.id).to eq regular_user.id
15
+ end
16
+
17
+ context 'logged', logged: true do
18
+
19
+ it '#logout' do
20
+ expect(Symphonia::User.current).to be_a Symphonia::User
21
+ delete symphonia.logout_path
22
+ expect(response).to redirect_to '/'
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,10 @@
1
+ module Symphonia
2
+ describe Role, logged: :admin do
3
+ subject { 'role' }
4
+
5
+ let(:route) { symphonia }
6
+ include_examples 'a requests', :name
7
+
8
+ end
9
+
10
+ end