moon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +11 -0
  3. data/Rakefile +48 -0
  4. data/lib/moon.rb +15 -0
  5. data/lib/moon/action.rb +12 -0
  6. data/lib/moon/action/base.rb +16 -0
  7. data/lib/moon/action/model.rb +10 -0
  8. data/lib/moon/action/model/create.rb +45 -0
  9. data/lib/moon/action/model/destroy.rb +42 -0
  10. data/lib/moon/action/model/index.rb +31 -0
  11. data/lib/moon/action/model/show.rb +32 -0
  12. data/lib/moon/action/model/update.rb +42 -0
  13. data/lib/moon/action/models.rb +8 -0
  14. data/lib/moon/action/models/finder.rb +43 -0
  15. data/lib/moon/action/models/initializer.rb +51 -0
  16. data/lib/moon/action/models/updater.rb +36 -0
  17. data/lib/moon/action/rebuild_arrays.rb +40 -0
  18. data/lib/moon/action/reference_object.rb +35 -0
  19. data/lib/moon/action/valid_models_required.rb +21 -0
  20. data/lib/moon/application.rb +33 -0
  21. data/lib/moon/application/rack.rb +104 -0
  22. data/lib/moon/application/routes.rb +16 -0
  23. data/lib/moon/context.rb +25 -0
  24. data/lib/moon/formatter.rb +22 -0
  25. data/lib/moon/formatter/base.rb +15 -0
  26. data/lib/moon/formatter/generic.rb +29 -0
  27. data/lib/moon/response.rb +7 -0
  28. data/lib/moon/response/base.rb +18 -0
  29. data/lib/moon/response/json.rb +26 -0
  30. data/lib/moon/response/json/collection.rb +12 -0
  31. data/lib/moon/response/json/message.rb +18 -0
  32. data/lib/moon/response/json/model.rb +16 -0
  33. data/lib/moon/response/json/validation_errors.rb +9 -0
  34. data/lib/moon/utility.rb +7 -0
  35. data/lib/moon/utility/string.rb +17 -0
  36. data/lib/moon/utility/template.rb +23 -0
  37. data/lib/moon/validator.rb +71 -0
  38. data/lib/moon/validator/format.rb +32 -0
  39. data/lib/moon/validator/length.rb +42 -0
  40. data/lib/moon/validator/presence.rb +29 -0
  41. data/spec/lib/moon/action/base_spec.rb +29 -0
  42. data/spec/lib/moon/action/model/create_spec.rb +111 -0
  43. data/spec/lib/moon/action/model/destroy_spec.rb +84 -0
  44. data/spec/lib/moon/action/model/index_spec.rb +51 -0
  45. data/spec/lib/moon/action/model/show_spec.rb +51 -0
  46. data/spec/lib/moon/action/model/update_spec.rb +91 -0
  47. data/spec/lib/moon/action/models/finder_spec.rb +36 -0
  48. data/spec/lib/moon/action/models/initializer_spec.rb +43 -0
  49. data/spec/lib/moon/action/models/updater_spec.rb +36 -0
  50. data/spec/lib/moon/action/rebuild_arrays_spec.rb +28 -0
  51. data/spec/lib/moon/action/reference_object_spec.rb +32 -0
  52. data/spec/lib/moon/action/valid_models_required_spec.rb +64 -0
  53. data/spec/lib/moon/application/rack_spec.rb +73 -0
  54. data/spec/lib/moon/application/routes_spec.rb +26 -0
  55. data/spec/lib/moon/context_spec.rb +28 -0
  56. data/spec/lib/moon/formatter/base_spec.rb +30 -0
  57. data/spec/lib/moon/formatter/generic_spec.rb +34 -0
  58. data/spec/lib/moon/formatter_spec.rb +36 -0
  59. data/spec/lib/moon/response/base_spec.rb +33 -0
  60. data/spec/lib/moon/response/json/collection_spec.rb +30 -0
  61. data/spec/lib/moon/response/json/message_spec.rb +30 -0
  62. data/spec/lib/moon/response/json/model_spec.rb +31 -0
  63. data/spec/lib/moon/response/json/validation_errors_spec.rb +21 -0
  64. data/spec/lib/moon/response/json_spec.rb +33 -0
  65. data/spec/lib/moon/utility/string_spec.rb +29 -0
  66. data/spec/lib/moon/utility/template_spec.rb +49 -0
  67. data/spec/lib/moon/validator/format_spec.rb +40 -0
  68. data/spec/lib/moon/validator/length_spec.rb +60 -0
  69. data/spec/lib/moon/validator/presence_spec.rb +45 -0
  70. data/spec/lib/moon/validator_spec.rb +83 -0
  71. data/spec/spec_helper.rb +4 -0
  72. metadata +209 -0
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
2
+
3
+ describe Moon::Validator::Length do
4
+
5
+ before :each do
6
+ described_class.minimum = 2
7
+ described_class.maximum = 3
8
+ @validator = described_class.new [ "one", "two" ]
9
+ end
10
+
11
+ describe "#ok?" do
12
+
13
+ it "should return true" do
14
+ ok = @validator.ok?
15
+ ok.should be_true
16
+ end
17
+
18
+ it "should raise #{ArgumentError} if value doesn't respond to :size" do
19
+ @validator.value = false
20
+ lambda do
21
+ @validator.ok?
22
+ end.should raise_error(ArgumentError)
23
+ end
24
+
25
+ it "should return false if value size is too small" do
26
+ @validator.value = [ "one" ]
27
+ ok = @validator.ok?
28
+ ok.should be_false
29
+ end
30
+
31
+ it "should return false if value size is too big" do
32
+ @validator.value = [ "one", "two", "three", "four" ]
33
+ ok = @validator.ok?
34
+ ok.should be_false
35
+ end
36
+
37
+ end
38
+
39
+ describe "#message" do
40
+
41
+ it "should return nil" do
42
+ message = @validator.message
43
+ message.should be_nil
44
+ end
45
+
46
+ it "should return an error message if value size is too small" do
47
+ @validator.value = [ "one" ]
48
+ message = @validator.message
49
+ message.should == "Must have at least 2 entries."
50
+ end
51
+
52
+ it "should return an error message if value size is too big" do
53
+ @validator.value = [ "one", "two", "three", "four" ]
54
+ message = @validator.message
55
+ message.should == "Must have at most 3 entries."
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
2
+
3
+ describe Moon::Validator::Presence do
4
+
5
+ before :each do
6
+ @validator = described_class.new "value"
7
+ end
8
+
9
+ describe "#ok?" do
10
+
11
+ it "should return true" do
12
+ ok = @validator.ok?
13
+ ok.should be_true
14
+ end
15
+
16
+ it "should return false if value is nil" do
17
+ @validator.value = nil
18
+ ok = @validator.ok?
19
+ ok.should be_false
20
+ end
21
+
22
+ it "should return false if value is blank" do
23
+ @validator.value = ""
24
+ ok = @validator.ok?
25
+ ok.should be_false
26
+ end
27
+
28
+ end
29
+
30
+ describe "#message" do
31
+
32
+ it "should return an empty array" do
33
+ message = @validator.message
34
+ message.should be_nil
35
+ end
36
+
37
+ it "should return an error message if value if blank" do
38
+ @validator.value = ""
39
+ message = @validator.message
40
+ message.should == "Must be present."
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,83 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
2
+
3
+ describe Moon::Validator do
4
+
5
+ before :each do
6
+ @model = mock Object, :name => "test"
7
+
8
+ @attribute_validator = mock Moon::Validator::Presence, :ok? => true, :message => "Error!"
9
+ @attribute_validator_class = mock Class, :new => @attribute_validator
10
+
11
+ @checks = { :name => [ @attribute_validator_class ] }
12
+
13
+ described_class.checks = @checks
14
+ @validator = described_class.new @model
15
+ end
16
+
17
+ describe "ok?" do
18
+
19
+ it "should initialize the attribute validator" do
20
+ @attribute_validator_class.should_receive(:new).with("test").and_return(@attribute_validator)
21
+ @validator.ok?
22
+ end
23
+
24
+ it "should check the attribute validator" do
25
+ @attribute_validator.should_receive(:ok?).and_return(true)
26
+ @validator.ok?
27
+ end
28
+
29
+ it "should return true" do
30
+ @validator.should be_ok
31
+ end
32
+
33
+ it "should return true if no checks applied" do
34
+ described_class.checks = nil
35
+ @validator.should be_ok
36
+ end
37
+
38
+ it "should return false if the attribute validator fails" do
39
+ @attribute_validator.stub :ok? => false
40
+ @validator.should_not be_ok
41
+ end
42
+
43
+ end
44
+
45
+ describe "messages" do
46
+
47
+ it "should return an empty hash" do
48
+ messages = @validator.messages
49
+ messages.should == { }
50
+ end
51
+
52
+ it "should return an array including the fitting error message" do
53
+ @attribute_validator.stub :ok? => false
54
+ messages = @validator.messages
55
+ messages[:name].should == [ "Error!" ]
56
+ end
57
+
58
+ end
59
+
60
+ describe "#self.[]" do
61
+
62
+ before :each do
63
+ described_class.configuration = { Object => @checks }
64
+ end
65
+
66
+ it "should return a class" do
67
+ result = described_class[Object]
68
+ result.should be_instance_of(Class)
69
+ end
70
+
71
+ it "should return a class that is different from the original" do
72
+ result = described_class[Object]
73
+ result.should_not == described_class
74
+ end
75
+
76
+ it "should return a class that is assigned to the right checks" do
77
+ result = described_class[Object]
78
+ result.checks.should == @checks
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "moon"))
2
+ require 'rack/test'
3
+
4
+ ENV["RACK_ENV"] = "test"
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moon
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - "Philipp Br\xC3\xBCll"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-09 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: sinatra
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.0.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: configure
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.3.0
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: gom
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.3.1
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "2"
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: reek
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "1.2"
69
+ type: :development
70
+ version_requirements: *id005
71
+ description: A simple rack application library - first alpha release.
72
+ email: b.phifty@gmail.com
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files:
78
+ - README.rdoc
79
+ files:
80
+ - README.rdoc
81
+ - LICENSE
82
+ - Rakefile
83
+ - lib/moon/application/rack.rb
84
+ - lib/moon/application/routes.rb
85
+ - lib/moon/context.rb
86
+ - lib/moon/action/base.rb
87
+ - lib/moon/action/models/initializer.rb
88
+ - lib/moon/action/models/finder.rb
89
+ - lib/moon/action/models/updater.rb
90
+ - lib/moon/action/rebuild_arrays.rb
91
+ - lib/moon/action/model.rb
92
+ - lib/moon/action/valid_models_required.rb
93
+ - lib/moon/action/models.rb
94
+ - lib/moon/action/reference_object.rb
95
+ - lib/moon/action/model/create.rb
96
+ - lib/moon/action/model/show.rb
97
+ - lib/moon/action/model/destroy.rb
98
+ - lib/moon/action/model/update.rb
99
+ - lib/moon/action/model/index.rb
100
+ - lib/moon/response/base.rb
101
+ - lib/moon/response/json/message.rb
102
+ - lib/moon/response/json/validation_errors.rb
103
+ - lib/moon/response/json/model.rb
104
+ - lib/moon/response/json/collection.rb
105
+ - lib/moon/response/json.rb
106
+ - lib/moon/utility.rb
107
+ - lib/moon/utility/string.rb
108
+ - lib/moon/utility/template.rb
109
+ - lib/moon/formatter.rb
110
+ - lib/moon/validator/format.rb
111
+ - lib/moon/validator/presence.rb
112
+ - lib/moon/validator/length.rb
113
+ - lib/moon/validator.rb
114
+ - lib/moon/response.rb
115
+ - lib/moon/action.rb
116
+ - lib/moon/formatter/base.rb
117
+ - lib/moon/formatter/generic.rb
118
+ - lib/moon/application.rb
119
+ - lib/moon.rb
120
+ - spec/lib/moon/context_spec.rb
121
+ - spec/lib/moon/application/routes_spec.rb
122
+ - spec/lib/moon/application/rack_spec.rb
123
+ - spec/lib/moon/action/models/initializer_spec.rb
124
+ - spec/lib/moon/action/models/updater_spec.rb
125
+ - spec/lib/moon/action/models/finder_spec.rb
126
+ - spec/lib/moon/action/reference_object_spec.rb
127
+ - spec/lib/moon/action/base_spec.rb
128
+ - spec/lib/moon/action/valid_models_required_spec.rb
129
+ - spec/lib/moon/action/rebuild_arrays_spec.rb
130
+ - spec/lib/moon/action/model/index_spec.rb
131
+ - spec/lib/moon/action/model/show_spec.rb
132
+ - spec/lib/moon/action/model/create_spec.rb
133
+ - spec/lib/moon/action/model/update_spec.rb
134
+ - spec/lib/moon/action/model/destroy_spec.rb
135
+ - spec/lib/moon/response/json/validation_errors_spec.rb
136
+ - spec/lib/moon/response/json/collection_spec.rb
137
+ - spec/lib/moon/response/json/model_spec.rb
138
+ - spec/lib/moon/response/json/message_spec.rb
139
+ - spec/lib/moon/response/base_spec.rb
140
+ - spec/lib/moon/response/json_spec.rb
141
+ - spec/lib/moon/utility/string_spec.rb
142
+ - spec/lib/moon/utility/template_spec.rb
143
+ - spec/lib/moon/validator/format_spec.rb
144
+ - spec/lib/moon/validator/presence_spec.rb
145
+ - spec/lib/moon/validator/length_spec.rb
146
+ - spec/lib/moon/validator_spec.rb
147
+ - spec/lib/moon/formatter_spec.rb
148
+ - spec/lib/moon/formatter/generic_spec.rb
149
+ - spec/lib/moon/formatter/base_spec.rb
150
+ - spec/spec_helper.rb
151
+ has_rdoc: true
152
+ homepage: http://github.com/phifty/moon
153
+ licenses: []
154
+
155
+ post_install_message:
156
+ rdoc_options: []
157
+
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: "0"
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: "0"
172
+ requirements: []
173
+
174
+ rubyforge_project: moon
175
+ rubygems_version: 1.6.1
176
+ signing_key:
177
+ specification_version: 3
178
+ summary: Moon - A rack application library.
179
+ test_files:
180
+ - spec/lib/moon/context_spec.rb
181
+ - spec/lib/moon/application/routes_spec.rb
182
+ - spec/lib/moon/application/rack_spec.rb
183
+ - spec/lib/moon/action/models/initializer_spec.rb
184
+ - spec/lib/moon/action/models/updater_spec.rb
185
+ - spec/lib/moon/action/models/finder_spec.rb
186
+ - spec/lib/moon/action/reference_object_spec.rb
187
+ - spec/lib/moon/action/base_spec.rb
188
+ - spec/lib/moon/action/valid_models_required_spec.rb
189
+ - spec/lib/moon/action/rebuild_arrays_spec.rb
190
+ - spec/lib/moon/action/model/index_spec.rb
191
+ - spec/lib/moon/action/model/show_spec.rb
192
+ - spec/lib/moon/action/model/create_spec.rb
193
+ - spec/lib/moon/action/model/update_spec.rb
194
+ - spec/lib/moon/action/model/destroy_spec.rb
195
+ - spec/lib/moon/response/json/validation_errors_spec.rb
196
+ - spec/lib/moon/response/json/collection_spec.rb
197
+ - spec/lib/moon/response/json/model_spec.rb
198
+ - spec/lib/moon/response/json/message_spec.rb
199
+ - spec/lib/moon/response/base_spec.rb
200
+ - spec/lib/moon/response/json_spec.rb
201
+ - spec/lib/moon/utility/string_spec.rb
202
+ - spec/lib/moon/utility/template_spec.rb
203
+ - spec/lib/moon/validator/format_spec.rb
204
+ - spec/lib/moon/validator/presence_spec.rb
205
+ - spec/lib/moon/validator/length_spec.rb
206
+ - spec/lib/moon/validator_spec.rb
207
+ - spec/lib/moon/formatter_spec.rb
208
+ - spec/lib/moon/formatter/generic_spec.rb
209
+ - spec/lib/moon/formatter/base_spec.rb