-
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 (#505)
* Adding in specs for params has_key_for? method. Fixes #503 * Adding in FakeParams for testing. This cleans up some specs using the fake params
- Loading branch information
Showing
3 changed files
with
100 additions
and
23 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
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,74 @@ | ||
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 < Avram::FakeParams | ||
@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 | ||
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 |
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,25 @@ | ||
abstract class Avram::FakeParams | ||
include Avram::Paramable | ||
|
||
abstract def nested?(key : String) : Hash(String, String) | ||
|
||
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 |