set_builder 2.0.0.beta1 → 2.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33054edba058a15627aaf11cbdd32f2a3bdb5c7e
4
- data.tar.gz: 2ab79d3204faa01c6acd43515f453d8c3a883990
3
+ metadata.gz: ae95d6f2f3cfb324b760144d8cab1e61fc4b41b5
4
+ data.tar.gz: a5f02d71b73862a3251ff48b167a07d3cf1a8b14
5
5
  SHA512:
6
- metadata.gz: f5af7ed922c28414483e4cf8c14704a94d527733a27ce8d07b95a3c687df7533594661c0d1099085d6326308602dd619dae2a143c09960aa69bdebdc41417b7e
7
- data.tar.gz: 47f857f3f679dec0cb5f0c701bd45a890a8cdd968d9eb8a544d76c8e866bc8ddfb9c2747c7437b7dba845dd17c32ebed93f9f0ff759b8e0324564f00d16e4b45
6
+ metadata.gz: f61aa92460102dd67880c0bc3d670f0c5ae5938ab0f83b2bf4f074597ececa1cf6933f9fcf15217d8e06d4913bd4b83192683fd5205d5b57c34aedacacca1932
7
+ data.tar.gz: 2803e8640beddb5fb8bbc880a2187af33da4534b98577df9dcde5ef29c7df432b45b886d1f654468d85adb925bb8f7ca5e483051275505ffa9dd385f49585e23
@@ -135,7 +135,7 @@ SetBuilder.Constraint = function(_trait, args) {
135
135
  case 'direct_object_type':
136
136
  return SetBuilder.getValue(text, _direct_object);
137
137
  case 'modifier':
138
- return _modifiers[i++].toString();
138
+ return _modifiers[i++].toString().replace('_', ' ');
139
139
  default:
140
140
  if(console && console.log) console.log('[SetBuilder.Constraint] unknown type: "' + type + '" (text: "' + text + '")');
141
141
  return false;
@@ -273,11 +273,14 @@ SetBuilder.Modifiers = function(_modifiers) {
273
273
 
274
274
  SetBuilder.Set = function(_raw_data) {
275
275
  if(!_raw_data) _raw_data = [];
276
+ if(_raw_data.constructor !== Array) _raw_data = convertObjectSetToArray(_raw_data);
276
277
 
277
278
  var _constraints = [];
279
+
278
280
  _raw_data.__each(function(line) {
279
281
  var trait_name = line[0];
280
282
  var negative = false;
283
+
281
284
  if(trait_name[0] == '!') {
282
285
  negative = true;
283
286
  trait_name = trait_name.slice(1);
@@ -290,8 +293,27 @@ SetBuilder.Set = function(_raw_data) {
290
293
  window.console.log('trait not found with name "' + line[0] + '"');
291
294
  }
292
295
  });
293
-
294
-
296
+
297
+ function convertObjectSetToArray(data) {
298
+ var set = [];
299
+
300
+ Object.keys(data).__each(function(key) {
301
+ var convertedTrait = [];
302
+ var trait = data[key];
303
+ convertedTrait.push(trait.negative ? "!" + trait.trait : trait.trait)
304
+ if(trait.direct_object) convertedTrait.push(trait.direct_object);
305
+ if(trait.modifiers) {
306
+ Object.keys(trait.modifiers).__each(function(key) {
307
+ var modifier = trait.modifiers[key];
308
+ var convertedModifier = {};
309
+ convertedModifier[modifier.operator] = modifier.values ? Object.values(modifier.values) : [];
310
+ convertedTrait.push(convertedModifier);
311
+ });
312
+ }
313
+ set.push(convertedTrait);
314
+ });
315
+ return set;
316
+ }
295
317
 
296
318
  // Public methods
297
319
 
@@ -309,6 +331,10 @@ SetBuilder.Set = function(_raw_data) {
309
331
  return this.constraints().toSentence();
310
332
  }
311
333
 
334
+ this.isEqualTo = function(other) {
335
+ return this.toString() == other.toString();
336
+ }
337
+
312
338
  };
313
339
 
314
340
 
@@ -430,6 +456,16 @@ if(!Object.keys) {
430
456
  }
431
457
  }
432
458
 
459
+ if(!Object.values) {
460
+ Object.values = function(o) {
461
+ var values = [];
462
+ Object.keys(o).__each(function(key) {
463
+ values.push(o[key]);
464
+ });
465
+ return values;
466
+ }
467
+ }
468
+
433
469
 
434
470
 
435
471
  //
@@ -8,31 +8,4 @@ require 'set_builder/engine'
8
8
 
9
9
 
10
10
  module SetBuilder
11
-
12
- def self.extended(base)
13
- base.instance_variable_set("@traits", SetBuilder::Traits.new)
14
- base.send(:include, SetBuilder::Modifiers)
15
- end
16
-
17
-
18
- attr_reader :traits
19
-
20
- def modifiers
21
- traits.modifiers
22
- end
23
-
24
- def that_belong_to(set)
25
- SetBuilder::Set.new(self, to_scope, set)
26
- end
27
-
28
- def to_scope
29
- scoped
30
- end
31
-
32
- protected
33
-
34
- def trait(trait_expression, &block)
35
- traits << Trait.new(trait_expression, &block)
36
- end
37
-
38
11
  end
@@ -1,71 +1,71 @@
1
1
  module SetBuilder
2
2
  class Set
3
-
4
-
5
-
6
- def initialize(model, scope, raw_data)
7
- @model = model
3
+
4
+
5
+
6
+ def initialize(traits, scope, raw_data)
7
+ @traits = traits
8
8
  @scope = scope
9
9
  @set = raw_data
10
10
  end
11
-
12
-
13
-
14
- attr_reader :model, :scope
15
-
16
-
17
-
11
+
12
+
13
+
14
+ attr_reader :traits, :scope
15
+
16
+
17
+
18
18
  def constraints
19
19
  @constraints ||= get_constraints
20
20
  end
21
-
22
-
23
-
21
+
22
+
23
+
24
24
  #
25
25
  # Returns true if all of the constraints in this set are valid
26
26
  #
27
27
  def valid?
28
28
  constraints.all?(&:valid?)
29
29
  end
30
-
31
-
32
-
30
+
31
+
32
+
33
33
  #
34
34
  # Describes this set in natural language
35
35
  #
36
36
  def to_s
37
37
  constraints.to_sentence
38
38
  end
39
-
40
-
41
-
39
+
40
+
41
+
42
42
  #
43
43
  # Returns an instance of ActiveRecord::NamedScope::Scope
44
44
  # which can fetch the objects which belong to this set
45
- #
45
+ #
46
46
  def perform
47
47
  constraints.inject(scope) { |scope, constraint| constraint.perform(scope) }
48
48
  end
49
-
50
-
51
-
49
+
50
+
51
+
52
52
  private
53
-
54
-
55
-
53
+
54
+
55
+
56
56
  attr_reader :set
57
-
57
+
58
58
  def get_constraints
59
59
  set.inject([]) do |constraints, line|
60
60
  negate, trait_name, args = false, line.first.to_s, line[1..-1]
61
61
  trait_name, negate = trait_name[1..-1], true if (trait_name[0..0] == "!")
62
- trait = model.traits[trait_name]
63
- raise("\"#{trait_name}\" is not a trait for #{model}") unless trait
62
+ trait = traits[trait_name]
63
+ raise("\"#{trait_name}\" is not a trait in `traits`") unless trait
64
64
  constraints << trait.apply(*args).negate(negate)
65
65
  end
66
66
  end
67
-
68
-
69
-
67
+
68
+
69
+
70
70
  end
71
71
  end
@@ -0,0 +1,14 @@
1
+ module SetBuilder
2
+ class TraitBuilder
3
+ attr_reader :traits
4
+
5
+ def initialize(traits)
6
+ @traits = traits
7
+ end
8
+
9
+ def trait(trait_expression, &block)
10
+ traits << Trait.new(trait_expression, &block)
11
+ end
12
+
13
+ end
14
+ end
@@ -1,12 +1,28 @@
1
1
  require 'set_builder/trait'
2
+ require 'set_builder/trait_builder'
2
3
  require 'set_builder/modifier_collection'
4
+ require 'delegate'
3
5
 
4
6
 
5
7
  module SetBuilder
6
- class Traits < Array
7
-
8
-
9
-
8
+ class Traits < SimpleDelegator
9
+
10
+
11
+
12
+ def initialize(array=[], &block)
13
+ super array
14
+
15
+ if block_given?
16
+ if block.arity.zero?
17
+ TraitBuilder.new(self).instance_eval(&block)
18
+ else
19
+ yield TraitBuilder.new(self)
20
+ end
21
+ end
22
+ end
23
+
24
+
25
+
10
26
  def [](index)
11
27
  case index
12
28
  when Symbol, String
@@ -16,15 +32,27 @@ module SetBuilder
16
32
  super
17
33
  end
18
34
  end
19
-
20
-
21
-
35
+
36
+
37
+
22
38
  def to_json
23
39
  "[#{collect(&:to_json).join(",")}]"
24
40
  end
25
-
26
-
27
-
41
+
42
+
43
+
44
+ def +(other_traits)
45
+ return super unless other_traits.is_a?(self.class)
46
+ self.class.new(self.__getobj__ + other_traits.__getobj__)
47
+ end
48
+
49
+ def concat(other_traits)
50
+ return super unless other_traits.is_a?(self.class)
51
+ self.class.new(self.__getobj__.concat other_traits.__getobj__)
52
+ end
53
+
54
+
55
+
28
56
  def modifiers
29
57
  # !nb: not sure why inject was failing but it was modifying trait.modifiers!
30
58
  @modifiers = ModifierCollection.new
@@ -35,8 +63,8 @@ module SetBuilder
35
63
  end
36
64
  @modifiers
37
65
  end
38
-
39
-
40
-
66
+
67
+
68
+
41
69
  end
42
- end
70
+ end
@@ -26,7 +26,7 @@ module SetBuilder
26
26
  end
27
27
 
28
28
  name = name.to_sym
29
- map = @registered_value_maps[name]
29
+ map = @registered_value_maps[name]
30
30
  if map
31
31
  pair = map.find { |pair| pair[0] == value || pair[0] == value.to_s }
32
32
  pair ? pair[1].to_s : "(unknown)"
@@ -59,6 +59,10 @@ module SetBuilder
59
59
 
60
60
 
61
61
 
62
+ def self.as_json(options={})
63
+ @registered_value_maps.dup
64
+ end
65
+
62
66
  def self.to_json
63
67
  @registered_value_maps.to_json
64
68
  end
@@ -1,3 +1,3 @@
1
1
  module SetBuilder
2
- VERSION = "2.0.0.beta1"
2
+ VERSION = "2.0.0.beta2"
3
3
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "jspec"
26
26
  spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "minitest-reporters"
27
28
  end
@@ -40,6 +40,30 @@ describe 'SetBuilder'
40
40
  ['died'],
41
41
  ['name', {'is': "Jerome"}]
42
42
  ];
43
+
44
+ set_data_hash = {
45
+ '0': {
46
+ trait: 'awesome'
47
+ },
48
+ '1': {
49
+ trait: 'attended',
50
+ direct_object: 2
51
+ },
52
+ '2': {
53
+ trait: 'died'
54
+ },
55
+ '3': {
56
+ trait: 'name',
57
+ modifiers: {
58
+ '0': {
59
+ operator: 'is',
60
+ values: {
61
+ '0': 'Jerome'
62
+ }
63
+ }
64
+ }
65
+ }
66
+ };
43
67
  end
44
68
 
45
69
 
@@ -145,6 +169,18 @@ describe 'SetBuilder'
145
169
  var set = new SetBuilder.Set(set_data);
146
170
  expect(set.constraints().length).to(be, 4);
147
171
  end
172
+
173
+ it 'should parse hash-style objects as well as arrays'
174
+ var set = new SetBuilder.Set(set_data_hash);
175
+ expect(set.constraints().length).to(be, 4);
176
+ end
177
+
178
+ it 'should consider two sets with identical constraints equal'
179
+ var set1 = new SetBuilder.Set(set_data);
180
+ var set2 = new SetBuilder.Set(set_data_hash);
181
+ expect(set1.isEqualTo(set2)).to(be, true);
182
+ expect(set2.isEqualTo(set1)).to(be, true);
183
+ end
148
184
  end
149
185
 
150
186
  describe '.toString'
@@ -7,7 +7,7 @@ class ModifierTest < ActiveSupport::TestCase
7
7
  test "get type with string" do
8
8
  assert_equal StringPreposition, SetBuilder::Modifier["StringPreposition"]
9
9
  end
10
-
10
+
11
11
  test "get type with symbol" do
12
12
  assert_equal StringPreposition, SetBuilder::Modifier[:string]
13
13
  end
@@ -21,13 +21,13 @@ class ModifierTest < ActiveSupport::TestCase
21
21
  SetBuilder::Modifier.for(:hash)
22
22
  end
23
23
  end
24
-
24
+
25
25
  test "registering an invalid modifier" do
26
26
  assert_raises ArgumentError do
27
27
  SetBuilder::Modifier.register(:hash, InvalidHashModifier)
28
28
  end
29
29
  end
30
-
30
+
31
31
  test "converting modifier to json" do
32
32
  expected_results = {
33
33
  "contains" => ["string"],
@@ -71,7 +71,7 @@ class ModifierTest < ActiveSupport::TestCase
71
71
  "is_not" => ["string"]
72
72
  }
73
73
  }
74
- assert_equal expected_results, Friend.modifiers.to_hash
74
+ assert_equal expected_results, $friend_traits.modifiers.to_hash
75
75
  end
76
76
 
77
77
 
@@ -82,9 +82,9 @@ class InvalidHashModifier
82
82
  end
83
83
 
84
84
  class HashModifier < SetBuilder::Modifier::Verb
85
-
85
+
86
86
  def self.operators
87
87
  [:has_key]
88
88
  end
89
-
89
+
90
90
  end
@@ -1,75 +1,66 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class SetTest < ActiveSupport::TestCase
4
-
5
-
6
-
4
+
5
+
6
+
7
7
  test "set data struture" do
8
- data = [
8
+ set = to_set [
9
9
  [:awesome],
10
10
  [:attended, 2],
11
11
  [:died],
12
12
  [:name, {:is => "Jerome"}]]
13
- set = Friend.that_belong_to(data)
14
13
  assert set.valid?
15
14
  assert_equal "who are awesome, who have attended McKendree, who died, and whose name is Jerome", set.to_s
16
15
  end
17
16
 
18
17
  test "sets with invalid modifiers should be invalid" do
19
- data = [[:born, {:after => ["wrong"]}]]
20
- set = Friend.that_belong_to(data)
18
+ set = to_set [[:born, {:after => ["wrong"]}]]
21
19
  assert_equal false, set.valid?
22
20
  end
23
21
 
24
22
  test "sets should not allow non-numbers in a number modifiers" do
25
- data = [[:age, {:is => ["12a"]}]]
26
- set = Friend.that_belong_to(data)
23
+ set = to_set [[:age, {:is => ["12a"]}]]
27
24
  refute set.valid?
28
25
  end
29
26
 
30
27
  test "sets should not allow empty string in a number modifiers" do
31
- data = [[:age, {:is => [""]}]]
32
- set = Friend.that_belong_to(data)
28
+ set = to_set [[:age, {:is => [""]}]]
33
29
  refute set.valid?
34
30
  end
35
-
31
+
36
32
  test "sets lacking expected modifiers should be invalid" do
37
- data = [[:born, {:ever => []}]]
38
- set = Friend.that_belong_to(data)
33
+ set = to_set [[:born, {:ever => []}]]
39
34
  assert_equal true, set.valid?
40
-
41
- data = [[:born]]
42
- set = Friend.that_belong_to(data)
35
+
36
+ set = to_set [[:born]]
43
37
  assert_equal false, set.valid?
44
- end
45
-
38
+ end
39
+
46
40
  test "set structure with negations (nouns are ignored)" do
47
- data = [
41
+ set = to_set [
48
42
  ["!awesome"],
49
43
  ["!attended", 2],
50
44
  ["!died"],
51
45
  ["!name", {:is => "Jerome"}]]
52
- set = Friend.that_belong_to(data)
53
46
  assert set.valid?
54
47
  assert_equal "who are not awesome, who have not attended McKendree, who have not died, and whose name is Jerome", set.to_s
55
48
  end
56
-
49
+
57
50
  test "simple perform" do
58
- data = [[:awesome]]
59
- set = Friend.that_belong_to(data)
60
-
51
+ set = to_set [[:awesome]]
52
+
61
53
  expected_results = [{:conditions => {:awesome => true}}]
62
54
  assert_equal expected_results, set.perform
63
55
  end
64
-
56
+
65
57
  test "complex perform" do
66
- data = [
58
+ set = to_set [
67
59
  [:awesome],
68
60
  [:attended, 1],
69
61
  [:died],
70
62
  [:name, {:begins_with => "Jerome"}]]
71
- set = Friend.that_belong_to(data)
72
-
63
+
73
64
  expected_results = [
74
65
  {:conditions => {:awesome => true}},
75
66
  {:joins => "INNER JOIN schools ON friends.school_id=schools.id", :conditions => {"schools.id" => 1}},
@@ -78,13 +69,19 @@ class SetTest < ActiveSupport::TestCase
78
69
  ]
79
70
  assert_equal expected_results, set.perform
80
71
  end
81
-
72
+
82
73
  test "invalid set" do
83
- data = [[:name, {:starts_with => "Jerome"}]] # starts_with is not a valid operator
84
- set = Friend.that_belong_to(data)
85
-
74
+ set = to_set [[:name, {:starts_with => "Jerome"}]] # starts_with is not a valid operator
75
+
86
76
  # !todo: what to do?
77
+ skip "TODO: test invalid sets"
87
78
  end
88
79
 
89
80
 
81
+ private
82
+
83
+ def to_set(data)
84
+ SetBuilder::Set.new($friend_traits, Friend.all, data)
85
+ end
86
+
90
87
  end
@@ -6,14 +6,14 @@ require "set_builder"
6
6
  require "pry"
7
7
  require "support/fake_connection"
8
8
 
9
-
9
+ require "minitest/reporters"
10
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
10
11
 
11
12
  # Sample class used by tests
12
13
 
13
14
  SetBuilder::ValueMap.register(:school, [[1, "Concordia"], [2, "McKendree"]])
14
15
 
15
- class Friend
16
- extend SetBuilder
16
+ $friend_traits = SetBuilder::Traits.new do
17
17
 
18
18
  trait('who are [not] "awesome"') do |query, scope|
19
19
  scope << {:conditions => {:awesome => true}}
@@ -41,28 +41,29 @@ class Friend
41
41
  trait('whose "name" <string>') do |query, scope|
42
42
  scope << {:conditions => query.modifiers[0].build_conditions_for("friends.name")}
43
43
  end
44
-
45
- # by stubbing out scoped, we can unit test the `performed` features
46
- def self.to_scope
44
+ end
45
+
46
+
47
+ class Friend
48
+
49
+ # by stubbing out `all`, we can unit test `Set#perform`
50
+ def self.all
47
51
  []
48
52
  end
49
-
50
-
51
-
53
+
54
+
52
55
  # Stubs so that Arel can SQL
53
-
56
+
54
57
  attr_accessor :connection_pool
55
-
58
+
56
59
  def initialize
57
60
  @connection_pool = Fake::ConnectionPool.new
58
61
  end
59
-
62
+
60
63
  def connection
61
64
  connection_pool.connection
62
65
  end
63
-
64
-
65
-
66
+
66
67
  end
67
68
 
68
69
  Arel::Table.engine = Arel::Sql::Engine.new(Friend.new)
@@ -5,16 +5,16 @@ class TraitTest < ActiveSupport::TestCase
5
5
 
6
6
 
7
7
  test "constraints find correct modifiers" do
8
- trait = Friend.traits[:name]
8
+ trait = $friend_traits[:name]
9
9
  assert_equal 1, trait.modifiers.length
10
10
 
11
11
  constraint = trait.apply({:is => "Jerome"})
12
12
  assert_equal 1, constraint.modifiers.length
13
13
  assert_kind_of StringPreposition, constraint.modifiers.first
14
14
  end
15
-
15
+
16
16
  test "modifiers should find correct values" do
17
- trait = Friend.traits[:name]
17
+ trait = $friend_traits[:name]
18
18
  modifier = trait.apply({:is => "Jerome"}).modifiers.first
19
19
  assert_equal :is, modifier.operator
20
20
  assert_equal ["Jerome"], modifier.values
@@ -29,18 +29,12 @@ class TraitTest < ActiveSupport::TestCase
29
29
  :name => false
30
30
  }
31
31
  trait_requires_direct_object.each do |trait, expected_value|
32
- assert_equal expected_value, Friend.traits[trait].requires_direct_object?
32
+ assert_equal expected_value, $friend_traits[trait].requires_direct_object?
33
33
  end
34
34
  end
35
35
 
36
- # test "traits whose direct objects support value mapping should be able to enumerate their values" do
37
- # trait = Friend.traits[:attended]
38
- # expected_map = {1 => "Concordia", 2 => "McKendree"}
39
- # actual_map = trait.
40
- # end
41
-
42
36
  test "constraint should be valid" do
43
- trait = Friend.traits[:name]
37
+ trait = $friend_traits[:name]
44
38
  constraint = trait.apply({:is => "Jerome"})
45
39
  assert constraint.valid?
46
40
  end
@@ -6,27 +6,55 @@ class TraitsTest < ActiveSupport::TestCase
6
6
 
7
7
  test "traits" do
8
8
  expected_traits = %w{age attended awesome born died name}
9
- assert_equal expected_traits, Friend.traits.collect(&:name).sort
9
+ assert_equal expected_traits, $friend_traits.collect(&:name).sort
10
10
  end
11
-
11
+
12
12
  test "traits' accessor" do
13
- traits = Friend.traits
13
+ traits = $friend_traits
14
14
  assert_kind_of SetBuilder::Traits, traits
15
15
  assert_equal "awesome", traits[0].name, "Array getter should still work like normal"
16
16
  assert_kind_of SetBuilder::Trait, traits[:born], "If you pass a string or symbol Traits should lookup a trait by name"
17
17
  end
18
-
18
+
19
19
  test "trait method is protected" do
20
20
  assert_raises NoMethodError, "this method is for use within class definition" do
21
21
  Friend.trait
22
22
  end
23
23
  end
24
-
24
+
25
25
  test "collection of modifiers" do
26
26
  expected_modifiers = %w{DatePreposition NumberPreposition StringPreposition}.collect {|name| "SetBuilder::Modifiers::#{name}"}
27
- assert_equal expected_modifiers, Friend.traits.modifiers.collect(&:name).sort
27
+ assert_equal expected_modifiers, $friend_traits.modifiers.collect(&:name).sort
28
+ end
29
+
30
+ test "two collections of traits can be concatenated with `+`" do
31
+ traits1 = SetBuilder::Traits.new do
32
+ trait('who are [not] "awesome"') { |query, scope| }
33
+ end
34
+
35
+ traits2 = SetBuilder::Traits.new do
36
+ trait('who are [not] "living"') { |query, scope| }
37
+ end
38
+
39
+ combined_traits = traits1 + traits2
40
+ assert_kind_of SetBuilder::Traits, combined_traits
41
+ assert_equal %w{awesome living}, combined_traits.map(&:name)
42
+ end
43
+
44
+ test "two collections of traits can be concatenated with `concat`" do
45
+ traits1 = SetBuilder::Traits.new do
46
+ trait('who are [not] "awesome"') { |query, scope| }
47
+ end
48
+
49
+ traits2 = SetBuilder::Traits.new do
50
+ trait('who are [not] "living"') { |query, scope| }
51
+ end
52
+
53
+ combined_traits = traits1.concat traits2
54
+ assert_kind_of SetBuilder::Traits, combined_traits
55
+ assert_equal %w{awesome living}, combined_traits.map(&:name)
28
56
  end
29
-
57
+
30
58
  test "to_json" do
31
59
  expected_json = [[["string","who are"],
32
60
  ["negative","not"],
@@ -47,7 +75,7 @@ class TraitsTest < ActiveSupport::TestCase
47
75
  [["string","whose"],
48
76
  ["name","name"],
49
77
  ["modifier","string"]]].to_json
50
- assert_equal expected_json, Friend.traits.to_json
78
+ assert_equal expected_json, $friend_traits.to_json
51
79
  end
52
80
 
53
81
 
@@ -7,20 +7,20 @@ class ValueMapTest < ActiveSupport::TestCase
7
7
  expected_map = [[1, "Concordia"], [2, "McKendree"]]
8
8
  assert_equal expected_map, SetBuilder::ValueMap.for(:school)
9
9
  end
10
-
11
-
12
- test "value map should fetch the correct value" do
10
+
11
+
12
+ test "value map should fetch the correct value" do
13
13
  expected_school = "Concordia"
14
14
  assert_equal expected_school, SetBuilder::ValueMap.to_s(:school, 1)
15
15
  end
16
16
 
17
17
 
18
- test "value map should fetch the correct value when passed as a string" do
18
+ test "value map should fetch the correct value when passed as a string" do
19
19
  expected_school = "Concordia"
20
20
  assert_equal expected_school, SetBuilder::ValueMap.to_s("school", 1)
21
21
  end
22
-
23
-
22
+
23
+
24
24
  test "value map should generate json that can be handed to the client-side SetBuilder" do
25
25
  expected_json = "{\"school\":[[1,\"Concordia\"],[2,\"McKendree\"]]}"
26
26
  assert_equal expected_json, SetBuilder::ValueMap.to_json
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: set_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta1
4
+ version: 2.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: minitest-reporters
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
103
117
  description: A gem for describing constraints on data sets
104
118
  email:
105
119
  - bob.lailfamily@gmail.com
@@ -131,6 +145,7 @@ files:
131
145
  - lib/set_builder/query_builders/string.rb
132
146
  - lib/set_builder/set.rb
133
147
  - lib/set_builder/trait.rb
148
+ - lib/set_builder/trait_builder.rb
134
149
  - lib/set_builder/traits.rb
135
150
  - lib/set_builder/value_map.rb
136
151
  - lib/set_builder/version.rb