decidim-dev 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +24 -0
- data/Rakefile +2 -0
- data/app/views/decidim/dummy_resource/_linked_dummys.html.erb +5 -0
- data/config/i18n-tasks.yml +4 -0
- data/config/locales/ca.yml +5 -0
- data/config/locales/en.yml +5 -0
- data/config/locales/es.yml +5 -0
- data/config/locales/eu.yml +5 -0
- data/config/locales/fi.yml +5 -0
- data/lib/decidim/dev.rb +22 -0
- data/lib/decidim/dev/assets/Exampledocument.docx +0 -0
- data/lib/decidim/dev/assets/Exampledocument.odt +0 -0
- data/lib/decidim/dev/assets/Exampledocument.pdf +0 -0
- data/lib/decidim/dev/assets/avatar.jpg +0 -0
- data/lib/decidim/dev/assets/city.jpeg +0 -0
- data/lib/decidim/dev/assets/city2.jpeg +0 -0
- data/lib/decidim/dev/assets/city3.jpeg +0 -0
- data/lib/decidim/dev/assets/icon.png +0 -0
- data/lib/decidim/dev/assets/malicious.jpg +0 -0
- data/lib/decidim/dev/common_rake.rb +28 -0
- data/lib/decidim/dev/dummy_authorization_handler.rb +26 -0
- data/lib/decidim/dev/test/authorization_shared_examples.rb +23 -0
- data/lib/decidim/dev/test/base_spec_helper.rb +48 -0
- data/lib/decidim/dev/test/i18n_spec.rb +34 -0
- data/lib/decidim/dev/test/rspec_support/action_mailer.rb +72 -0
- data/lib/decidim/dev/test/rspec_support/active_job.rb +11 -0
- data/lib/decidim/dev/test/rspec_support/authenticated_controller_context.rb +9 -0
- data/lib/decidim/dev/test/rspec_support/authorization_handlers.rb +7 -0
- data/lib/decidim/dev/test/rspec_support/capybara.rb +73 -0
- data/lib/decidim/dev/test/rspec_support/database_cleaner.rb +13 -0
- data/lib/decidim/dev/test/rspec_support/engine_routes.rb +34 -0
- data/lib/decidim/dev/test/rspec_support/factory_girl.rb +4 -0
- data/lib/decidim/dev/test/rspec_support/feature.rb +91 -0
- data/lib/decidim/dev/test/rspec_support/feature_context.rb +44 -0
- data/lib/decidim/dev/test/rspec_support/geocoder.rb +11 -0
- data/lib/decidim/dev/test/rspec_support/helpers.rb +46 -0
- data/lib/decidim/dev/test/rspec_support/html_matchers.rb +6 -0
- data/lib/decidim/dev/test/rspec_support/i18n.rb +15 -0
- data/lib/decidim/dev/test/rspec_support/phantomjs_polyfills/bind-polyfill.js +18 -0
- data/lib/decidim/dev/test/rspec_support/phantomjs_polyfills/object-assign-polyfill.js +24 -0
- data/lib/decidim/dev/test/rspec_support/phantomjs_polyfills/promise.js +233 -0
- data/lib/decidim/dev/test/rspec_support/translation_helpers.rb +75 -0
- data/lib/decidim/dev/test/rspec_support/warden.rb +9 -0
- data/lib/decidim/dev/test/rspec_support/webmock.rb +2 -0
- data/lib/decidim/dev/test/rspec_support/wisper.rb +6 -0
- data/lib/decidim/dev/test/spec_helper.rb +37 -0
- data/lib/generators/decidim/dummy_generator.rb +80 -0
- data/lib/generators/decidim/templates/autoprefixer.yml +8 -0
- data/lib/generators/decidim/templates/autoprefixer_initializer.rb +16 -0
- data/lib/generators/decidim/templates/decidim_dev.rb +2 -0
- metadata +406 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eb6caf2afbc815dd893523f38c345953f2b04fdc
|
4
|
+
data.tar.gz: f4fd8e3949a62bed4f24a03c790163a0ae4d2da8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9714a35ff2d96b5b9d258ffbc1bbeb2623d3ef856555d72688f8a4db31895c57acf8d5879900a6d49221138e049c63ecef813164957e34f8c65db4a54cab0e0
|
7
|
+
data.tar.gz: 5fcb703af373cbb6585a37a223dad32b326fb457ab11fcd13472b9637d5364420ed9872e6f5be256d953f7f6fefc1403f4f6c2ba5b481b4d90f89ef70668d63d
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Decidim::Dev
|
2
|
+
|
3
|
+
This gem allows local development of decidim's features and other features.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
TODO: Write docs.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'decidim-dev'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
```bash
|
17
|
+
$ bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
See [Decidim](https://github.com/AjuntamentdeBarcelona/decidim).
|
22
|
+
|
23
|
+
## License
|
24
|
+
See [Decidim](https://github.com/AjuntamentdeBarcelona/decidim).
|
data/Rakefile
ADDED
data/lib/decidim/dev.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "letter_opener_web"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
# Decidim::Dev holds all the convenience logic and libraries to be able to
|
7
|
+
# create external libraries that create test apps and test themselves against
|
8
|
+
# them.
|
9
|
+
module Dev
|
10
|
+
# Public: Finds an asset.
|
11
|
+
#
|
12
|
+
# Returns a String with the path for a particular asset.
|
13
|
+
def self.asset(name)
|
14
|
+
File.join(
|
15
|
+
File.dirname(__FILE__),
|
16
|
+
"dev",
|
17
|
+
"assets",
|
18
|
+
name
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
require_relative "../../generators/decidim/dummy_generator"
|
5
|
+
|
6
|
+
engine_path = Dir.pwd
|
7
|
+
engine_name = engine_path.split("/").last
|
8
|
+
dummy_app_path = File.expand_path(File.join(engine_path, "spec", "#{engine_name}_dummy_app"))
|
9
|
+
|
10
|
+
desc "Generates a dummy app for testing"
|
11
|
+
task :generate_test_app do
|
12
|
+
Decidim::Generators::DummyGenerator.start(
|
13
|
+
[
|
14
|
+
"--engine_path=#{engine_path}",
|
15
|
+
"--migrate=true",
|
16
|
+
"--quiet"
|
17
|
+
]
|
18
|
+
)
|
19
|
+
|
20
|
+
require File.join(dummy_app_path, "config", "application")
|
21
|
+
Rails.application.load_tasks
|
22
|
+
Rake.application["assets:precompile"].invoke
|
23
|
+
|
24
|
+
FileUtils.cd(engine_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec::Core::RakeTask.new(:spec)
|
28
|
+
task default: [:generate_test_app, :spec]
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
# An example implementation of an AuthorizationHandler to be used in tests.
|
4
|
+
class DummyAuthorizationHandler < AuthorizationHandler
|
5
|
+
attribute :document_number, String
|
6
|
+
attribute :postal_code, String
|
7
|
+
attribute :birthday, Date
|
8
|
+
|
9
|
+
validates :document_number, presence: true
|
10
|
+
validate :valid_document_number
|
11
|
+
|
12
|
+
def metadata
|
13
|
+
super.merge(document_number: document_number)
|
14
|
+
end
|
15
|
+
|
16
|
+
def unique_id
|
17
|
+
document_number
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def valid_document_number
|
23
|
+
errors.add(:document_number, :invalid) unless document_number.to_s.end_with?("X")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
RSpec.shared_examples "an authorization handler" do
|
3
|
+
before do
|
4
|
+
unless respond_to?(:handler)
|
5
|
+
raise "You need to define `handler` (an instance of the authorization handler) in order to run the shared examples."
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "to_partial_path" do
|
10
|
+
subject { handler.to_partial_path }
|
11
|
+
it { is_expected.to be_kind_of(String) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "handler_name" do
|
15
|
+
subject { handler.handler_name }
|
16
|
+
it { is_expected.to be_kind_of(String) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "metadata" do
|
20
|
+
subject { handler.metadata }
|
21
|
+
it { is_expected.to be_kind_of(Hash) }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
ENV["RAILS_ENV"] ||= "test"
|
3
|
+
|
4
|
+
engine_name = ENV["ENGINE_NAME"]
|
5
|
+
engine_spec_dir = File.join(Dir.pwd, "spec")
|
6
|
+
dummy_app_path = File.expand_path(File.join(engine_spec_dir, "#{engine_name}_dummy_app"))
|
7
|
+
|
8
|
+
if ENV["CI"]
|
9
|
+
require "simplecov"
|
10
|
+
SimpleCov.root(ENV["TRAVIS_BUILD_DIR"])
|
11
|
+
|
12
|
+
SimpleCov.start do
|
13
|
+
filters.clear
|
14
|
+
add_filter "/test/"
|
15
|
+
add_filter "/spec/"
|
16
|
+
add_filter "bundle.js"
|
17
|
+
add_filter "/vendor/"
|
18
|
+
|
19
|
+
add_filter do |src|
|
20
|
+
!(src.filename =~ /^#{ENV["TRAVIS_BUILD_DIR"]}/)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "codecov"
|
25
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
26
|
+
end
|
27
|
+
|
28
|
+
require "rails"
|
29
|
+
require "active_support/core_ext/string"
|
30
|
+
require "decidim/core"
|
31
|
+
require "decidim/core/test"
|
32
|
+
require "#{File.dirname(__FILE__)}/rspec_support/feature.rb"
|
33
|
+
|
34
|
+
begin
|
35
|
+
require "#{dummy_app_path}/config/environment"
|
36
|
+
rescue LoadError
|
37
|
+
puts "Could not load dummy application. Please ensure you have run `bundle exec rake generate_test_app`"
|
38
|
+
puts "Tried to load it from #{dummy_app_path}"
|
39
|
+
exit(-1)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Requires supporting files with custom matchers and macros, etc,
|
43
|
+
# in ./support/ and its subdirectories.
|
44
|
+
Dir["#{engine_spec_dir}/support/**/*.rb"].each { |f| require f }
|
45
|
+
Dir["#{engine_spec_dir}/shared/**/*.rb"].each { |f| require f }
|
46
|
+
|
47
|
+
require_relative "spec_helper"
|
48
|
+
require_relative "i18n_spec"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "i18n/tasks"
|
3
|
+
|
4
|
+
RSpec.describe "I18n" do
|
5
|
+
let(:i18n) { I18n::Tasks::BaseTask.new(locales: [I18n.default_locale]) }
|
6
|
+
let(:missing_keys) { i18n.missing_keys }
|
7
|
+
let(:unused_keys) { i18n.unused_keys }
|
8
|
+
|
9
|
+
it "does not have missing keys" do
|
10
|
+
expect(missing_keys).to be_empty,
|
11
|
+
"Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing` to show them"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "does not have unused keys" do
|
15
|
+
expect(unused_keys).to be_empty,
|
16
|
+
"#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused` to show them"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is normalized" do
|
20
|
+
previous_locale_hashes = locale_hashes
|
21
|
+
i18n.normalize_store!
|
22
|
+
new_locale_hashes = locale_hashes
|
23
|
+
|
24
|
+
expect(previous_locale_hashes).to eq(new_locale_hashes),
|
25
|
+
"Please normalize your locale files with `i18n-tasks normalize`"
|
26
|
+
end
|
27
|
+
|
28
|
+
def locale_hashes
|
29
|
+
Dir.glob("config/locales/**/*.yml").inject({}) do |results, file|
|
30
|
+
md5 = Digest::MD5.file(file).hexdigest
|
31
|
+
results.merge(file => md5)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.before(:each) { clear_emails }
|
6
|
+
end
|
7
|
+
|
8
|
+
# A set of helpers meant to make your life easier when testing
|
9
|
+
# emails, especially given the fact that ActionMailer's API can
|
10
|
+
# be a bit inconsistent.
|
11
|
+
module MailerHelpers
|
12
|
+
def emails
|
13
|
+
ActionMailer::Base.deliveries
|
14
|
+
end
|
15
|
+
|
16
|
+
def clear_emails
|
17
|
+
ActionMailer::Base.deliveries.clear
|
18
|
+
end
|
19
|
+
|
20
|
+
def last_email
|
21
|
+
emails.last
|
22
|
+
end
|
23
|
+
|
24
|
+
def last_email_body
|
25
|
+
email_body(last_email)
|
26
|
+
end
|
27
|
+
|
28
|
+
def email_body(email)
|
29
|
+
(email.try(:html_part).try(:body) || email.body).encoded
|
30
|
+
end
|
31
|
+
|
32
|
+
def last_email_link
|
33
|
+
Nokogiri::HTML(last_email_body).css("table.content a").last["href"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def last_email_first_link
|
37
|
+
Nokogiri::HTML(last_email_body).css("table.content a").first["href"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def wait_for_email(options = {})
|
41
|
+
options[:max_attempts] ||= 3
|
42
|
+
attempts = 0
|
43
|
+
loop do
|
44
|
+
if attempts >= options[:max_attempts]
|
45
|
+
raise StandardError, "An email with subject containing '#{options[:subject]}' wasn't sent.'"
|
46
|
+
end
|
47
|
+
|
48
|
+
return if last_email&.subject&.include? options[:subject]
|
49
|
+
|
50
|
+
sleep 1
|
51
|
+
attempts += 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
RSpec.configure do |config|
|
57
|
+
config.include MailerHelpers
|
58
|
+
end
|
59
|
+
|
60
|
+
RSpec.configure do |config|
|
61
|
+
config.before :example, perform_enqueued: true do
|
62
|
+
@old_perform_enqueued_jobs = ActiveJob::Base.queue_adapter.perform_enqueued_jobs
|
63
|
+
@old_perform_enqueued_at_jobs = ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs
|
64
|
+
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
|
65
|
+
ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = true
|
66
|
+
end
|
67
|
+
|
68
|
+
config.after :example, perform_enqueued: true do
|
69
|
+
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = @old_perform_enqueued_jobs
|
70
|
+
ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = @old_perform_enqueued_at_jobs
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "capybara/poltergeist"
|
4
|
+
require "capybara-screenshot/rspec"
|
5
|
+
|
6
|
+
module Decidim
|
7
|
+
# Helpers meant to be used only during capybara test runs.
|
8
|
+
module CapybaraTestHelpers
|
9
|
+
def switch_to_host(host = "lvh.me")
|
10
|
+
unless /lvh\.me$/ =~ host
|
11
|
+
raise "Can't switch to a custom host unless it really exists. Use `whatever.lvh.me` as a workaround."
|
12
|
+
end
|
13
|
+
|
14
|
+
app_host = (host ? "http://#{host}" : nil)
|
15
|
+
Capybara.app_host = app_host
|
16
|
+
end
|
17
|
+
|
18
|
+
def switch_to_default_host
|
19
|
+
Capybara.app_host = nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
capybara_options = {
|
25
|
+
extensions: [
|
26
|
+
File.expand_path(
|
27
|
+
File.join(File.dirname(__FILE__), "phantomjs_polyfills", "promise.js")
|
28
|
+
),
|
29
|
+
File.expand_path(
|
30
|
+
File.join(File.dirname(__FILE__), "phantomjs_polyfills", "bind-polyfill.js")
|
31
|
+
),
|
32
|
+
File.expand_path(
|
33
|
+
File.join(File.dirname(__FILE__), "phantomjs_polyfills", "object-assign-polyfill.js")
|
34
|
+
)
|
35
|
+
],
|
36
|
+
js_errors: true,
|
37
|
+
url_whitelist: ["http://*.lvh.me", "localhost", "127.0.0.1"]
|
38
|
+
}
|
39
|
+
|
40
|
+
Capybara.register_driver :poltergeist do |app|
|
41
|
+
Capybara::Poltergeist::Driver.new(app, capybara_options)
|
42
|
+
end
|
43
|
+
|
44
|
+
Capybara.register_driver :debug do |app|
|
45
|
+
Capybara::Poltergeist::Driver.new(app, capybara_options.merge(inspector: true))
|
46
|
+
end
|
47
|
+
|
48
|
+
Capybara::Screenshot.prune_strategy = :keep_last_run
|
49
|
+
Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples = true
|
50
|
+
|
51
|
+
Capybara.configure do |config|
|
52
|
+
config.always_include_port = true
|
53
|
+
config.default_driver = :poltergeist
|
54
|
+
config.always_include_port = true
|
55
|
+
end
|
56
|
+
|
57
|
+
RSpec.configure do |config|
|
58
|
+
config.before :each, type: :feature do
|
59
|
+
Capybara.current_session.driver.reset!
|
60
|
+
switch_to_default_host
|
61
|
+
end
|
62
|
+
|
63
|
+
config.include Decidim::CapybaraTestHelpers, type: :feature
|
64
|
+
|
65
|
+
if ENV["CI"]
|
66
|
+
require "rspec/repeat"
|
67
|
+
|
68
|
+
config.include RSpec::Repeat
|
69
|
+
config.around :each, type: :feature do |example|
|
70
|
+
repeat example, 5.times, wait: 1, verbose: true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|