cassandra_object 0.6.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/lib/cassandra_object/associations/one_to_many.rb +136 -0
  2. data/lib/cassandra_object/associations/one_to_one.rb +77 -0
  3. data/lib/cassandra_object/associations.rb +35 -0
  4. data/lib/cassandra_object/attributes.rb +93 -0
  5. data/lib/cassandra_object/base.rb +104 -0
  6. data/lib/cassandra_object/callbacks.rb +10 -0
  7. data/lib/cassandra_object/collection.rb +8 -0
  8. data/lib/cassandra_object/cursor.rb +86 -0
  9. data/lib/cassandra_object/dirty.rb +27 -0
  10. data/lib/cassandra_object/identity/abstract_key_factory.rb +36 -0
  11. data/lib/cassandra_object/identity/key.rb +20 -0
  12. data/lib/cassandra_object/identity/natural_key_factory.rb +51 -0
  13. data/lib/cassandra_object/identity/uuid_key_factory.rb +37 -0
  14. data/lib/cassandra_object/identity.rb +61 -0
  15. data/lib/cassandra_object/indexes.rb +129 -0
  16. data/lib/cassandra_object/legacy_callbacks.rb +33 -0
  17. data/lib/cassandra_object/migrations.rb +72 -0
  18. data/lib/cassandra_object/mocking.rb +15 -0
  19. data/lib/cassandra_object/persistence.rb +193 -0
  20. data/lib/cassandra_object/serialization.rb +6 -0
  21. data/lib/cassandra_object/type_registration.rb +7 -0
  22. data/lib/cassandra_object/types.rb +128 -0
  23. data/lib/cassandra_object/validation.rb +58 -0
  24. data/lib/cassandra_object.rb +30 -0
  25. data/vendor/active_support_shims.rb +4 -0
  26. data/vendor/activemodel/CHANGELOG +13 -0
  27. data/vendor/activemodel/CHANGES +12 -0
  28. data/vendor/activemodel/MIT-LICENSE +21 -0
  29. data/vendor/activemodel/README +21 -0
  30. data/vendor/activemodel/Rakefile +52 -0
  31. data/vendor/activemodel/activemodel.gemspec +19 -0
  32. data/vendor/activemodel/examples/validations.rb +29 -0
  33. data/vendor/activemodel/lib/active_model/attribute_methods.rb +291 -0
  34. data/vendor/activemodel/lib/active_model/callbacks.rb +91 -0
  35. data/vendor/activemodel/lib/active_model/conversion.rb +8 -0
  36. data/vendor/activemodel/lib/active_model/deprecated_error_methods.rb +33 -0
  37. data/vendor/activemodel/lib/active_model/dirty.rb +126 -0
  38. data/vendor/activemodel/lib/active_model/errors.rb +162 -0
  39. data/vendor/activemodel/lib/active_model/lint.rb +91 -0
  40. data/vendor/activemodel/lib/active_model/locale/en.yml +27 -0
  41. data/vendor/activemodel/lib/active_model/naming.rb +45 -0
  42. data/vendor/activemodel/lib/active_model/observing.rb +191 -0
  43. data/vendor/activemodel/lib/active_model/railtie.rb +2 -0
  44. data/vendor/activemodel/lib/active_model/serialization.rb +30 -0
  45. data/vendor/activemodel/lib/active_model/serializers/json.rb +96 -0
  46. data/vendor/activemodel/lib/active_model/serializers/xml.rb +204 -0
  47. data/vendor/activemodel/lib/active_model/state_machine/event.rb +62 -0
  48. data/vendor/activemodel/lib/active_model/state_machine/machine.rb +75 -0
  49. data/vendor/activemodel/lib/active_model/state_machine/state.rb +47 -0
  50. data/vendor/activemodel/lib/active_model/state_machine/state_transition.rb +40 -0
  51. data/vendor/activemodel/lib/active_model/state_machine.rb +70 -0
  52. data/vendor/activemodel/lib/active_model/test_case.rb +18 -0
  53. data/vendor/activemodel/lib/active_model/translation.rb +44 -0
  54. data/vendor/activemodel/lib/active_model/validations/acceptance.rb +55 -0
  55. data/vendor/activemodel/lib/active_model/validations/confirmation.rb +47 -0
  56. data/vendor/activemodel/lib/active_model/validations/exclusion.rb +42 -0
  57. data/vendor/activemodel/lib/active_model/validations/format.rb +64 -0
  58. data/vendor/activemodel/lib/active_model/validations/inclusion.rb +42 -0
  59. data/vendor/activemodel/lib/active_model/validations/length.rb +117 -0
  60. data/vendor/activemodel/lib/active_model/validations/numericality.rb +111 -0
  61. data/vendor/activemodel/lib/active_model/validations/presence.rb +42 -0
  62. data/vendor/activemodel/lib/active_model/validations/with.rb +59 -0
  63. data/vendor/activemodel/lib/active_model/validations.rb +120 -0
  64. data/vendor/activemodel/lib/active_model/validator.rb +110 -0
  65. data/vendor/activemodel/lib/active_model/version.rb +9 -0
  66. data/vendor/activemodel/lib/active_model.rb +61 -0
  67. data/vendor/activemodel/test/cases/attribute_methods_test.rb +46 -0
  68. data/vendor/activemodel/test/cases/callbacks_test.rb +70 -0
  69. data/vendor/activemodel/test/cases/helper.rb +23 -0
  70. data/vendor/activemodel/test/cases/lint_test.rb +28 -0
  71. data/vendor/activemodel/test/cases/naming_test.rb +28 -0
  72. data/vendor/activemodel/test/cases/observing_test.rb +133 -0
  73. data/vendor/activemodel/test/cases/serializeration/json_serialization_test.rb +83 -0
  74. data/vendor/activemodel/test/cases/serializeration/xml_serialization_test.rb +110 -0
  75. data/vendor/activemodel/test/cases/state_machine/event_test.rb +49 -0
  76. data/vendor/activemodel/test/cases/state_machine/machine_test.rb +43 -0
  77. data/vendor/activemodel/test/cases/state_machine/state_test.rb +72 -0
  78. data/vendor/activemodel/test/cases/state_machine/state_transition_test.rb +84 -0
  79. data/vendor/activemodel/test/cases/state_machine_test.rb +312 -0
  80. data/vendor/activemodel/test/cases/tests_database.rb +37 -0
  81. data/vendor/activemodel/test/cases/translation_test.rb +45 -0
  82. data/vendor/activemodel/test/cases/validations/acceptance_validation_test.rb +71 -0
  83. data/vendor/activemodel/test/cases/validations/conditional_validation_test.rb +141 -0
  84. data/vendor/activemodel/test/cases/validations/confirmation_validation_test.rb +58 -0
  85. data/vendor/activemodel/test/cases/validations/exclusion_validation_test.rb +47 -0
  86. data/vendor/activemodel/test/cases/validations/format_validation_test.rb +118 -0
  87. data/vendor/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb +175 -0
  88. data/vendor/activemodel/test/cases/validations/i18n_validation_test.rb +527 -0
  89. data/vendor/activemodel/test/cases/validations/inclusion_validation_test.rb +71 -0
  90. data/vendor/activemodel/test/cases/validations/length_validation_test.rb +437 -0
  91. data/vendor/activemodel/test/cases/validations/numericality_validation_test.rb +180 -0
  92. data/vendor/activemodel/test/cases/validations/presence_validation_test.rb +70 -0
  93. data/vendor/activemodel/test/cases/validations/with_validation_test.rb +166 -0
  94. data/vendor/activemodel/test/cases/validations_test.rb +215 -0
  95. data/vendor/activemodel/test/config.rb +3 -0
  96. data/vendor/activemodel/test/fixtures/topics.yml +41 -0
  97. data/vendor/activemodel/test/models/contact.rb +7 -0
  98. data/vendor/activemodel/test/models/custom_reader.rb +17 -0
  99. data/vendor/activemodel/test/models/developer.rb +6 -0
  100. data/vendor/activemodel/test/models/person.rb +9 -0
  101. data/vendor/activemodel/test/models/reply.rb +34 -0
  102. data/vendor/activemodel/test/models/topic.rb +9 -0
  103. data/vendor/activemodel/test/models/track_back.rb +4 -0
  104. data/vendor/activemodel/test/schema.rb +14 -0
  105. data/vendor/activesupport/lib/active_support/autoload.rb +48 -0
  106. data/vendor/activesupport/lib/active_support/concern.rb +25 -0
  107. data/vendor/activesupport/lib/active_support/core_ext/array/wrap.rb +20 -0
  108. data/vendor/activesupport/lib/active_support/core_ext/object/blank.rb +58 -0
  109. data/vendor/activesupport/lib/active_support/core_ext/object/tap.rb +6 -0
  110. data/vendor/activesupport/lib/active_support/dependency_module.rb +17 -0
  111. data/vendor/activesupport/lib/active_support/i18n.rb +2 -0
  112. data/vendor/activesupport/lib/active_support/locale/en.yml +33 -0
  113. metadata +230 -0
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require 'cases/helper'
3
+ require 'cases/tests_database'
4
+
5
+ require 'models/topic'
6
+ require 'models/person'
7
+
8
+ class ExclusionValidationTest < ActiveModel::TestCase
9
+ include ActiveModel::TestsDatabase
10
+
11
+ def teardown
12
+ Topic.reset_callbacks(:validate)
13
+ end
14
+
15
+ def test_validates_exclusion_of
16
+ Topic.validates_exclusion_of( :title, :in => %w( abe monkey ) )
17
+
18
+ assert Topic.create("title" => "something", "content" => "abc").valid?
19
+ assert !Topic.create("title" => "monkey", "content" => "abc").valid?
20
+ end
21
+
22
+ def test_validates_exclusion_of_with_formatted_message
23
+ Topic.validates_exclusion_of( :title, :in => %w( abe monkey ), :message => "option {{value}} is restricted" )
24
+
25
+ assert Topic.create("title" => "something", "content" => "abc")
26
+
27
+ t = Topic.create("title" => "monkey")
28
+ assert !t.valid?
29
+ assert t.errors[:title].any?
30
+ assert_equal ["option monkey is restricted"], t.errors[:title]
31
+ end
32
+
33
+ def test_validates_exclusion_of_for_ruby_class
34
+ Person.validates_exclusion_of :karma, :in => %w( abe monkey )
35
+
36
+ p = Person.new
37
+ p.karma = "abe"
38
+ assert p.invalid?
39
+
40
+ assert_equal ["is reserved"], p.errors[:karma]
41
+
42
+ p.karma = "Lifo"
43
+ assert p.valid?
44
+ ensure
45
+ Person.reset_callbacks(:validate)
46
+ end
47
+ end
@@ -0,0 +1,118 @@
1
+ # encoding: utf-8
2
+ require 'cases/helper'
3
+ require 'cases/tests_database'
4
+
5
+ require 'models/topic'
6
+ require 'models/developer'
7
+ require 'models/person'
8
+
9
+ class PresenceValidationTest < ActiveModel::TestCase
10
+ include ActiveModel::TestsDatabase
11
+
12
+ def teardown
13
+ Topic.reset_callbacks(:validate)
14
+ end
15
+
16
+ def test_validate_format
17
+ Topic.validates_format_of(:title, :content, :with => /^Validation\smacros \w+!$/, :message => "is bad data")
18
+
19
+ t = Topic.create("title" => "i'm incorrect", "content" => "Validation macros rule!")
20
+ assert !t.valid?, "Shouldn't be valid"
21
+ assert !t.save, "Shouldn't save because it's invalid"
22
+ assert_equal ["is bad data"], t.errors[:title]
23
+ assert t.errors[:content].empty?
24
+
25
+ t.title = "Validation macros rule!"
26
+
27
+ assert t.save
28
+ assert t.errors[:title].empty?
29
+
30
+ assert_raise(ArgumentError) { Topic.validates_format_of(:title, :content) }
31
+ end
32
+
33
+ def test_validate_format_with_allow_blank
34
+ Topic.validates_format_of(:title, :with => /^Validation\smacros \w+!$/, :allow_blank=>true)
35
+ assert !Topic.create("title" => "Shouldn't be valid").valid?
36
+ assert Topic.create("title" => "").valid?
37
+ assert Topic.create("title" => nil).valid?
38
+ assert Topic.create("title" => "Validation macros rule!").valid?
39
+ end
40
+
41
+ # testing ticket #3142
42
+ def test_validate_format_numeric
43
+ Topic.validates_format_of(:title, :content, :with => /^[1-9][0-9]*$/, :message => "is bad data")
44
+
45
+ t = Topic.create("title" => "72x", "content" => "6789")
46
+ assert !t.valid?, "Shouldn't be valid"
47
+ assert !t.save, "Shouldn't save because it's invalid"
48
+ assert_equal ["is bad data"], t.errors[:title]
49
+ assert t.errors[:content].empty?
50
+
51
+ t.title = "-11"
52
+ assert !t.valid?, "Shouldn't be valid"
53
+
54
+ t.title = "03"
55
+ assert !t.valid?, "Shouldn't be valid"
56
+
57
+ t.title = "z44"
58
+ assert !t.valid?, "Shouldn't be valid"
59
+
60
+ t.title = "5v7"
61
+ assert !t.valid?, "Shouldn't be valid"
62
+
63
+ t.title = "1"
64
+
65
+ assert t.save
66
+ assert t.errors[:title].empty?
67
+ end
68
+
69
+ def test_validate_format_with_formatted_message
70
+ Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => "can't be {{value}}")
71
+ t = Topic.create(:title => 'Invalid title')
72
+ assert_equal ["can't be Invalid title"], t.errors[:title]
73
+ end
74
+
75
+ def test_validate_format_with_not_option
76
+ Topic.validates_format_of(:title, :without => /foo/, :message => "should not contain foo")
77
+ t = Topic.new
78
+
79
+ t.title = "foobar"
80
+ t.valid?
81
+ assert_equal ["should not contain foo"], t.errors[:title]
82
+
83
+ t.title = "something else"
84
+ t.valid?
85
+ assert_equal [], t.errors[:title]
86
+ end
87
+
88
+ def test_validate_format_of_without_any_regexp_should_raise_error
89
+ assert_raise(ArgumentError) { Topic.validates_format_of(:title) }
90
+ end
91
+
92
+ def test_validates_format_of_with_both_regexps_should_raise_error
93
+ assert_raise(ArgumentError) { Topic.validates_format_of(:title, :with => /this/, :without => /that/) }
94
+ end
95
+
96
+ def test_validates_format_of_when_with_isnt_a_regexp_should_raise_error
97
+ assert_raise(ArgumentError) { Topic.validates_format_of(:title, :with => "clearly not a regexp") }
98
+ end
99
+
100
+ def test_validates_format_of_when_not_isnt_a_regexp_should_raise_error
101
+ assert_raise(ArgumentError) { Topic.validates_format_of(:title, :without => "clearly not a regexp") }
102
+ end
103
+
104
+ def test_validates_format_of_for_ruby_class
105
+ Person.validates_format_of :karma, :with => /\A\d+\Z/
106
+
107
+ p = Person.new
108
+ p.karma = "Pixies"
109
+ assert p.invalid?
110
+
111
+ assert_equal ["is invalid"], p.errors[:karma]
112
+
113
+ p.karma = "1234"
114
+ assert p.valid?
115
+ ensure
116
+ Person.reset_callbacks(:validate)
117
+ end
118
+ end
@@ -0,0 +1,175 @@
1
+ require "cases/helper"
2
+ require 'cases/tests_database'
3
+
4
+ require 'models/person'
5
+
6
+ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
7
+ def setup
8
+ Person.reset_callbacks(:validate)
9
+ @person = Person.new
10
+
11
+ @old_load_path, @old_backend = I18n.load_path, I18n.backend
12
+ I18n.load_path.clear
13
+ I18n.backend = I18n::Backend::Simple.new
14
+
15
+ I18n.backend.store_translations :'en', {
16
+ :activemodel => {
17
+ :errors => {
18
+ :messages => {
19
+ :inclusion => "is not included in the list",
20
+ :exclusion => "is reserved",
21
+ :invalid => "is invalid",
22
+ :confirmation => "doesn't match confirmation",
23
+ :accepted => "must be accepted",
24
+ :empty => "can't be empty",
25
+ :blank => "can't be blank",
26
+ :too_long => "is too long (maximum is {{count}} characters)",
27
+ :too_short => "is too short (minimum is {{count}} characters)",
28
+ :wrong_length => "is the wrong length (should be {{count}} characters)",
29
+ :not_a_number => "is not a number",
30
+ :greater_than => "must be greater than {{count}}",
31
+ :greater_than_or_equal_to => "must be greater than or equal to {{count}}",
32
+ :equal_to => "must be equal to {{count}}",
33
+ :less_than => "must be less than {{count}}",
34
+ :less_than_or_equal_to => "must be less than or equal to {{count}}",
35
+ :odd => "must be odd",
36
+ :even => "must be even"
37
+ }
38
+ }
39
+ }
40
+ }
41
+ end
42
+
43
+ def teardown
44
+ I18n.load_path.replace @old_load_path
45
+ I18n.backend = @old_backend
46
+ end
47
+
48
+ # validates_inclusion_of: generate_message(attr_name, :inclusion, :default => configuration[:message], :value => value)
49
+ def test_generate_message_inclusion_with_default_message
50
+ assert_equal 'is not included in the list', @person.errors.generate_message(:title, :inclusion, :default => nil, :value => 'title')
51
+ end
52
+
53
+ def test_generate_message_inclusion_with_custom_message
54
+ assert_equal 'custom message title', @person.errors.generate_message(:title, :inclusion, :default => 'custom message {{value}}', :value => 'title')
55
+ end
56
+
57
+ # validates_exclusion_of: generate_message(attr_name, :exclusion, :default => configuration[:message], :value => value)
58
+ def test_generate_message_exclusion_with_default_message
59
+ assert_equal 'is reserved', @person.errors.generate_message(:title, :exclusion, :default => nil, :value => 'title')
60
+ end
61
+
62
+ def test_generate_message_exclusion_with_custom_message
63
+ assert_equal 'custom message title', @person.errors.generate_message(:title, :exclusion, :default => 'custom message {{value}}', :value => 'title')
64
+ end
65
+
66
+ # validates_format_of: generate_message(attr_name, :invalid, :default => configuration[:message], :value => value)
67
+ def test_generate_message_invalid_with_default_message
68
+ assert_equal 'is invalid', @person.errors.generate_message(:title, :invalid, :default => nil, :value => 'title')
69
+ end
70
+
71
+ def test_generate_message_invalid_with_custom_message
72
+ assert_equal 'custom message title', @person.errors.generate_message(:title, :invalid, :default => 'custom message {{value}}', :value => 'title')
73
+ end
74
+
75
+ # validates_confirmation_of: generate_message(attr_name, :confirmation, :default => configuration[:message])
76
+ def test_generate_message_confirmation_with_default_message
77
+ assert_equal "doesn't match confirmation", @person.errors.generate_message(:title, :confirmation, :default => nil)
78
+ end
79
+
80
+ def test_generate_message_confirmation_with_custom_message
81
+ assert_equal 'custom message', @person.errors.generate_message(:title, :confirmation, :default => 'custom message')
82
+ end
83
+
84
+ # validates_acceptance_of: generate_message(attr_name, :accepted, :default => configuration[:message])
85
+ def test_generate_message_accepted_with_default_message
86
+ assert_equal "must be accepted", @person.errors.generate_message(:title, :accepted, :default => nil)
87
+ end
88
+
89
+ def test_generate_message_accepted_with_custom_message
90
+ assert_equal 'custom message', @person.errors.generate_message(:title, :accepted, :default => 'custom message')
91
+ end
92
+
93
+ # add_on_empty: generate_message(attr, :empty, :default => custom_message)
94
+ def test_generate_message_empty_with_default_message
95
+ assert_equal "can't be empty", @person.errors.generate_message(:title, :empty, :default => nil)
96
+ end
97
+
98
+ def test_generate_message_empty_with_custom_message
99
+ assert_equal 'custom message', @person.errors.generate_message(:title, :empty, :default => 'custom message')
100
+ end
101
+
102
+ # add_on_blank: generate_message(attr, :blank, :default => custom_message)
103
+ def test_generate_message_blank_with_default_message
104
+ assert_equal "can't be blank", @person.errors.generate_message(:title, :blank, :default => nil)
105
+ end
106
+
107
+ def test_generate_message_blank_with_custom_message
108
+ assert_equal 'custom message', @person.errors.generate_message(:title, :blank, :default => 'custom message')
109
+ end
110
+
111
+ # validates_length_of: generate_message(attr, :too_long, :default => options[:too_long], :count => option_value.end)
112
+ def test_generate_message_too_long_with_default_message
113
+ assert_equal "is too long (maximum is 10 characters)", @person.errors.generate_message(:title, :too_long, :default => nil, :count => 10)
114
+ end
115
+
116
+ def test_generate_message_too_long_with_custom_message
117
+ assert_equal 'custom message 10', @person.errors.generate_message(:title, :too_long, :default => 'custom message {{count}}', :count => 10)
118
+ end
119
+
120
+ # validates_length_of: generate_message(attr, :too_short, :default => options[:too_short], :count => option_value.begin)
121
+ def test_generate_message_too_short_with_default_message
122
+ assert_equal "is too short (minimum is 10 characters)", @person.errors.generate_message(:title, :too_short, :default => nil, :count => 10)
123
+ end
124
+
125
+ def test_generate_message_too_short_with_custom_message
126
+ assert_equal 'custom message 10', @person.errors.generate_message(:title, :too_short, :default => 'custom message {{count}}', :count => 10)
127
+ end
128
+
129
+ # validates_length_of: generate_message(attr, key, :default => custom_message, :count => option_value)
130
+ def test_generate_message_wrong_length_with_default_message
131
+ assert_equal "is the wrong length (should be 10 characters)", @person.errors.generate_message(:title, :wrong_length, :default => nil, :count => 10)
132
+ end
133
+
134
+ def test_generate_message_wrong_length_with_custom_message
135
+ assert_equal 'custom message 10', @person.errors.generate_message(:title, :wrong_length, :default => 'custom message {{count}}', :count => 10)
136
+ end
137
+
138
+ # validates_numericality_of: generate_message(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
139
+ def test_generate_message_not_a_number_with_default_message
140
+ assert_equal "is not a number", @person.errors.generate_message(:title, :not_a_number, :default => nil, :value => 'title')
141
+ end
142
+
143
+ def test_generate_message_not_a_number_with_custom_message
144
+ assert_equal 'custom message title', @person.errors.generate_message(:title, :not_a_number, :default => 'custom message {{value}}', :value => 'title')
145
+ end
146
+
147
+ # validates_numericality_of: generate_message(attr_name, option, :value => raw_value, :default => configuration[:message])
148
+ def test_generate_message_greater_than_with_default_message
149
+ assert_equal "must be greater than 10", @person.errors.generate_message(:title, :greater_than, :default => nil, :value => 'title', :count => 10)
150
+ end
151
+
152
+ def test_generate_message_greater_than_or_equal_to_with_default_message
153
+ assert_equal "must be greater than or equal to 10", @person.errors.generate_message(:title, :greater_than_or_equal_to, :default => nil, :value => 'title', :count => 10)
154
+ end
155
+
156
+ def test_generate_message_equal_to_with_default_message
157
+ assert_equal "must be equal to 10", @person.errors.generate_message(:title, :equal_to, :default => nil, :value => 'title', :count => 10)
158
+ end
159
+
160
+ def test_generate_message_less_than_with_default_message
161
+ assert_equal "must be less than 10", @person.errors.generate_message(:title, :less_than, :default => nil, :value => 'title', :count => 10)
162
+ end
163
+
164
+ def test_generate_message_less_than_or_equal_to_with_default_message
165
+ assert_equal "must be less than or equal to 10", @person.errors.generate_message(:title, :less_than_or_equal_to, :default => nil, :value => 'title', :count => 10)
166
+ end
167
+
168
+ def test_generate_message_odd_with_default_message
169
+ assert_equal "must be odd", @person.errors.generate_message(:title, :odd, :default => nil, :value => 'title', :count => 10)
170
+ end
171
+
172
+ def test_generate_message_even_with_default_message
173
+ assert_equal "must be even", @person.errors.generate_message(:title, :even, :default => nil, :value => 'title', :count => 10)
174
+ end
175
+ end