Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/values/user_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def with_only(*)
end

def without(*keys)
keys = keys.map(&:to_s)
params.reject! { |key| keys.include?(key) }
self
end

private
Expand Down
72 changes: 70 additions & 2 deletions spec/values/user_parameters_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
require "rails_helper"

RSpec.describe UserParameters do
# TODO: Add tests for UserParameters
def build_params(attrs)
ActionController::Parameters.new(user: attrs)
end

pending "add some tests for UserParameters"
describe "#without" do
it "removes the given keys and is chainable" do
params = build_params(display_name: "Jane", active: "false", type: "Volunteer")

result = described_class.new(params).without(:active, :type)

expect(result).to be_a(described_class)
expect(result.to_h).to eq("display_name" => "Jane")
end

it "removes keys even when the params only has string keys" do
params = build_params(display_name: "Jane", active: "false")

result = described_class.new(params).without(:active)

expect(result.to_h).to eq("display_name" => "Jane")
end

it "supports further chaining after without" do
params = build_params(display_name: "Jane", active: "false", password: "old")

result = described_class.new(params).without(:active).with_password("new-password")

expect(result.to_h).to eq("display_name" => "Jane", "password" => "new-password")
end
end

describe "#without_type" do
it "removes the type key" do
params = build_params(display_name: "Jane", type: "Volunteer")

result = described_class.new(params).without_type

expect(result.to_h).to eq("display_name" => "Jane")
end
end

describe "#without_active" do
it "removes the active key" do
params = build_params(display_name: "Jane", active: "false")

result = described_class.new(params).without_active

expect(result.to_h).to eq("display_name" => "Jane")
end
end

describe "#with_organization" do
it "sets casa_org_id" do
params = build_params(display_name: "Jane")
organization = create(:casa_org)

result = described_class.new(params).with_organization(organization)

expect(result.to_h).to eq("display_name" => "Jane", "casa_org_id" => organization.id)
end
end

describe "#with_password" do
it "sets password" do
params = build_params(display_name: "Jane")

result = described_class.new(params).with_password("secret123")

expect(result.to_h).to eq("display_name" => "Jane", "password" => "secret123")
end
end
end
Loading