diff --git a/.rspec b/.rspec index c99d2e73..f8f74f2a 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,3 @@ +--color --require spec_helper +--format documentation \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 0661dbe0..3442c164 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - binda (0.0.8.pre.alpha.3) + binda (0.0.8.pre.alpha.4) aasm (>= 4.11, < 4.13) ancestry (>= 2.1, < 3.1) carrierwave (>= 0.10, < 1.12) @@ -23,49 +23,48 @@ GEM specs: aasm (4.12.2) concurrent-ruby (~> 1.0) - actioncable (5.1.3) - actionpack (= 5.1.3) + actioncable (5.1.4) + actionpack (= 5.1.4) nio4r (~> 2.0) websocket-driver (~> 0.6.1) - actionmailer (5.1.3) - actionpack (= 5.1.3) - actionview (= 5.1.3) - activejob (= 5.1.3) + actionmailer (5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.3) - actionview (= 5.1.3) - activesupport (= 5.1.3) + actionpack (5.1.4) + actionview (= 5.1.4) + activesupport (= 5.1.4) rack (~> 2.0) - rack-test (~> 0.6.3) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.3) - activesupport (= 5.1.3) + actionview (5.1.4) + activesupport (= 5.1.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.3) - activesupport (= 5.1.3) + activejob (5.1.4) + activesupport (= 5.1.4) globalid (>= 0.3.6) - activemodel (5.1.3) - activesupport (= 5.1.3) - activerecord (5.1.3) - activemodel (= 5.1.3) - activesupport (= 5.1.3) + activemodel (5.1.4) + activesupport (= 5.1.4) + activerecord (5.1.4) + activemodel (= 5.1.4) + activesupport (= 5.1.4) arel (~> 8.0) - activesupport (5.1.3) + activesupport (5.1.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.5.1) - public_suffix (~> 2.0, >= 2.0.2) + addressable (2.4.0) ancestry (3.0.1) activerecord (>= 3.2.0) arel (8.0.0) - autoprefixer-rails (7.1.2.4) + autoprefixer-rails (7.1.4) execjs backports (3.8.0) bcrypt (3.1.11) @@ -86,7 +85,7 @@ GEM mime-types (>= 1.16) childprocess (0.7.1) ffi (~> 1.0, >= 1.0.11) - coderay (1.1.1) + coderay (1.1.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -95,7 +94,6 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.0.5) - connection_pool (2.2.1) database_cleaner (1.6.1) devise (4.3.0) bcrypt (~> 3.0) @@ -120,12 +118,12 @@ GEM ffi (1.9.18) friendly_id (5.2.1) activerecord (>= 4.0.0) - gh (0.14.0) - addressable + gh (0.15.1) + addressable (~> 2.4.0) backports faraday (~> 0.8) multi_json (~> 1.0) - net-http-persistent (>= 2.7) + net-http-persistent (~> 2.9) net-http-pipeline github-markup (1.6.1) globalid (0.4.0) @@ -166,47 +164,45 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_magick (4.7.2) - mini_mime (0.1.3) + mini_mime (0.1.4) mini_portile2 (2.2.0) minitest (5.10.3) minitest-rails (3.0.0) minitest (~> 5.8) railties (~> 5.0) - multi_json (1.12.1) + multi_json (1.12.2) multipart-post (2.0.0) - net-http-persistent (3.0.0) - connection_pool (~> 2.2) + net-http-persistent (2.9.4) net-http-pipeline (1.0.1) nio4r (2.1.0) nokogiri (1.8.0) mini_portile2 (~> 2.2.0) orm_adapter (0.5.0) pg (0.21.0) - power_assert (0.2.6) + power_assert (1.1.0) pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) pry-rails (0.3.6) pry (>= 0.10.4) - public_suffix (2.0.5) pusher-client (0.6.2) json websocket (~> 1.0) rack (2.0.3) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.1.3) - actioncable (= 5.1.3) - actionmailer (= 5.1.3) - actionpack (= 5.1.3) - actionview (= 5.1.3) - activejob (= 5.1.3) - activemodel (= 5.1.3) - activerecord (= 5.1.3) - activesupport (= 5.1.3) + rack-test (0.7.0) + rack (>= 1.0, < 3) + rails (5.1.4) + actioncable (= 5.1.4) + actionmailer (= 5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + activemodel (= 5.1.4) + activerecord (= 5.1.4) + activesupport (= 5.1.4) bundler (>= 1.3.0) - railties (= 5.1.3) + railties (= 5.1.4) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) @@ -214,13 +210,13 @@ GEM rails-html-sanitizer (1.0.3) loofah (~> 2.0) rails-perftest (0.0.7) - railties (5.1.3) - actionpack (= 5.1.3) - activesupport (= 5.1.3) + railties (5.1.4) + actionpack (= 5.1.4) + activesupport (= 5.1.4) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.0.0) + rake (12.1.0) rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) @@ -259,7 +255,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - selenium-webdriver (3.5.1) + selenium-webdriver (3.5.2) childprocess (~> 0.5) rubyzip (~> 1.0) simple_form (3.5.0) @@ -273,9 +269,9 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - test-unit (3.1.5) + test-unit (3.2.5) power_assert - thor (0.19.4) + thor (0.20.0) thread_safe (0.3.6) tilt (2.0.8) tinymce-rails (4.6.6) diff --git a/app/controllers/concerns/binda/default_helpers.rb b/app/controllers/concerns/binda/default_helpers.rb index 983357ee..e5204cee 100644 --- a/app/controllers/concerns/binda/default_helpers.rb +++ b/app/controllers/concerns/binda/default_helpers.rb @@ -151,48 +151,6 @@ def get_board( slug, args = { fields: [] }) end end - # This method retrieves a **repeater**. - # With this method you can optimize the query in order to avoid the infamous - # [N+1 issue](https://youtu.be/oJ4Ur5XPAF8) by specifing what field types - # you are going to request in the view. The list of field types available - # can be found in the [official documentation](https://github.com/lacolonia/binda/wiki/Fields). - # Field types must be listed as separated strings, lowercase and plural. - # See the following examples. - # - # @example Get a repeater with slug `slideshow` - # get_repeater('slideshow') - # # return the repeater - # - # get_repeater('slideshow', { fields: ['strings', 'assets'] }) - # # return the repeater and optimize the query for any of the listed fields related to it - # - # - # @param slug [string] The slug of the repeater - # @param args [hash] A hash containing the options used to customize the query. - # - # The hash parameters are: - # - # - `fields` (array) - Include related field classes to the query. The list of field types available - # can be found in the [official documentation](https://github.com/lacolonia/binda/wiki/Fields). - # Field types must be listed as separated strings, lowercase and plural. - # - # @return [ActiveRecord Object] - def get_repeater( slug, args = { fields: [] }) - - validate_provided_arguments( args ) - - # Sets defaults - args[:fields] = [] if args[:fields].nil? - - validate_provided_fields( args ) - - if args[:fields].any? - Repeater.where(slug: slug).first.inlcudes( args[:fields] ) - else - Repeater.where(slug: slug).first - end - end - private # Check if provided `fields` are ok, otherwise raise an error diff --git a/app/models/binda/field_setting.rb b/app/models/binda/field_setting.rb index 0683b47c..debeb1af 100644 --- a/app/models/binda/field_setting.rb +++ b/app/models/binda/field_setting.rb @@ -15,10 +15,10 @@ class FieldSetting < ApplicationRecord has_many :dates, as: :fieldable has_many :galleries, as: :fieldable has_many :assets, as: :fieldable - has_many :repeater, as: :fieldable - has_many :radio, as: :fieldable - has_many :selection, as: :fieldable - has_many :checkbox, as: :fieldable + has_many :repeaters, as: :fieldable + has_many :radios, as: :fieldable + has_many :selections, as: :fieldable + has_many :checkboxes, as: :fieldable # The following direct association is used to securely delete associated fields @@ -28,10 +28,10 @@ class FieldSetting < ApplicationRecord has_many :strings, dependent: :delete_all has_many :dates, dependent: :delete_all has_many :galleries, dependent: :delete_all - has_many :repeater, dependent: :delete_all - has_many :radio, dependent: :delete_all - has_many :selection, dependent: :delete_all - has_many :checkbox, dependent: :delete_all + has_many :repeaters, dependent: :delete_all + has_many :radios, dependent: :delete_all + has_many :selections, dependent: :delete_all + has_many :checkboxes, dependent: :delete_all has_many :choices, dependent: :delete_all has_one :default_choice, -> (field_setting) { where(id: field_setting.default_choice_id) }, class_name: 'Binda::Choice' diff --git a/app/views/binda/fieldable/_form_section_repeater.html.erb b/app/views/binda/fieldable/_form_section_repeater.html.erb index 5ba854a7..8f4ca3ed 100644 --- a/app/views/binda/fieldable/_form_section_repeater.html.erb +++ b/app/views/binda/fieldable/_form_section_repeater.html.erb @@ -41,7 +41,7 @@ <%# - - - - - - - - - - - - %> <%# SELECTABLES %> <%# - - - - - - - - - - - - %> -<% elsif ['radio', 'select', 'checkbox'].include? repeater_setting_child.field_type %> +<% elsif ['radio', 'selection', 'checkbox'].include? repeater_setting_child.field_type %> <%# current = f.object.find_or_create_a_field_by( repeater_setting_child.id, 'radio' ) %> <%= render 'binda/fieldable/form_item_selections', f: f, field_setting: repeater_setting_child %> diff --git a/binda-0.0.8.pre.alpha.3.gem b/binda-0.0.8.pre.alpha.3.gem deleted file mode 100644 index 2c0e3889..00000000 Binary files a/binda-0.0.8.pre.alpha.3.gem and /dev/null differ diff --git a/binda-0.0.8.pre.alpha.4.gem b/binda-0.0.8.pre.alpha.4.gem new file mode 100644 index 00000000..c0a6f433 Binary files /dev/null and b/binda-0.0.8.pre.alpha.4.gem differ diff --git a/lib/binda/version.rb b/lib/binda/version.rb index 17a5e65c..d3145662 100644 --- a/lib/binda/version.rb +++ b/lib/binda/version.rb @@ -1,3 +1,3 @@ module Binda - VERSION = '0.0.8-alpha.3' + VERSION = '0.0.8-alpha.4' end \ No newline at end of file diff --git a/spec/features/component_spec.rb b/spec/features/component_spec.rb index 2f331930..ab98f905 100644 --- a/spec/features/component_spec.rb +++ b/spec/features/component_spec.rb @@ -1,13 +1,13 @@ require "rails_helper" -describe "Indexing components:", type: :feature do +describe "GET components#index:", type: :feature do let(:user) { Binda::User.first } before(:context) do @structure = create(:article_structure_with_components) end - it "reorder components based on position" do + it "display components sorted by position" do sign_in user first_component = @structure.components.order(:position).first @@ -31,7 +31,7 @@ end end -describe "Editing component:", type: :feature, js: true do +describe "GET component#edit", type: :feature, js: true do let(:user){ Binda::User.first } @@ -40,31 +40,6 @@ @component = @structure.components.first end - it "fails if you try to create a component with no name" do - sign_in user - path = binda.new_structure_component_path( structure_id: @structure.slug ) - visit path - expect( page ).to have_current_path( path ) - previous_components_quantity = @structure.components.length - click_button "form-body--save" - current_components_quantity = @structure.components.length - expect( current_components_quantity ).to eq( previous_components_quantity ) - end - - it "creates a new component if name is provided" do - sign_in user - path = binda.new_structure_component_path( structure_id: @structure.slug ) - visit path - expect( page ).to have_current_path( path ) - string_value = 'hello' - fill_in "component_name", with: 'hello' - expect( find('#component_name').value ).to eq string_value - click_button "form-body--save" - # @todo this should be changed - expect( page ).not_to have_content "You need to create the component before being able to add any detail" - expect( Binda::Component.where( structure_id: @structure, name: string_value ).count ).to eq 1 - end - it "isn't blocked by any Rails error" do sign_in user path = binda.edit_structure_component_path( structure_id: @structure.slug, id: @component.slug ) @@ -73,7 +48,7 @@ expect( page ).to have_selector "#component_name[value='#{ @component.name }']" end - it "lets edit a string field" do + it "allows to edit a string field" do sign_in user path = binda.edit_structure_component_path( @structure, @component ) visit path @@ -86,7 +61,7 @@ expect( @component.strings.first.content ).to eq string_value end - it "lets edit a string field in a repeater" do + it "allows to edit a string field in a repeater" do # sign_in user # path = binda.edit_structure_component_path( @structure, @component ) # visit path @@ -100,55 +75,55 @@ skip "not implemented yet" end - it "lets edit a text field" do + it "allows to edit a text field" do skip "not implemeted yet" end - it "lets edit a text field in a repeater" do + it "allows to edit a text field in a repeater" do skip "not implemeted yet" end - it "lets edit a selection field" do + it "allows to edit a selection field" do skip "not implemeted yet" end - it "lets edit a selection field in a repeater" do + it "allows to edit a selection field in a repeater" do skip "not implemeted yet" end - it "lets edit a radio field" do + it "allows to edit a radio field" do skip "not implemeted yet" end - it "lets edit a radio field in a repeater" do + it "allows to edit a radio field in a repeater" do skip "not implemeted yet" end - it "lets edit a checkbox field" do + it "allows to edit a checkbox field" do skip "not implemeted yet" end - it "lets edit a checkbox field in a repeater" do + it "allows to edit a checkbox field in a repeater" do skip "not implemeted yet" end - it "lets add an image to an asset field" do + it "allows to add an image to an asset field" do skip "not implemeted yet" end - it "lets add an image to an asset field in a repeater" do + it "allows to add an image to an asset field in a repeater" do skip "not implemeted yet" end - it "lets remove an image to an asset field" do + it "allows to remove an image to an asset field" do skip "not implemeted yet" end - it "lets remove an image to an asset field in a repeater" do + it "allows to remove an image to an asset field in a repeater" do skip "not implemeted yet" end - it "lets add a new repeater element" do + it "allows to add a new repeater element" do # sign_in user # path = binda.edit_structure_component_path( @structure, @component ) # visit path @@ -163,7 +138,7 @@ skip "not implemented yet" end - it "lets reorder repeater elements" do + it "allows to reorder repeater elements" do # This is pretty difficult, probably not reliable either skip "not implemented yet" end