diff --git a/.gitignore b/.gitignore index 9432bbd..5dd579c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ spec/test_app/log/*.log spec/test_app/tmp/ Gemfile.lock .byebug_history +binda-api*.gem \ No newline at end of file diff --git a/Gemfile b/Gemfile index ccd4c4f..ef9a5bb 100644 --- a/Gemfile +++ b/Gemfile @@ -5,8 +5,6 @@ source 'https://rubygems.org' # development dependencies will be added by default to the :development group. gemspec -gem "binda", github: "lacolonia/binda", ref: "v0.1.9.alpha.5" - # Declare any dependencies that are still in development here instead of in # your gemspec. These might include edge Rails or gems from your path or # Git. Remember to move these dependencies to your gemspec before releasing diff --git a/README.md b/README.md index 04e98cb..00cec1d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ A GraphQL API for [Binda CMS](http://github.com/lacolonia/binda). **Binda** is a headless CMS with an intuitive out-of-the-box interface which makes very easy creating application infrastructures. For more info about Binda structure please visit the [official documentation](http://www.rubydoc.info/gems/binda) [![Maintainability](https://api.codeclimate.com/v1/badges/d670f30b4635e5d7bb2a/maintainability)](https://codeclimate.com/github/lacolonia/binda-api/maintainability) - [![Test Coverage](https://api.codeclimate.com/v1/badges/d670f30b4635e5d7bb2a/test_coverage)](https://codeclimate.com/github/lacolonia/binda-api/test_coverage) # Quick start diff --git a/binda-api.gemspec b/binda-api.gemspec index c6b5f4c..54b567a 100644 --- a/binda-api.gemspec +++ b/binda-api.gemspec @@ -16,15 +16,15 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] - s.add_dependency "rails", "~> 5.1.5" - s.add_dependency "binda", "~> 0.1" - s.add_dependency "graphql", "1.8.0.pre11" - s.add_dependency "graphiql-rails", "~> 1.4" - s.add_dependency 'rack-cors' - s.add_dependency 'pg' - - s.add_development_dependency 'rspec-rails' - s.add_development_dependency 'byebug' - s.add_development_dependency "factory_bot_rails", "~> 4.8" - s.add_development_dependency 'database_cleaner' + s.add_dependency "rails", "~> 5.1" + s.add_dependency "binda", "~> 0.1.9" + s.add_dependency "graphql", "~> 1.8" + s.add_dependency "graphiql-rails", "~> 1.4" + s.add_dependency 'rack-cors', "~> 1.0" + + s.add_development_dependency 'pg', "~> 1.0" + s.add_development_dependency 'rspec-rails', ">= 3.5", "< 3.8" + s.add_development_dependency 'byebug', "~> 10.0" + s.add_development_dependency "factory_bot_rails", "~> 4.8" + s.add_development_dependency 'database_cleaner', ">= 1.6", "< 2" end diff --git a/lib/binda/api/version.rb b/lib/binda/api/version.rb index 5f07d6a..5cfa12c 100644 --- a/lib/binda/api/version.rb +++ b/lib/binda/api/version.rb @@ -1,5 +1,5 @@ module Binda module Api - VERSION = '0.1.0' + VERSION = '0.1.2' end end diff --git a/spec/.DS_Store b/spec/.DS_Store new file mode 100644 index 0000000..9744421 Binary files /dev/null and b/spec/.DS_Store differ diff --git a/spec/factories/boards.rb b/spec/factories/boards.rb new file mode 100644 index 0000000..85b241e --- /dev/null +++ b/spec/factories/boards.rb @@ -0,0 +1,20 @@ +FactoryBot.define do + + # IMPORTANT: + # if you need to create a board use :board_structure + # + # Boards are automatically generated when you create + # a structure with `instance_type` = `board` + + factory :board_structure_with_fields, parent: :board_structure do + after(:create) do |board_structure, evaluator| + # Fetch the deafult field group + field_group = board_structure.field_groups.first + + # Generate some field settings + create :string_setting, field_group: field_group + create :repeater_setting_with_children_settings, field_group: field_group + end + end + +end diff --git a/spec/factories/checkbox.rb b/spec/factories/checkbox.rb new file mode 100644 index 0000000..4ad3b85 --- /dev/null +++ b/spec/factories/checkbox.rb @@ -0,0 +1,13 @@ +FactoryBot.define do + + factory :checkbox, class: Binda::Checkbox do + association :field_setting, factory: :checkbox_setting + end + + factory :component_and_checkbox, class: Binda::Component, parent: :component do + after(:create) do |component| + create(:checkbox, fieldable_id: component.id, fieldable_type: component.class.name) + end + end + +end \ No newline at end of file diff --git a/spec/factories/choices.rb b/spec/factories/choices.rb new file mode 100644 index 0000000..b410c5f --- /dev/null +++ b/spec/factories/choices.rb @@ -0,0 +1,9 @@ +FactoryBot.define do + + factory :choice, class: Binda::Choice do + sequence(:label){ |n| "Choice ##{n}" } + sequence(:value){ |n| "Lorem ipsum #{n}" } + association :field_setting, factory: :selection_setting + end + +end diff --git a/spec/factories/components.rb b/spec/factories/components.rb new file mode 100644 index 0000000..5f8afcc --- /dev/null +++ b/spec/factories/components.rb @@ -0,0 +1,17 @@ +FactoryBot.define do + + sequence(:article_title) { |n| "This is article number #{ n }" } + + # Component + factory :component, class: Binda::Component do + sequence(:name) { |n| "##{n} component" } + slug { "#{name}".parameterize } + association :structure + end + + # Article Component + factory :article_component, parent: :component do + name { generate(:article_title) } + end + +end diff --git a/spec/factories/field_groups.rb b/spec/factories/field_groups.rb new file mode 100644 index 0000000..23526c6 --- /dev/null +++ b/spec/factories/field_groups.rb @@ -0,0 +1,21 @@ +FactoryBot.define do + + sequence(:field_group_name) { |n| "Default details ##{n}" } + + factory :field_group, class: Binda::FieldGroup do + name { generate :field_group_name } + slug { "#{name}".parameterize } + association :structure + end + + factory :field_group_with_fields, parent: :field_group do + after(:create) do |field_group| + create :string_setting, field_group: field_group + create :text_setting, field_group: field_group + create :repeater_setting_with_children_settings, field_group: field_group + create :radio_setting_with_choices, field_group: field_group + create :selection_setting_with_choices, field_group: field_group + end + end + +end diff --git a/spec/factories/field_settings.rb b/spec/factories/field_settings.rb new file mode 100644 index 0000000..1853f0e --- /dev/null +++ b/spec/factories/field_settings.rb @@ -0,0 +1,101 @@ +FactoryBot.define do + + sequence(:field_name){ |n| "##{n} Field Setting" } + + factory :field_setting, class: Binda::FieldSetting do + name { generate :field_name } + slug { "#{name}".parameterize } + association :field_group + end + + factory :repeater_setting, parent: :field_setting do + field_type 'repeater' + end + + factory :repeater_setting_with_children_settings, parent: :repeater_setting do + after(:create) do |repeater| + repeater.children.create( + name: attributes_for(:field_setting)[:name], + field_type: 'string', + field_group: repeater.field_group + ) + repeater.children.create( + name: attributes_for(:field_setting)[:name], + field_type: 'text', + field_group: repeater.field_group + ) + end + end + + factory :string_setting, parent: :field_setting do + field_type 'string' + end + + factory :text_setting, parent: :field_setting do + field_type 'text' + end + + factory :radio_setting, parent: :field_setting do + field_type 'radio' + allow_null false + end + + factory :radio_setting_with_choices, parent: :radio_setting do + transient do + _count 3 + end + after(:create) do |radio_setting, evaluator| + create_list(:choice, evaluator._count, field_setting: radio_setting) + end + end + + factory :selection_setting, parent: :field_setting do + field_type 'selection' + allow_null true + end + + factory :selection_setting_with_choices, parent: :selection_setting do + transient do + _count 3 + end + after(:create) do |selection_setting, evaluator| + create_list(:choice, evaluator._count, field_setting: selection_setting) + end + end + + factory :checkbox_setting, parent: :field_setting do + field_type 'checkbox' + allow_null true + end + + factory :checkbox_setting_with_choices, parent: :checkbox_setting do + transient do + _count 3 + end + after(:create) do |checkbox_setting, evaluator| + create_list(:choice, evaluator._count, field_setting: checkbox_setting) + end + end + + + factory :relation_setting, parent: :field_setting do + field_type 'relation' + end + + factory :image_setting, parent: :field_setting do + field_type 'image' + end + + factory :video_setting, parent: :field_setting do + field_type 'video' + end + + factory :audio_setting, parent: :field_setting do + field_type 'audio' + end + + factory :svg_setting, parent: :field_setting do + field_type 'svg' + end + +end diff --git a/spec/factories/image.rb b/spec/factories/image.rb new file mode 100644 index 0000000..1eab69f --- /dev/null +++ b/spec/factories/image.rb @@ -0,0 +1,13 @@ +FactoryBot.define do + + factory :image, class: Binda::Image do + association :field_setting, factory: :image_setting + end + + factory :component_and_image, class: Binda::Component, parent: :component do + after(:create) do |component| + create(:image, fieldable_id: component.id, fieldable_type: component.class.name) + end + end + +end \ No newline at end of file diff --git a/spec/factories/radios.rb b/spec/factories/radios.rb new file mode 100644 index 0000000..67c43f8 --- /dev/null +++ b/spec/factories/radios.rb @@ -0,0 +1,13 @@ +FactoryBot.define do + + factory :radio, class: Binda::Radio do + association :field_setting, factory: :radio_setting + end + + factory :component_and_radio, class: Binda::Component, parent: :component do + after(:create) do |component| + create(:radio, fieldable_id: component.id, fieldable_type: component.class.name) + end + end + +end diff --git a/spec/factories/repeaters.rb b/spec/factories/repeaters.rb new file mode 100644 index 0000000..bb25eba --- /dev/null +++ b/spec/factories/repeaters.rb @@ -0,0 +1,10 @@ +FactoryBot.define do + + sequence(:repeater_name){ |n| "##{n} Repeater" } + + # Article repeater + factory :repeater, class: Binda::Repeater do + association :field_setting, factory: :selection_setting + end + +end diff --git a/spec/factories/selections.rb b/spec/factories/selections.rb new file mode 100644 index 0000000..527cde9 --- /dev/null +++ b/spec/factories/selections.rb @@ -0,0 +1,13 @@ +FactoryBot.define do + + factory :selection, class: Binda::Selection do + association :field_setting, factory: :selection_setting + end + + factory :component_and_selection, class: Binda::Component, parent: :component do + after(:create) do |component| + create(:selection, fieldable_id: component.id, fieldable_type: component.class.name) + end + end + +end diff --git a/spec/factories/structures.rb b/spec/factories/structures.rb new file mode 100644 index 0000000..3ea7c7f --- /dev/null +++ b/spec/factories/structures.rb @@ -0,0 +1,57 @@ +FactoryBot.define do + + sequence(:article_structure_title) { |n| "N.#{n} Article" } + sequence(:structure_name) { |n| "##{n} structure" } + + # Structure + factory :structure, class: Binda::Structure do + name { generate :structure_name } + slug { "#{name}".parameterize } + instance_type 'component' + end + + # Boards are automatically generated when you create + # a structure with `instance_type` = `board` + factory :board_structure, class: Binda::Structure do + sequence(:name) { |n| "##{n} board" } + slug { "#{name}".parameterize } + instance_type 'board' + end + + # Article structure + factory :article_structure, parent: :structure do + name { generate :article_structure_title } + end + + # Article structure with components + # @see https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#associations + factory :article_structure_with_components, parent: :structure do + transient do + components_count 3 + end + after(:create) do |structure, evaluator| + create_list( :article_component, evaluator.components_count, structure: structure) + end + end + + # Article structure with components + # @see https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#associations + factory :article_structure_with_components_and_fields, parent: :structure do + transient do + components_count 3 + end + after(:create) do |structure, evaluator| + # get default field group which is generated by default for each structure + default_field_group = structure.field_groups.first + # Generate some field settings + create :string_setting, field_group: default_field_group + create :text_setting, field_group: default_field_group + create :repeater_setting_with_children_settings, field_group: default_field_group + create :radio_setting_with_choices, field_group: default_field_group + create :selection_setting_with_choices, field_group: default_field_group + create :checkbox_setting_with_choices, field_group: default_field_group + create_list( :article_component, evaluator.components_count, structure: structure) + end + end + +end diff --git a/spec/factories/svg.rb b/spec/factories/svg.rb new file mode 100644 index 0000000..cb3112a --- /dev/null +++ b/spec/factories/svg.rb @@ -0,0 +1,13 @@ +FactoryBot.define do + + factory :svg, class: Binda::Svg do + association :field_setting, factory: :svg_setting + end + + factory :component_and_svg, class: Binda::Component, parent: :component do + after(:create) do |component| + create(:svg, fieldable_id: component.id, fieldable_type: component.class.name) + end + end + +end \ No newline at end of file diff --git a/spec/factories/texts.rb b/spec/factories/texts.rb new file mode 100644 index 0000000..e51dd2b --- /dev/null +++ b/spec/factories/texts.rb @@ -0,0 +1,13 @@ +FactoryBot.define do + + sequence(:text_name){ |n| "##{n} Lorem ipsum sit dolor" } + + factory :string, class: Binda::String do + content { generate :text_name } + end + + factory :text, class: Binda::Text do + content { generate :text_name } + end + +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 0000000..8b85966 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,13 @@ +FactoryBot.define do + + factory :user, class: Binda::User do + + email "mail@domain.com" + + pw = "abcDEF123$£@" + password pw + password_confirmation pw + + end + +end