render 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,128 +0,0 @@
1
- module Render
2
- describe Attribute do
3
- describe "#initialize" do
4
- describe "#name" do
5
- it "is set from options key" do
6
- options = { id: { type: UUID } }
7
- Attribute.new(options).name.should == :id
8
- end
9
- end
10
-
11
- describe "#type" do
12
- it "is set from options" do
13
- type = Integer
14
- attribute = Attribute.new({ type: type })
15
- attribute.type.should == type
16
- end
17
-
18
- it "is set from name hash" do
19
- type = String
20
- attribute = Attribute.new({ id: { type: UUID } })
21
- attribute.type.should == UUID
22
- end
23
-
24
- it "determines type from string" do
25
- Attribute.new({ type: "string" }).type.should == String
26
- end
27
- end
28
-
29
- describe "#schema" do
30
- it "is set to nil if its a regular attribute" do
31
- Attribute.new({ id: { type: UUID } }).schema.should == nil
32
- end
33
-
34
- it "is initiazed from options" do
35
- options = {
36
- film: {
37
- type: Object,
38
- attributes: {
39
- year: { type: Integer }
40
- }
41
- }
42
- }
43
-
44
- schema = Attribute.new(options).schema
45
- schema.title.should == :film
46
- schema.type.should == Object
47
- attributes = schema.attributes
48
- attributes.size.should == 1
49
- attribute = attributes.first
50
- attribute.name.should == :year
51
- attribute.type.should == Integer
52
- end
53
- end
54
-
55
- context "enums" do
56
- it "sets enum values" do
57
- enum_values = ["foo", "bar", "baz"]
58
- attribute = Attribute.new({ type: String, enum: enum_values })
59
- attribute.enums.should == enum_values
60
- end
61
- end
62
- end
63
-
64
- describe "#to_hash" do
65
- it "converts attributes to hashes" do
66
- attributes = { foo: { type: String } }
67
- attribute = Attribute.new(attributes)
68
- attribute.to_hash.should == { foo: nil }
69
- end
70
-
71
- it "converts attributes to hashes with values" do
72
- attributes = { foo: { type: String } }
73
- attribute = Attribute.new(attributes)
74
- attribute.to_hash("bar").should == { foo: "bar" }
75
- end
76
-
77
- it "converts schema values to hashes" do
78
- schema_name = "foo"
79
- attributes = {
80
- schema_name => {
81
- type: Object,
82
- attributes: {
83
- attribute: { type: String }
84
- }
85
- }
86
- }
87
-
88
- value = "baz"
89
- data = { attribute: value }
90
-
91
- attribute = Attribute.new(attributes)
92
- attribute.to_hash(data).should == { foo: { :attribute => value } }
93
- end
94
- end
95
-
96
- describe "#value" do
97
- context "offline mode" do
98
- before(:all) do
99
- @original_live = Render.live
100
- Render.live = false
101
- end
102
-
103
- after(:all) do
104
- Render.live = @original_live
105
- end
106
-
107
- it "generate value based on type" do
108
- supported_classes = [
109
- String,
110
- Integer
111
- ]
112
-
113
- supported_classes.each do |klass|
114
- Attribute.new({ type: klass }).default_value.should be_a(klass)
115
- end
116
- UUID.validate(Attribute.new({ type: UUID }).default_value).should be_true
117
- end
118
-
119
- it "generates value from enum" do
120
- enums = ["horror", "comedy", "drama"]
121
- attribute = Attribute.new({ genre: { enum: enums, type: String } })
122
- enums.should include(attribute.default_value)
123
- end
124
- end
125
- end
126
-
127
- end
128
- end