moon 0.0.1 → 0.0.2

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