-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding in specs for params has_key_for? method. Fixes #503
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
require "./spec_helper" | ||
|
||
private class TestOperationWithDefaultParamKey < Avram::Operation | ||
attribute title : String | ||
|
||
def run | ||
end | ||
end | ||
|
||
private class TestOperationWithCustomParamKey < Avram::Operation | ||
param_key :test_op | ||
attribute title : String | ||
|
||
def run | ||
end | ||
end | ||
|
||
private class SaveUser < User::SaveOperation | ||
end | ||
|
||
private class NestedParams | ||
include Avram::Paramable | ||
|
||
@data : Hash(String, String) = {} of String => String | ||
|
||
def initialize(@data) | ||
end | ||
|
||
def nested?(key : String) : Hash(String, String) | ||
if @data.keys.map(&.split(':').first).includes?(key) | ||
@data | ||
else | ||
{} of String => String | ||
end | ||
end | ||
|
||
def nested(key : String) : Hash(String, String) | ||
nested?(key) | ||
end | ||
|
||
def get?(key) | ||
raise "Not implemented" | ||
end | ||
|
||
def get(key) | ||
raise "Not implemented" | ||
end | ||
|
||
def nested_file?(key) | ||
raise "Not implemented" | ||
end | ||
|
||
def nested_file(key) | ||
raise "Not implemented" | ||
end | ||
end | ||
|
||
describe Avram::Paramable do | ||
describe "#has_key_for?" do | ||
it "returns true for the Operation with the proper key" do | ||
params = NestedParams.new({"test_operation_with_default_param_key:title" => "Test"}) | ||
|
||
params.has_key_for?(TestOperationWithDefaultParamKey).should be_true | ||
end | ||
|
||
it "returns true for the Operation with a custom key" do | ||
params = NestedParams.new({"test_op:title" => "Test"}) | ||
|
||
params.has_key_for?(TestOperationWithCustomParamKey).should be_true | ||
end | ||
|
||
it "returns false for the Operation with the improper key" do | ||
params = NestedParams.new({"bad_key:title" => "Test"}) | ||
|
||
params.has_key_for?(TestOperationWithDefaultParamKey).should be_false | ||
end | ||
|
||
it "returns false for the Operation with no key" do | ||
params = NestedParams.new({"title" => "Test"}) | ||
|
||
params.has_key_for?(TestOperationWithDefaultParamKey).should be_false | ||
end | ||
|
||
it "returns true for the SaveOperation with the proper key" do | ||
params = NestedParams.new({"user:name" => "Test"}) | ||
|
||
params.has_key_for?(SaveUser).should be_true | ||
end | ||
|
||
it "returns false for the SaveOperation with the improper key" do | ||
params = NestedParams.new({"author:name" => "Test"}) | ||
|
||
params.has_key_for?(SaveUser).should be_false | ||
end | ||
end | ||
end |