decidim 0.0.1.alpha7 → 0.0.1.alpha8
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -1
- data/.eslintignore +1 -0
- data/.eslintrc.json +12 -0
- data/.github/ISSUE_TEMPLATE.md +12 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +8 -11
- data/.gitignore +1 -0
- data/.hound.yml +4 -0
- data/.rubocop.yml +14 -1
- data/.travis.yml +20 -4
- data/CODE_OF_CONDUCT.md +1 -1
- data/Dockerfile +1 -0
- data/Gemfile +3 -2
- data/Gemfile.common +1 -1
- data/Gemfile.lock +68 -39
- data/LICENSE.txt +619 -21
- data/README.md +17 -13
- data/Rakefile +1 -1
- data/codecov.yml +6 -1
- data/crowdin.yaml +4 -0
- data/decidim-admin/LICENSE.txt +619 -0
- data/decidim-admin/README.md +1 -1
- data/decidim-admin/app/assets/javascripts/decidim/admin/application.js.es6 +12 -0
- data/decidim-admin/app/assets/javascripts/decidim/admin/sort_steps.js.es6 +21 -0
- data/decidim-admin/app/assets/stylesheets/decidim/admin/_tables.scss +9 -0
- data/decidim-admin/app/commands/decidim/admin/activate_participatory_process_step.rb +43 -0
- data/decidim-admin/app/commands/decidim/admin/create_participatory_process.rb +1 -0
- data/decidim-admin/app/commands/decidim/admin/create_participatory_process_step.rb +46 -0
- data/decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb +35 -0
- data/decidim-admin/app/commands/decidim/admin/publish_participatory_process.rb +35 -0
- data/decidim-admin/app/commands/decidim/admin/reorder_participatory_process_steps.rb +47 -0
- data/decidim-admin/app/commands/decidim/admin/unpublish_participatory_process.rb +35 -0
- data/decidim-admin/app/commands/decidim/admin/update_participatory_process.rb +1 -0
- data/decidim-admin/app/commands/decidim/admin/update_participatory_process_step.rb +49 -0
- data/decidim-admin/app/constraints/decidim/admin/organization_dashboard_constraint.rb +1 -1
- data/decidim-admin/app/controllers/decidim/admin/application_controller.rb +4 -0
- data/decidim-admin/app/controllers/decidim/admin/dashboard_controller.rb +1 -9
- data/decidim-admin/app/controllers/decidim/admin/participatory_process_publications_controller.rb +49 -0
- data/decidim-admin/app/controllers/decidim/admin/participatory_process_step_activations_controller.rb +56 -0
- data/decidim-admin/app/controllers/decidim/admin/participatory_process_step_ordering_controller.rb +30 -0
- data/decidim-admin/app/controllers/decidim/admin/participatory_process_steps_controller.rb +81 -0
- data/decidim-admin/app/controllers/decidim/admin/participatory_processes_controller.rb +7 -12
- data/decidim-admin/app/forms/decidim/admin/participatory_process_form.rb +1 -0
- data/decidim-admin/app/forms/decidim/admin/participatory_process_step_form.rb +25 -0
- data/decidim-admin/app/helpers/decidim/admin/application_helper.rb +1 -0
- data/decidim-admin/app/mailers/decidim/admin/application_mailer.rb +1 -1
- data/decidim-admin/app/models/decidim/admin/abilities/admin.rb +21 -0
- data/decidim-admin/app/views/decidim/admin/participatory_process_steps/_form.html.erb +19 -0
- data/decidim-admin/app/views/decidim/admin/participatory_process_steps/_table.html.erb +53 -0
- data/decidim-admin/app/views/decidim/admin/participatory_process_steps/edit.html.erb +11 -0
- data/decidim-admin/app/views/decidim/admin/participatory_process_steps/new.html.erb +11 -0
- data/decidim-admin/app/views/decidim/admin/participatory_process_steps/show.html.erb +22 -0
- data/decidim-admin/app/views/decidim/admin/participatory_processes/_form.html.erb +4 -0
- data/decidim-admin/app/views/decidim/admin/participatory_processes/index.html.erb +22 -2
- data/decidim-admin/app/views/decidim/admin/participatory_processes/show.html.erb +21 -2
- data/decidim-admin/config/i18n-tasks.yml +2 -2
- data/decidim-admin/config/locales/ca.yml +55 -2
- data/decidim-admin/config/locales/en.yml +55 -2
- data/decidim-admin/config/locales/es.yml +56 -3
- data/decidim-admin/config/routes.rb +10 -1
- data/decidim-admin/decidim-admin.gemspec +6 -7
- data/decidim-admin/lib/decidim/admin/engine.rb +6 -1
- data/decidim-admin/spec/commands/activate_participatory_process_step_spec.rb +44 -0
- data/decidim-admin/spec/commands/deactivate_participatory_process_step_spec.rb +35 -0
- data/decidim-admin/spec/commands/publish_participatory_process_spec.rb +35 -0
- data/decidim-admin/spec/commands/reorder_participatory_process_steps_spec.rb +53 -0
- data/decidim-admin/spec/commands/unpublish_participatory_process_spec.rb +35 -0
- data/decidim-admin/spec/controllers/participatory_processes_controller_spec.rb +32 -0
- data/decidim-admin/spec/features/manage_participatory_process_steps_spec.rb +151 -0
- data/decidim-admin/spec/features/manage_participatory_processes_spec.rb +87 -39
- data/decidim-admin/spec/forms/participatory_process_form_spec.rb +122 -0
- data/decidim-admin/spec/forms/participatory_process_step_form_spec.rb +113 -0
- data/decidim-admin/spec/models/abilities/admin_spec.rb +25 -0
- data/decidim-admin/spec/spec_helper.rb +0 -1
- data/decidim-admin/vendor/assets/javascripts/html.sortable.min.js +2 -0
- data/decidim-api/.gitignore +7 -0
- data/decidim-api/LICENSE.txt +619 -0
- data/decidim-api/README.md +28 -0
- data/decidim-api/Rakefile +27 -0
- data/decidim-api/app/controllers/decidim/api/application_controller.rb +9 -0
- data/decidim-api/app/controllers/decidim/api/queries_controller.rb +33 -0
- data/decidim-api/app/schemas/decidim/api/schema.rb +9 -0
- data/decidim-api/app/types/decidim/api/localized_string_type.rb +13 -0
- data/decidim-api/app/types/decidim/api/process_step_type.rb +26 -0
- data/decidim-api/app/types/decidim/api/process_type.rb +18 -0
- data/decidim-api/app/types/decidim/api/query_type.rb +19 -0
- data/decidim-api/app/types/decidim/api/translated_field_type.rb +44 -0
- data/decidim-api/bin/rails +14 -0
- data/decidim-api/config/routes.rb +6 -0
- data/decidim-api/decidim-api.gemspec +27 -0
- data/decidim-api/lib/decidim/api.rb +9 -0
- data/decidim-api/lib/decidim/api/engine.rb +22 -0
- data/decidim-api/lib/tasks/decidim/api_tasks.rake +5 -0
- data/decidim-api/spec/controllers/queries_controller_spec.rb +22 -0
- data/decidim-api/spec/factories.rb +1 -0
- data/decidim-api/spec/schemas/schema_spec.rb +38 -0
- data/decidim-api/spec/spec_helper.rb +2 -0
- data/decidim-api/spec/support/type_helpers.rb +46 -0
- data/decidim-api/spec/types/localized_string_type_spec.rb +30 -0
- data/decidim-api/spec/types/process_step_type_spec.rb +50 -0
- data/decidim-api/spec/types/process_type_spec.rb +39 -0
- data/decidim-api/spec/types/query_type_spec.rb +24 -0
- data/decidim-api/spec/types/translated_field_type_spec.rb +68 -0
- data/decidim-dev/README.md +1 -1
- data/decidim-dev/decidim-dev.gemspec +5 -3
- data/decidim-dev/lib/decidim/dummy_authorization_handler.rb +18 -0
- data/decidim-dev/lib/decidim/test/authorization_shared_examples.rb +31 -0
- data/decidim-dev/lib/decidim/test/base_spec_helper.rb +6 -1
- data/decidim-dev/lib/decidim/test/rspec_support/authenticated_controller_context.rb +9 -0
- data/decidim-dev/lib/decidim/test/rspec_support/authorization_handlers.rb +7 -0
- data/decidim-dev/lib/decidim/test/rspec_support/bullet.rb +15 -0
- data/decidim-dev/lib/decidim/test/rspec_support/engine_routes.rb +30 -0
- data/decidim-dev/lib/decidim/test/rspec_support/translation_helpers.rb +12 -0
- data/decidim-dev/lib/generators/decidim/dummy_generator.rb +10 -0
- data/decidim-dev/lib/generators/decidim/templates/bullet.rb +6 -0
- data/decidim-system/LICENSE.txt +619 -0
- data/decidim-system/README.md +1 -1
- data/decidim-system/app/assets/javascripts/decidim/system/application.js.es6 +10 -0
- data/decidim-system/app/mailers/decidim/system/application_mailer.rb +1 -1
- data/decidim-system/decidim-system.gemspec +4 -4
- data/decidim.gemspec +3 -2
- data/lib/decidim.rb +1 -6
- data/lib/generators/decidim/app_generator.rb +13 -1
- data/lib/generators/decidim/install_generator.rb +11 -2
- data/lib/generators/decidim/templates/Gemfile.erb +5 -2
- data/lib/generators/decidim/templates/authorization_handler.rb +50 -0
- data/lib/generators/decidim/templates/carrierwave.rb +27 -0
- data/lib/generators/decidim/templates/decidim.scss.erb +3 -0
- data/lib/generators/decidim/templates/initializer.rb +3 -1
- data/package.json +21 -0
- data/yarn.lock +890 -0
- metadata +102 -21
- data/.eslintrc +0 -213
- data/decidim-admin/app/assets/javascripts/decidim/admin/application.js +0 -22
- data/decidim-admin/app/controllers/concerns/decidim/needs_authorization.rb +0 -50
- data/decidim-admin/app/policies/decidim/admin/application_policy.rb +0 -20
- data/decidim-admin/app/policies/decidim/admin/dashboard_policy.rb +0 -15
- data/decidim-admin/app/policies/decidim/admin/organization_policy.rb +0 -15
- data/decidim-admin/app/policies/decidim/admin/participatory_process_policy.rb +0 -57
- data/decidim-admin/spec/policies/dashboard_policy_spec.rb +0 -23
- data/decidim-admin/spec/policies/organization_policy_spec.rb +0 -41
- data/decidim-admin/spec/policies/participatory_process_policy_spec.rb +0 -153
- data/decidim-system/app/assets/javascripts/decidim/system/application.js +0 -22
@@ -0,0 +1,28 @@
|
|
1
|
+
# Decidim::Api
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'decidim-admin'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install decidim-admin
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [AGPLv3 License](https://opensource.org/licenses/AGPL-3.0).
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/common_rake"
|
4
|
+
require "rdoc/task"
|
5
|
+
|
6
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
7
|
+
rdoc.rdoc_dir = "rdoc"
|
8
|
+
rdoc.title = "Decidim::Api"
|
9
|
+
rdoc.options << "--line-numbers"
|
10
|
+
rdoc.rdoc_files.include("README.md")
|
11
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
load "rails/tasks/statistics.rake"
|
15
|
+
|
16
|
+
require "bundler/gem_tasks"
|
17
|
+
|
18
|
+
begin
|
19
|
+
require "rspec/core/rake_task"
|
20
|
+
RSpec::Core::RakeTask.new(:spec)
|
21
|
+
ENV["ENGINE_PATH"] = File.dirname(__FILE__)
|
22
|
+
|
23
|
+
task default: :spec
|
24
|
+
|
25
|
+
Rake::Task["spec"].enhance ["common:test_app"]
|
26
|
+
rescue LoadError
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Api
|
4
|
+
# This controller takes queries from an HTTP endpoint and sends them out to
|
5
|
+
# the Schema to be executed, later returning the response as JSON.
|
6
|
+
class QueriesController < ApplicationController
|
7
|
+
def create
|
8
|
+
query_string = params[:query]
|
9
|
+
query_variables = ensure_hash(params[:variables])
|
10
|
+
result = Schema.execute(query_string, variables: query_variables, context: context)
|
11
|
+
render json: result
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def context
|
17
|
+
{
|
18
|
+
current_organization: current_organization
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def ensure_hash(query_variables)
|
23
|
+
if query_variables.blank?
|
24
|
+
{}
|
25
|
+
elsif query_variables.is_a?(String)
|
26
|
+
JSON.parse(query_variables)
|
27
|
+
else
|
28
|
+
query_variables
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Api
|
4
|
+
# This type represents a localized string in a single language.
|
5
|
+
LocalizedStringType = GraphQL::ObjectType.define do
|
6
|
+
name "LocalizedStringFieldType"
|
7
|
+
description "Represents a particular translation of a LocalizedStringType"
|
8
|
+
|
9
|
+
field :locale, !types.String, "The standard locale of this translation."
|
10
|
+
field :text, types.String, "The content of this translation."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Api
|
4
|
+
# This type represents a step on a participatory process.
|
5
|
+
ProcessStepType = GraphQL::ObjectType.define do
|
6
|
+
name "ParticipatoryProcessStep"
|
7
|
+
description "A participatory process step"
|
8
|
+
|
9
|
+
field :id, !types.ID, "The unique ID of this step."
|
10
|
+
|
11
|
+
field :process do
|
12
|
+
type ProcessType
|
13
|
+
description "The participatory process in which this step belongs to."
|
14
|
+
property :participatory_process
|
15
|
+
end
|
16
|
+
|
17
|
+
field :title, TranslatedFieldType, "The title of this step"
|
18
|
+
|
19
|
+
field :shortDescription do
|
20
|
+
type TranslatedFieldType
|
21
|
+
description "A short description of the step."
|
22
|
+
property :short_description
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Api
|
4
|
+
# This type represents a ParticipatoryProcess.
|
5
|
+
ProcessType = GraphQL::ObjectType.define do
|
6
|
+
name "ParticipatoryProcess"
|
7
|
+
description "A participatory process"
|
8
|
+
|
9
|
+
field :id, !types.ID, "The Process' unique ID"
|
10
|
+
|
11
|
+
field :title, TranslatedFieldType, "The title of this process."
|
12
|
+
|
13
|
+
connection :steps, ProcessStepType.connection_type do
|
14
|
+
description "All the steps of this process."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Api
|
4
|
+
# This type represents the root type of the whole API.
|
5
|
+
QueryType = GraphQL::ObjectType.define do
|
6
|
+
name "Query"
|
7
|
+
description "The root query of this schema"
|
8
|
+
|
9
|
+
field :processes do
|
10
|
+
type !types[ProcessType]
|
11
|
+
description "Lists all processes."
|
12
|
+
|
13
|
+
resolve ->(_obj, _args, ctx) {
|
14
|
+
ctx[:current_organization].participatory_processes
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Api
|
4
|
+
# This type represents a translated field in multiple languages.
|
5
|
+
TranslatedFieldType = GraphQL::ObjectType.define do
|
6
|
+
name "TranslatedFieldType"
|
7
|
+
description "A translated field"
|
8
|
+
|
9
|
+
field :locales do
|
10
|
+
type types[types.String]
|
11
|
+
description "Lists all the locales in which this translation is available"
|
12
|
+
resolve ->(obj, _args, _ctx) { obj.keys }
|
13
|
+
end
|
14
|
+
|
15
|
+
field :translations do
|
16
|
+
type !types[LocalizedStringType]
|
17
|
+
description "All the localized strings for this translation."
|
18
|
+
|
19
|
+
argument :locales do
|
20
|
+
type types[types.String]
|
21
|
+
description "A list of locales to scope the translations to."
|
22
|
+
end
|
23
|
+
|
24
|
+
resolve ->(obj, args, _ctx) {
|
25
|
+
translations = obj.stringify_keys
|
26
|
+
translations = translations.slice(*args["locales"]) if args["locales"]
|
27
|
+
|
28
|
+
translations.map { |locale, text| OpenStruct.new(locale: locale, text: text) }
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
field :translation do
|
33
|
+
type types.String
|
34
|
+
description "Returns a single translation given a locale."
|
35
|
+
argument :locale, types.String, "A locale to search for"
|
36
|
+
|
37
|
+
resolve ->(obj, args, _ctx) {
|
38
|
+
translations = obj.stringify_keys
|
39
|
+
translations[args["locale"]]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
4
|
+
# installed from the root of your application.
|
5
|
+
|
6
|
+
ENGINE_ROOT = File.expand_path("../..", __FILE__)
|
7
|
+
ENGINE_PATH = File.expand_path("../../lib/decidim/api/engine", __FILE__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
|
11
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
12
|
+
|
13
|
+
require "rails/all"
|
14
|
+
require "rails/engine/commands"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
# Maintain your gem's version:
|
5
|
+
require_relative "../decidim-core/lib/decidim/core/version"
|
6
|
+
|
7
|
+
# Describe your gem and declare its dependencies:
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = "decidim-api"
|
10
|
+
s.version = Decidim.version
|
11
|
+
s.authors = ["Josep Jaume Rey Peroy", "Marc Riera Casals", "Oriol Gual Oliva"]
|
12
|
+
s.email = ["josepjaume@gmail.com", "mrc2407@gmail.com", "oriolgual@gmail.com"]
|
13
|
+
s.homepage = "http://github.com/AjuntamentdeBarcelona/decidim"
|
14
|
+
s.summary = "API engine for decidim"
|
15
|
+
s.description = "API engine for decidim"
|
16
|
+
s.license = "AGPLv3"
|
17
|
+
|
18
|
+
s.files = Dir["{app,config,db,lib}/**/*", "LICENSE.txt", "Rakefile", "README.md"]
|
19
|
+
|
20
|
+
s.add_dependency "decidim-core", Decidim.version
|
21
|
+
s.add_dependency "rails", Decidim.rails_version
|
22
|
+
s.add_dependency "graphql", "~> 0.19.4"
|
23
|
+
s.add_dependency "graphiql-rails", "~> 1.3.0"
|
24
|
+
s.add_dependency "rack-cors", "~> 0.4.0"
|
25
|
+
|
26
|
+
s.add_development_dependency "decidim-dev", Decidim.version
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql"
|
3
|
+
require "graphiql/rails"
|
4
|
+
require "rack/cors"
|
5
|
+
|
6
|
+
module Decidim
|
7
|
+
module Api
|
8
|
+
# Mountable engine that exposes a side-wide API for Decidim.
|
9
|
+
class Engine < ::Rails::Engine
|
10
|
+
isolate_namespace Decidim::Api
|
11
|
+
|
12
|
+
initializer "decidim-api.middleware" do |app|
|
13
|
+
app.config.middleware.insert_before 0, Rack::Cors do
|
14
|
+
allow do
|
15
|
+
origins "*"
|
16
|
+
resource "*", headers: :any, methods: [:get, :post, :options]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
module Decidim
|
5
|
+
module Api
|
6
|
+
describe QueriesController, type: :controller do
|
7
|
+
let!(:participatory_process) { create(:participatory_process) }
|
8
|
+
let!(:other_participatory_process) { create(:participatory_process) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
@request.env["decidim.current_organization"] = participatory_process.organization
|
12
|
+
end
|
13
|
+
|
14
|
+
it "executes a query" do
|
15
|
+
post :create, params: { query: "{ processes { id }}" }
|
16
|
+
|
17
|
+
parsed_response = JSON.parse(response.body)["data"]
|
18
|
+
expect(parsed_response["processes"]).to eq(["id" => participatory_process.id.to_s])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "../../decidim-core/spec/factories"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
module Decidim
|
5
|
+
module Api
|
6
|
+
describe Schema do
|
7
|
+
let!(:current_user) { create(:user) }
|
8
|
+
let!(:current_organization) { current_user.organization }
|
9
|
+
|
10
|
+
def execute_query(query, variables = {})
|
11
|
+
described_class.execute(
|
12
|
+
query,
|
13
|
+
context: {
|
14
|
+
current_organization: current_organization,
|
15
|
+
current_user: current_user
|
16
|
+
},
|
17
|
+
variables: variables
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "processes" do
|
22
|
+
let!(:process1) { create(:participatory_process, organization: current_organization) }
|
23
|
+
let!(:process2) { create(:participatory_process, organization: current_organization) }
|
24
|
+
let!(:process3) { create(:participatory_process) }
|
25
|
+
|
26
|
+
let(:query) { %({ processes { id } }) }
|
27
|
+
|
28
|
+
it "returns all the processes" do
|
29
|
+
result = execute_query(query)
|
30
|
+
|
31
|
+
expect(result["data"]["processes"]).to include("id" => process1.id.to_s)
|
32
|
+
expect(result["data"]["processes"]).to include("id" => process2.id.to_s)
|
33
|
+
expect(result["data"]["processes"]).to_not include("id" => process3.id.to_s)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Decidim
|
2
|
+
module Api
|
3
|
+
module TypeHelpers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
let!(:current_organization) { create(:organization) }
|
8
|
+
let(:model) { OpenStruct.new({}) }
|
9
|
+
|
10
|
+
let(:schema) do
|
11
|
+
resolver = ->(_obj, _args, _ctx) { model }
|
12
|
+
type_class = described_class
|
13
|
+
|
14
|
+
query_type = GraphQL::ObjectType.define do
|
15
|
+
name "FakeTestQuery"
|
16
|
+
|
17
|
+
field :type, !type_class do
|
18
|
+
resolve resolver
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
GraphQL::Schema.define do
|
23
|
+
query query_type
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:response) do
|
28
|
+
execute_query "{ type #{query}}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute_query(query, variables = {})
|
33
|
+
result = schema.execute(
|
34
|
+
query,
|
35
|
+
context: {
|
36
|
+
current_organization: current_organization
|
37
|
+
},
|
38
|
+
variables: variables
|
39
|
+
)
|
40
|
+
|
41
|
+
raise Exception, result["errors"].map { |e| e["message"] }.join(", ") if result["errors"]
|
42
|
+
result["data"]["type"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|