camaleon_cms 2.3.3 → 2.3.4

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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -12
  3. data/app/assets/javascripts/camaleon_cms/admin/_custom_fields.js +1 -2
  4. data/app/assets/javascripts/camaleon_cms/admin/_data.js +1 -0
  5. data/app/assets/javascripts/camaleon_cms/admin/_post.js +1 -1
  6. data/app/assets/javascripts/camaleon_cms/admin/_posttype.js.coffee +21 -0
  7. data/app/assets/javascripts/camaleon_cms/admin/admin-manifest.js +2 -0
  8. data/app/assets/javascripts/camaleon_cms/admin/jquery_validate/fr.js +49 -0
  9. data/app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb +11 -6
  10. data/app/controllers/camaleon_cms/admin/appearances/themes_controller.rb +6 -0
  11. data/app/controllers/camaleon_cms/admin/media_controller.rb +3 -0
  12. data/app/controllers/camaleon_cms/admin/users_controller.rb +3 -0
  13. data/app/controllers/camaleon_cms/camaleon_controller.rb +5 -0
  14. data/app/controllers/camaleon_cms/frontend_controller.rb +1 -1
  15. data/app/controllers/concerns/camaleon_cms/frontend_concern.rb +1 -1
  16. data/app/decorators/camaleon_cms/site_decorator.rb +1 -1
  17. data/app/decorators/camaleon_cms/user_decorator.rb +4 -0
  18. data/app/helpers/camaleon_cms/admin/custom_fields_helper.rb +4 -4
  19. data/app/helpers/camaleon_cms/camaleon_helper.rb +5 -0
  20. data/app/helpers/camaleon_cms/frontend/nav_menu_helper.rb +16 -16
  21. data/app/helpers/camaleon_cms/hooks_helper.rb +10 -4
  22. data/app/helpers/camaleon_cms/plugins_helper.rb +1 -1
  23. data/app/helpers/camaleon_cms/session_helper.rb +9 -4
  24. data/app/helpers/camaleon_cms/short_code_helper.rb +1 -1
  25. data/app/helpers/camaleon_cms/theme_helper.rb +1 -1
  26. data/app/helpers/camaleon_cms/uploader_helper.rb +10 -7
  27. data/app/mailers/camaleon_cms/html_mailer.rb +33 -17
  28. data/app/models/camaleon_cms/ability.rb +2 -2
  29. data/app/models/camaleon_cms/nav_menu.rb +2 -2
  30. data/app/models/camaleon_cms/nav_menu_item.rb +5 -3
  31. data/app/models/camaleon_cms/site.rb +5 -101
  32. data/app/models/camaleon_cms/user.rb +8 -144
  33. data/app/models/camaleon_cms/user_relationship.rb +1 -1
  34. data/app/models/camaleon_cms/user_role.rb +0 -2
  35. data/app/models/concerns/camaleon_cms/custom_fields_read.rb +14 -7
  36. data/app/models/concerns/camaleon_cms/metas.rb +5 -4
  37. data/app/models/concerns/camaleon_cms/site_default_settings.rb +87 -0
  38. data/app/models/concerns/camaleon_cms/user_methods.rb +142 -0
  39. data/app/uploaders/camaleon_cms_aws_uploader.rb +13 -4
  40. data/app/uploaders/camaleon_cms_uploader.rb +3 -1
  41. data/app/views/camaleon_cms/admin/appearances/nav_menus/_custom_menus.html.erb +11 -5
  42. data/app/views/camaleon_cms/admin/appearances/nav_menus/_external_menu.html.erb +8 -0
  43. data/app/views/camaleon_cms/admin/settings/_media_settings.html.erb +4 -0
  44. data/app/views/camaleon_cms/admin/settings/custom_fields/_get_items.html.erb +155 -154
  45. data/app/views/camaleon_cms/admin/settings/custom_fields/_render.html.erb +1 -1
  46. data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_checkbox.html.erb +1 -1
  47. data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_checkboxes.html.erb +1 -1
  48. data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_posts.html.erb +2 -5
  49. data/app/views/camaleon_cms/admin/settings/custom_fields/form.html.erb +1 -1
  50. data/app/views/camaleon_cms/admin/settings/post_types/_form.html.erb +24 -16
  51. data/app/views/camaleon_cms/admin/users/form.html.erb +2 -2
  52. data/app/views/camaleon_cms/default_theme/single.html.erb +1 -1
  53. data/app/views/layouts/camaleon_cms/admin.html.erb +2 -2
  54. data/config/initializers/model_alias.rb +10 -3
  55. data/config/locales/camaleon_cms/admin/en.yml +10 -0
  56. data/config/locales/camaleon_cms/admin/fr.yml +663 -0
  57. data/config/locales/camaleon_cms/common.yml +66 -0
  58. data/config/routes/frontend.rb +1 -1
  59. data/config/system.json +2 -2
  60. data/db/migrate/20150611161134_post_table_into_utf8.rb +6 -5
  61. data/lib/camaleon_cms/engine.rb +3 -0
  62. data/lib/camaleon_cms/version.rb +1 -1
  63. data/lib/ext/string.rb +1 -54
  64. data/lib/plugin_routes.rb +5 -0
  65. data/spec/decorators/post_type_spec.rb +13 -0
  66. data/spec/dummy/README.rdoc +28 -0
  67. data/spec/dummy/Rakefile +6 -0
  68. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  69. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  70. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  71. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  72. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/spec/dummy/bin/bundle +3 -0
  74. data/spec/dummy/bin/rails +4 -0
  75. data/spec/dummy/bin/rake +4 -0
  76. data/spec/dummy/bin/setup +29 -0
  77. data/spec/dummy/config.ru +4 -0
  78. data/spec/dummy/config/application.rb +26 -0
  79. data/spec/dummy/config/boot.rb +5 -0
  80. data/spec/dummy/config/database.yml +25 -0
  81. data/spec/dummy/config/environment.rb +5 -0
  82. data/spec/dummy/config/environments/development.rb +41 -0
  83. data/spec/dummy/config/environments/production.rb +79 -0
  84. data/spec/dummy/config/environments/test.rb +42 -0
  85. data/spec/dummy/config/initializers/assets.rb +11 -0
  86. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  87. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  88. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  89. data/spec/dummy/config/initializers/inflections.rb +16 -0
  90. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  91. data/spec/dummy/config/initializers/session_store.rb +3 -0
  92. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  93. data/spec/dummy/config/locales/en.yml +23 -0
  94. data/spec/dummy/config/routes.rb +4 -0
  95. data/spec/dummy/config/secrets.yml +22 -0
  96. data/spec/dummy/db/development.sqlite3 +0 -0
  97. data/spec/dummy/db/schema.rb +186 -0
  98. data/spec/dummy/public/404.html +67 -0
  99. data/spec/dummy/public/422.html +67 -0
  100. data/spec/dummy/public/500.html +66 -0
  101. data/spec/dummy/public/favicon.ico +0 -0
  102. data/spec/features/categories_spec.rb +25 -0
  103. data/spec/features/comments_spec.rb +45 -0
  104. data/spec/features/contact_form_spec.rb +53 -0
  105. data/spec/features/content_groups_spec.rb +45 -0
  106. data/spec/features/custom_fields_spec.rb +47 -0
  107. data/spec/features/frontend/pages_spec.rb +5 -0
  108. data/spec/features/languages_spec.rb +27 -0
  109. data/spec/features/media_spec.rb +50 -0
  110. data/spec/features/menus_spec.rb +46 -0
  111. data/spec/features/pages_spec.rb +30 -0
  112. data/spec/features/plugins_spec.rb +29 -0
  113. data/spec/features/posts_spec.rb +36 -0
  114. data/spec/features/session_spec.rb +52 -0
  115. data/spec/features/settings_spec.rb +17 -0
  116. data/spec/features/shortcodes_spec.rb +11 -0
  117. data/spec/features/sites_spec.rb +45 -0
  118. data/spec/features/tags_spec.rb +25 -0
  119. data/spec/features/themes_spec.rb +18 -0
  120. data/spec/features/user_roles_spec.rb +60 -0
  121. data/spec/features/users_spec.rb +79 -0
  122. data/spec/features/widgets_spec.rb +50 -0
  123. data/spec/helpers/email_helper_spec.rb +16 -0
  124. data/spec/mailers/send_mail_spec.rb +37 -0
  125. data/spec/rails_helper.rb +1 -0
  126. data/spec/routing/post_type_routes_spec.rb +12 -0
  127. data/spec/spec_helper.rb +191 -0
  128. data/spec/support/common.rb +113 -0
  129. data/spec/support/wait_for_ajax.rb +36 -0
  130. metadata +326 -3
@@ -0,0 +1,50 @@
1
+ require "rails_helper"
2
+ describe "the Themes", js: true do
3
+ login_success
4
+
5
+ it "Widgets list" do
6
+ admin_sign_in
7
+ visit "#{cama_root_relative_path}/admin/appearances/widgets/main"
8
+ expect(page).to have_css('#view_widget_list')
9
+ within "#view_widget_list" do
10
+ first('#new_widget_link').click
11
+ wait_for_ajax
12
+ end
13
+ within '#widget_form' do
14
+ fill_in "widget_main_name", with: "test widget"
15
+ fill_in "widget_main_slug", with: "test-widget"
16
+ fill_in "widget_main_description", with: "lorem ipsum"
17
+ click_button "Submit"
18
+ end
19
+ expect(page).to have_css('.alert-success')
20
+ expect(page).to have_content("test-widget")
21
+ end
22
+
23
+ it "Widgets Edit" do
24
+ admin_sign_in
25
+ visit "#{cama_root_relative_path}/admin/appearances/widgets/main"
26
+ within "#view_widget_list" do
27
+ first('.edit_link').click
28
+ wait_for_ajax
29
+ end
30
+ within '#widget_form' do
31
+ fill_in "widget_main_name", with: "test widget updated"
32
+ fill_in "widget_main_slug", with: "test-widget-updated"
33
+ fill_in "widget_main_description", with: "lorem ipsum updated"
34
+ click_button "Submit"
35
+ end
36
+ expect(page).to have_css('.alert-success')
37
+ expect(page).to have_content("test-widget-updated")
38
+ end
39
+
40
+ it "Widgets destroy" do
41
+ admin_sign_in
42
+ visit "#{cama_root_relative_path}/admin/appearances/widgets/main"
43
+ within "#view_widget_list" do
44
+ first('.del_link').click
45
+ end
46
+ page.driver.browser.switch_to.alert.accept
47
+ expect(page).to have_css('.alert-success')
48
+ end
49
+
50
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails_helper'
2
+
3
+ describe "CamaleonCms::EmailHelper" do
4
+ get_current_test_site()
5
+ describe "#send_email (old way)" do
6
+ it "returns empty" do
7
+ expect(helper.send_email('test@gmail.com', 'Test Email', 'test content', 'owenperedo@gmail.com')).to be_a_kind_of(ActionMailer::DeliveryJob)
8
+ end
9
+ end
10
+
11
+ describe "#send_email (new way)" do
12
+ it "returns empty" do
13
+ expect(helper.cama_send_email('test@gmail.com', 'Test Email', {content: 'test content', from: 'owenperedo@gmail.com'})).to be_a_kind_of(ActionMailer::DeliveryJob)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ require 'rails_helper'
2
+
3
+ describe "CamaleonCms::HtmlMailer" do
4
+ describe 'empty content' do
5
+ get_current_test_site()
6
+ let(:mail) { CamaleonCms::HtmlMailer.sender('test@gmail.com', "test") }
7
+
8
+ it 'renders the subject' do
9
+ expect(mail.subject).to eql('test')
10
+ end
11
+
12
+ it 'renders the receiver email' do
13
+ expect(mail.to).to eql(['test@gmail.com'])
14
+ end
15
+
16
+ it 'renders the sender email' do
17
+ expect(mail.from).to eql(['owenperedo@gmail.com'])
18
+ end
19
+
20
+ it 'html layout text' do
21
+ expect(mail.body.encoded).to match('Visit Site')
22
+ end
23
+ end
24
+
25
+ describe 'custom content' do
26
+ get_current_test_site()
27
+ let(:mail) { CamaleonCms::HtmlMailer.sender('test@gmail.com', "test", content: 'custom content', cc_to: ['a@gmail.com', 'b@gmail.com']) }
28
+
29
+ it 'renders the sender email' do
30
+ expect(mail.cc).to eql(['a@gmail.com', 'b@gmail.com'])
31
+ end
32
+
33
+ it 'custom content' do
34
+ expect(mail.body.encoded).to match('custom content')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,12 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe "routes for Post Types", :type => :routing do
4
+ it "routes for /test-post-type" do
5
+ post_type = create_test_post_type(slug: "test-post-type")
6
+ expect(post_type.id).to be_present
7
+ expect(get("/test-post-type")).to route_to(
8
+ "camaleon_cms/frontend#post_type",
9
+ post_type_id: post_type.id,
10
+ post_type_slug: "test-post-type")
11
+ end
12
+ end
@@ -0,0 +1,191 @@
1
+ # Configuration was inspired by:
2
+ # https://www.viget.com/articles/rails-engine-testing-with-rspec-capybara-and-factorygirl
3
+
4
+ ENV['RAILS_ENV'] ||= 'test'
5
+
6
+ CAMALEON_CMS_ROOT = Pathname.new(__FILE__).join('../..')
7
+
8
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
9
+
10
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
11
+ ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
12
+
13
+ require 'rspec/rails'
14
+ require "capybara/rspec"
15
+ require 'database_cleaner'
16
+
17
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
18
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
19
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
20
+ # this file to always be loaded, without a need to explicitly require it in any
21
+ # files.
22
+ #
23
+ # Given that it is always loaded, you are encouraged to keep this file as
24
+ # light-weight as possible. Requiring heavyweight dependencies from this file
25
+ # will add to the boot time of your test suite on EVERY test run, even for an
26
+ # individual file that may not need all of that loaded. Instead, consider making
27
+ # a separate helper file that requires the additional dependencies and performs
28
+ # the additional setup, and require it from the spec files that actually need
29
+ # it.
30
+ #
31
+ # The `.rspec` file also contains a few flags that are not defaults but that
32
+ # users commonly want.
33
+ #
34
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
35
+
36
+ #Capybara.javascript_driver = :webkit
37
+
38
+ # require 'capybara/poltergeist'
39
+ # Capybara.javascript_driver = :poltergeist
40
+
41
+ # require 'capybara/poltergeist'
42
+ # Capybara.register_driver :poltergeist_debug do |app|
43
+ # Capybara::Poltergeist::Driver.new(app, :inspector => true)
44
+ # end
45
+ #
46
+ # # Capybara.javascript_driver = :poltergeist
47
+ # Capybara.javascript_driver = :poltergeist_debug
48
+
49
+
50
+ RSpec.configure do |config|
51
+ # rspec-expectations config goes here. You can use an alternate
52
+ # assertion/expectation library such as wrong or the stdlib/minitest
53
+ # assertions if you prefer.
54
+ config.include Rails.application.routes.url_helpers if defined? Rails
55
+ config.expect_with :rspec do |expectations|
56
+ # This option will default to `true` in RSpec 4. It makes the `description`
57
+ # and `failure_message` of custom matchers include text for helper methods
58
+ # defined using `chain`, e.g.:
59
+ # be_bigger_than(2).and_smaller_than(4).description
60
+ # # => "be bigger than 2 and smaller than 4"
61
+ # ...rather than:
62
+ # # => "be bigger than 2"
63
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
64
+ end
65
+
66
+ # rspec-mocks config goes here. You can use an alternate test double
67
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
68
+ config.mock_with :rspec do |mocks|
69
+ # Prevents you from mocking or stubbing a method that does not exist on
70
+ # a real object. This is generally recommended, and will default to
71
+ # `true` in RSpec 4.
72
+ mocks.verify_partial_doubles = true
73
+ end
74
+
75
+ # The settings below are suggested to provide a good initial experience
76
+ # with RSpec, but feel free to customize to your heart's content.
77
+ =begin
78
+ # These two settings work together to allow you to limit a spec run
79
+ # to individual examples or groups you care about by tagging them with
80
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
81
+ # get run.
82
+ config.filter_run :focus
83
+ config.run_all_when_everything_filtered = true
84
+
85
+ # Limits the available syntax to the non-monkey patched syntax that is
86
+ # recommended. For more details, see:
87
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
88
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
89
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
90
+ config.disable_monkey_patching!
91
+
92
+ # Many RSpec users commonly either run the entire suite or an individual
93
+ # file, and it's useful to allow more verbose output when running an
94
+ # individual spec file.
95
+ if config.files_to_run.one?
96
+ # Use the documentation formatter for detailed output,
97
+ # unless a formatter has already been configured
98
+ # (e.g. via a command-line flag).
99
+ config.default_formatter = 'doc'
100
+ end
101
+
102
+ # Print the 10 slowest examples and example groups at the
103
+ # end of the spec run, to help surface which specs are running
104
+ # particularly slow.
105
+ config.profile_examples = 10
106
+
107
+ # Run specs in random order to surface order dependencies. If you find an
108
+ # order dependency and want to debug it, you can fix the order by providing
109
+ # the seed, which is printed after each run.
110
+ # --seed 1234
111
+ config.order = :random
112
+
113
+ # Seed global randomization in this process using the `--seed` CLI option.
114
+ # Setting this allows you to use `--seed` to deterministically reproduce
115
+ # test failures related to randomization by passing the same `--seed` value
116
+ # as the one that triggered the failure.
117
+ Kernel.srand config.seed
118
+ =end
119
+ end
120
+
121
+ # Requires supporting ruby files with custom matchers and macros, etc, in
122
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
123
+ # run as spec files by default. This means that files in spec/support that end
124
+ # in _spec.rb will both be required and run as specs, causing the specs to be
125
+ # run twice. It is recommended that you do not name files matching this glob to
126
+ # end with _spec.rb. You can configure this pattern with the --pattern
127
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
128
+ #
129
+ # The following line is provided for convenience purposes. It has the downside
130
+ # of increasing the boot-up time by auto-requiring all files in the support
131
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
132
+ # require only the support files necessary.
133
+ #
134
+ Dir[CAMALEON_CMS_ROOT.join('spec/support/**/*.rb')].each { |f| require f }
135
+ # Rails.root refers to spec/dummy app
136
+ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
137
+
138
+ # Checks for pending migrations before tests are run.
139
+ # If you are not using ActiveRecord, you can remove this line.
140
+ ActiveRecord::Migration.maintain_test_schema!
141
+
142
+ RSpec.configure do |config|
143
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
144
+ #config.fixture_path = "#{::Rails.root}/spec/fixtures"
145
+
146
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
147
+ # examples within a transaction, remove the following line or assign false
148
+ # instead of true.
149
+ config.use_transactional_fixtures = false
150
+
151
+ # RSpec Rails can automatically mix in different behaviours to your tests
152
+ # based on their file location, for example enabling you to call `get` and
153
+ # `post` in specs under `spec/controllers`.
154
+ #
155
+ # You can disable this behaviour by removing the line below, and instead
156
+ # explicitly tag your specs with their type, e.g.:
157
+ #
158
+ # RSpec.describe UsersController, :type => :controller do
159
+ # # ...
160
+ # end
161
+ #
162
+ # The different available types are documented in the features, such as in
163
+ # https://relishapp.com/rspec/rspec-rails/docs
164
+ config.infer_spec_type_from_file_location!
165
+ end
166
+
167
+ RSpec.configure do |config|
168
+
169
+ config.before(:suite) do
170
+ DatabaseCleaner.strategy = :transaction
171
+ DatabaseCleaner.clean_with(:truncation)
172
+ end
173
+
174
+ config.around(:each) do |example|
175
+ DatabaseCleaner.cleaning do
176
+ example.run
177
+ end
178
+ end
179
+
180
+ end
181
+
182
+ # Windows less than 1000px wide produce broken rendering on some pages:
183
+ # https://github.com/owen2345/camaleon-cms/issues/481
184
+ # Workaround: maximize the window in capybara:
185
+ # https://makandracards.com/makandra/9773-how-to-start-selenium-browser-maximized-or-with-custom-window-size
186
+ # http://stackoverflow.com/questions/18390071/change-default-capybara-browser-window-size
187
+ RSpec.configure do |config|
188
+ config.before(:each, js: true) do
189
+ Capybara.page.driver.browser.manage.window.maximize
190
+ end
191
+ end
@@ -0,0 +1,113 @@
1
+ # include ApplicationHelper
2
+ require 'rails_helper'
3
+
4
+ # do login for admin panel and also verify if the site was created
5
+ # if site is not created, then create a new site
6
+ def login_success
7
+ if !CamaleonCms::Site.any? && !defined?($install_called)
8
+ it "Verify Install Camaleon" do
9
+ visit "#{cama_root_relative_path}/admin/installers"
10
+ within("#new_site") do
11
+ fill_in 'site_name', :with => 'Test Site'
12
+ select "Default Theme", from: "theme"
13
+ end
14
+ click_button 'Submit'
15
+ expect(page).to have_content 'successfully'
16
+
17
+ admin_sign_in(true)
18
+ end
19
+ $install_called = true
20
+ else
21
+ it "signs me in" do
22
+ admin_sign_in
23
+ end
24
+ end
25
+ end
26
+
27
+ # sign in for admin panel
28
+ # skip: true => close the skip button for intro
29
+ def admin_sign_in(close = false, user = "admin", pass = "admin")
30
+ visit "#{cama_root_relative_path}/admin/login"
31
+ within("#login_user") do
32
+ fill_in 'user_username', :with => user
33
+ fill_in 'user_password', :with => pass
34
+ end
35
+ click_button 'Log In'
36
+ expect(page).to have_content 'Welcome'
37
+
38
+ click_link "Skip" if close
39
+ end
40
+
41
+ def cama_root_relative_path
42
+ "#{PluginRoutes.system_info["relative_url_root"]}" if PluginRoutes.system_info["relative_url_root"].present?
43
+ end
44
+
45
+ # open file manager modal and upload a new file
46
+ # TODO
47
+ def file_select
48
+ attach_file("Select files to upload", "/Users/owen/Pictures/luna\ miel/DSC00116.JPG ")
49
+ end
50
+
51
+ def eval_code(code)
52
+ instance_eval(code)
53
+ end
54
+
55
+ def wait(time)
56
+ sleep(time)
57
+ end
58
+
59
+ # return the id of the first post
60
+ def get_content_attr(post_type = "post", attr = "id", pos = "first")
61
+ res = Cama::Site.first.decorate.the_post_type(post_type).decorate.the_posts.send(pos).decorate.send(attr)
62
+ fix_db
63
+ res
64
+ end
65
+
66
+ # return the id of the first post
67
+ def get_cat_attr(attr = "id", pos = "first")
68
+ res = Cama::Site.first.decorate.the_full_categories.decorate.send(pos).send(attr)
69
+ fix_db
70
+ res
71
+ end
72
+
73
+ # return the id of the first post
74
+ def get_tag_attr(attr = "id", pos = "first")
75
+ res = Cama::Site.first.decorate.the_tags.decorate.send(pos).send(attr)
76
+ fix_db
77
+ res
78
+ end
79
+
80
+ # fix for: SQLite3::BusyException: database is locked: commit transaction
81
+ def fix_db
82
+ # ActiveRecord::Base.connection.execute("END;")
83
+ # ActiveRecord::Base.connection.execute("BEGIN TRANSACTION;")
84
+ end
85
+
86
+ def pages_test
87
+ current_site = Cama::Site.first.decorate
88
+ page1 = current_site.the_post_type("post").add_post(title: "test1", content: "content [data key='subtitle']", summary: "summary", order_position: 2)
89
+ page1.add_field({"name"=>"Sub Title", "slug"=>"subtitle"}, {"field_key"=>"text_box", "translate"=>true, default_value: "test sub title"})
90
+ page1.set_settings({has_summary: true, default_template: "home/page2", has_picture: true})
91
+ visit(page1.the_title)
92
+
93
+ current_site.the_contents.decorate.each do |p|
94
+ visit "#{p.the_url(as_path: true)}"
95
+ expect(page).to have_content p.the_title
96
+ end
97
+ the_tags.decorate.send(pos).send(attr)
98
+ end
99
+
100
+ # return the current for testing case
101
+ def get_current_test_site
102
+ Cama::Site.first || create_test_site
103
+ end
104
+
105
+ # create a new post type for first site
106
+ def create_test_post_type(args = {})
107
+ get_current_test_site.post_types.create!({name: 'Test', slug: 'test', description: 'this is a test', data_options: {}}.merge(args))
108
+ end
109
+
110
+ # create a test site
111
+ def create_test_site(args = {})
112
+ Cama::Site.create({slug: 'test', name: 'Test Site'}.merge(args))
113
+ end
@@ -0,0 +1,36 @@
1
+ # spec/support/wait_for_ajax.rb
2
+ module WaitForAjax
3
+ def wait_for_ajax
4
+ Timeout.timeout(Capybara.default_max_wait_time) do
5
+ loop until finished_all_ajax_requests?
6
+ end
7
+ end
8
+
9
+ def finished_all_ajax_requests?
10
+ page.evaluate_script('jQuery.active').zero?
11
+ end
12
+
13
+ def wait_for_visible_modal(key = nil)
14
+ Timeout.timeout(Capybara.default_max_wait_time) do
15
+ loop until visible_modal?(key)
16
+ end
17
+ end
18
+
19
+ def wait_for_hidden_modal(key = nil)
20
+ Timeout.timeout(Capybara.default_max_wait_time) do
21
+ loop until hidden_modal?(key)
22
+ end
23
+ end
24
+
25
+ def hidden_modal?(key = nil)
26
+ page.evaluate_script("jQuery('#{key || "#ow_inline_modal"}').is(':visible')") == false
27
+ end
28
+
29
+ def visible_modal?(key = nil)
30
+ page.evaluate_script("jQuery('#{key || "#ow_inline_modal"}').is(':visible')") == true
31
+ end
32
+ end
33
+
34
+ RSpec.configure do |config|
35
+ config.include WaitForAjax, type: :feature
36
+ end