From e2331f248f758516143262f37eda336c8307d773 Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Mon, 4 Jul 2022 12:18:30 +0100 Subject: [PATCH] tests for fieldable concern --- spec/concerns/fieldable_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/concerns/fieldable_spec.rb diff --git a/spec/concerns/fieldable_spec.rb b/spec/concerns/fieldable_spec.rb new file mode 100644 index 000000000..148dce4cc --- /dev/null +++ b/spec/concerns/fieldable_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "Dois", type: :controller do + subject { DataciteDoisController.new } + + it "no params" do + params = ActionController::Parameters.new + expect(subject.fields_from_params(params)).to be_nil + expect(subject.fields_hash_from_params(params)).to be_nil + end + + it "single value" do + params = ActionController::Parameters.new(fields: { dois: "id" }) + expect(subject.fields_from_params(params)).to eq({ dois: ["id"] }.with_indifferent_access) + expect(subject.fields_hash_from_params(params)).to eq({ dois: "id" }.with_indifferent_access) + end + + it "multiple values" do + params = ActionController::Parameters.new(fields: { dois: "id,subjects" }) + expect(subject.fields_from_params(params)).to eq({ dois: ["id", "subjects"] }.with_indifferent_access) + expect(subject.fields_hash_from_params(params)).to eq({ dois: "id,subjects" }.with_indifferent_access) + end +end