Sha256: 94ea8b892689f1c66fd54d20eea063a30b09e36b658a1daf7a9853bb4f68b159

Contents?: true

Size: 1.81 KB

Versions: 33

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Quby::Answers::Services
  describe FiltersAnswerValue do

    let(:questionnaire) do
      Quby::Questionnaires::DSL.build("test") do
        question :v_6, type: :radio do
          title "Testvraag"
          option :rad1
          option :rad2
        end

        question :v_7, type: :check_box do
          title "Checkbox vraag"
          option :v_7a1
          option :v_7a2
        end

        question :date, type: :date
      end
    end

    let(:attribute_filter) { FiltersAnswerValue.new questionnaire }

    let(:empty_hash) do
      {
        "aborted" => nil, "v_6" => nil, "v_7a1" => nil, "v_7a2" => nil,
        "date_dd" => nil, "date_mm" => nil, "date_yyyy" => nil
      }
    end

    describe '#update' do
      it 'sets answer value for the provided key to the provided value' do
        expect(attribute_filter.filter("v_6" => "value")).to eq(empty_hash.merge("v_6" => "value"))
      end

      it 'disallows setting attributes that are not questions' do
        expect(attribute_filter.filter("random_key" => "value")).to eq(empty_hash)
      end

      it 'passes through aborted' do
        expect(attribute_filter.filter("aborted" => "value")).to eq(empty_hash.merge("aborted" => "value"))
      end

      it 'allows checkbox options' do
        # expect(attribute_filter.filter("v_7" => "value")).to eq("v_7" => "value")
        expect(attribute_filter.filter("v_7a1" => "value")).to eq(empty_hash.merge("v_7a1" => "value"))
        expect(attribute_filter.filter("v_7a2" => "value")).to eq(empty_hash.merge("v_7a2" => "value"))
      end

      it 'does not mutate the original hash' do
        hash = {"foo" => "bar"}
        expect(attribute_filter.filter(hash)).to eq(empty_hash)
        expect(hash).to eq("foo" => "bar")
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
quby-5.6.5 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.6.3 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.6.2 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.6.1 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.6.0 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.5.0 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.4.0 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.3.1 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.3.0 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.2.0 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.1.3 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.1.2 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.1.1 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.1.0 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.0.5 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.0.4 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.0.3 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.0.2 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.0.1 spec/quby/answers/services/filters_answer_value_spec.rb
quby-5.0.0 spec/quby/answers/services/filters_answer_value_spec.rb