msfl 0.0.1.pre.rc2 → 0.0.1.pre.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/msfl/parsers/json.rb +3 -1
- data/lib/msfl/sinatra.rb +1 -1
- data/msfl.gemspec +1 -1
- data/spec/msfl/parsers/json_spec.rb +11 -0
- data/spec/msfl/shared_examples.rb +18 -0
- data/spec/msfl/sinatra/helpers_spec.rb +0 -7
- data/spec/msfl/validators/semantic_spec.rb +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6c56cf3880a84eafff98a45f46931bf957e2f09
|
4
|
+
data.tar.gz: 23afd30b810244488d9307059faad6ddfae6ba48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3ac65b1be870a46fa7495c3510fb78290b93b9ff28ec49fe5fdd5860bd1c8a51a625df4ec067e0f30da9a93f90b3a6ae7e11bef6ef0b1aededbf53015e23771
|
7
|
+
data.tar.gz: a2c081a4776ab4f93eddeca6c219c4238c3cb3f0e60c383ce560172fd1ba556a4590b7eaed030f05831ca7b45561034190be91bebabb6b358acd8749c3827471
|
data/lib/msfl/parsers/json.rb
CHANGED
@@ -8,7 +8,9 @@ module MSFL
|
|
8
8
|
# @param json [String] the string to parse
|
9
9
|
# @return [Object] the Ruby encoded MSFL, which may be a Hash, MSFL::Types::Set, or any number of scalar types
|
10
10
|
def self.parse(json)
|
11
|
-
|
11
|
+
json_to_parse = json
|
12
|
+
json_to_parse = '{}' if json_to_parse.nil? || json_to_parse == "" || json_to_parse == "null"
|
13
|
+
obj = ::JSON.parse(json_to_parse)
|
12
14
|
obj = arrays_to_sets obj
|
13
15
|
obj
|
14
16
|
end
|
data/lib/msfl/sinatra.rb
CHANGED
@@ -14,7 +14,7 @@ module MSFL
|
|
14
14
|
# @return [Object] the Ruby-ified MSFL filter
|
15
15
|
def parse_filter_from(params)
|
16
16
|
filter = params[:filter]
|
17
|
-
MSFL::Parsers::JSON.parse filter.to_json
|
17
|
+
MSFL::Parsers::JSON.parse filter.to_json
|
18
18
|
end
|
19
19
|
|
20
20
|
# Extracts the dataset name from the Sinatra params. It then returns a new instance of the specified
|
data/msfl.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'msfl'
|
3
|
-
s.version = '0.0.1-
|
3
|
+
s.version = '0.0.1-rc3'
|
4
4
|
s.date = '2015-03-05'
|
5
5
|
s.summary = "MSFL in Ruby"
|
6
6
|
s.description = "Serializers, validators, and other tasty goodness for the Mattermark Semantic Filter Language in Ruby."
|
@@ -9,6 +9,17 @@ describe "MSFL::Parsers::JSON" do
|
|
9
9
|
|
10
10
|
let(:test_json) { '{"total_funding": 5000000}' }
|
11
11
|
|
12
|
+
context "when parsing an empty json string" do
|
13
|
+
|
14
|
+
let(:test_json) { '' }
|
15
|
+
|
16
|
+
let(:expected) { MSFL::Parsers::JSON.parse '{}' }
|
17
|
+
|
18
|
+
it "is parsed as an empty json hash" do
|
19
|
+
expect(mut).to eq expected
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
12
23
|
context "when parsing a json hash" do
|
13
24
|
|
14
25
|
it "is an equivalent Ruby Hash" do
|
@@ -2,6 +2,24 @@ shared_examples_for "an invocation of MSFL::Sinatra.validate" do
|
|
2
2
|
|
3
3
|
let(:params) { { dataset: dataset, filter: filter } }
|
4
4
|
|
5
|
+
context "when params[:filter] is nil" do
|
6
|
+
|
7
|
+
let(:filter) { nil }
|
8
|
+
|
9
|
+
let(:dataset) { nil }
|
10
|
+
|
11
|
+
it { is_expected.to be true }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when params[:filter] is an empty hash" do
|
15
|
+
|
16
|
+
let(:filter) { {} }
|
17
|
+
|
18
|
+
let(:dataset) { nil }
|
19
|
+
|
20
|
+
it { is_expected.to be true }
|
21
|
+
end
|
22
|
+
|
5
23
|
context "when params[:dataset] is :movies" do
|
6
24
|
|
7
25
|
let(:dataset) { :movies }
|
@@ -69,13 +69,6 @@ describe "MSFL::Sinatra::Helpers" do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
context "when params[:filter] is nil" do
|
73
|
-
|
74
|
-
it "raises an ArgumentError" do
|
75
|
-
expect { mut }.to raise_error ArgumentError
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
72
|
context "when params[:dataset] is a valid Dataset" do
|
80
73
|
|
81
74
|
let(:dataset) { :cars }
|
@@ -40,6 +40,23 @@ describe "MSFL::Validators::Semantic" do
|
|
40
40
|
|
41
41
|
end
|
42
42
|
|
43
|
+
describe "#validate" do
|
44
|
+
|
45
|
+
subject(:mut) { test_instance.validate hash, errors, options }
|
46
|
+
|
47
|
+
let(:test_instance) { MSFL::Validators::Semantic.new }
|
48
|
+
|
49
|
+
let(:hash) { {} }
|
50
|
+
|
51
|
+
let(:errors) { [] }
|
52
|
+
|
53
|
+
let(:options) { {} }
|
54
|
+
|
55
|
+
context "when the filter is empty" do
|
56
|
+
it { is_expected.to be true }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
43
60
|
describe "#validate_set" do
|
44
61
|
|
45
62
|
subject(:mut) { test_instance.validate_set set, errors, options }
|