sunstone 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active_record/connection_adapters/sunstone/column.rb +19 -0
  3. data/lib/active_record/connection_adapters/sunstone/database_statements.rb +40 -0
  4. data/lib/active_record/connection_adapters/sunstone/schema_statements.rb +95 -0
  5. data/lib/active_record/connection_adapters/sunstone/type/date_time.rb +22 -0
  6. data/lib/active_record/connection_adapters/sunstone_adapter.rb +177 -0
  7. data/lib/arel/collectors/sunstone.rb +75 -0
  8. data/lib/arel/visitors/sunstone.rb +769 -0
  9. data/lib/ext/active_record/associations/builder/has_and_belongs_to_many.rb +48 -0
  10. data/lib/ext/active_record/relation.rb +26 -0
  11. data/lib/ext/active_record/statement_cache.rb +24 -0
  12. data/lib/sunstone.rb +37 -347
  13. data/lib/sunstone/connection.rb +337 -0
  14. data/sunstone.gemspec +3 -2
  15. data/test/sunstone/connection_test.rb +319 -0
  16. data/test/sunstone/parser_test.rb +21 -21
  17. metadata +30 -36
  18. data/lib/sunstone/model.rb +0 -23
  19. data/lib/sunstone/model/attributes.rb +0 -99
  20. data/lib/sunstone/model/persistence.rb +0 -168
  21. data/lib/sunstone/schema.rb +0 -38
  22. data/lib/sunstone/type/boolean.rb +0 -19
  23. data/lib/sunstone/type/date_time.rb +0 -20
  24. data/lib/sunstone/type/decimal.rb +0 -19
  25. data/lib/sunstone/type/integer.rb +0 -17
  26. data/lib/sunstone/type/mutable.rb +0 -16
  27. data/lib/sunstone/type/string.rb +0 -18
  28. data/lib/sunstone/type/value.rb +0 -97
  29. data/test/sunstone/model/associations_test.rb +0 -55
  30. data/test/sunstone/model/attributes_test.rb +0 -60
  31. data/test/sunstone/model/persistence_test.rb +0 -173
  32. data/test/sunstone/model_test.rb +0 -11
  33. data/test/sunstone/schema_test.rb +0 -25
  34. data/test/sunstone/type/boolean_test.rb +0 -24
  35. data/test/sunstone/type/date_time_test.rb +0 -31
  36. data/test/sunstone/type/decimal_test.rb +0 -27
  37. data/test/sunstone/type/integer_test.rb +0 -29
  38. data/test/sunstone/type/string_test.rb +0 -54
  39. data/test/sunstone/type/value_test.rb +0 -27
@@ -1,11 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::ModelTest < Minitest::Test
4
-
5
- def setup
6
- Sunstone.site = "http://test_api_key@testhost.com"
7
- end
8
-
9
- #TODO: test initializer
10
-
11
- end
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::SchemaTest < Minitest::Test
4
-
5
- test "type methods" do
6
- schema = Sunstone::Schema.new
7
-
8
- schema.boolean(:boolean)
9
- schema.datetime(:datetime)
10
- schema.decimal(:decimal)
11
- schema.integer(:integer)
12
- schema.string(:string)
13
-
14
- {
15
- :boolean => Sunstone::Type::Boolean,
16
- :datetime => Sunstone::Type::DateTime,
17
- :decimal => Sunstone::Type::Decimal,
18
- :integer => Sunstone::Type::Integer,
19
- :string => Sunstone::Type::String
20
- }.each do |name, klass|
21
- assert_kind_of klass, schema[name]
22
- end
23
- end
24
-
25
- end
@@ -1,24 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::Type::BooleanTest < Minitest::Test
4
-
5
- test "type casting" do
6
- type = Sunstone::Type::Boolean.new
7
-
8
- assert_equal true, type.type_cast_from_user(true)
9
- assert_equal true, type.type_cast_from_user('true')
10
- assert_equal true, type.type_cast_from_user('TRUE')
11
-
12
- assert_equal false, type.type_cast_from_user(false)
13
- assert_equal false, type.type_cast_from_user('false')
14
- assert_equal false, type.type_cast_from_user('FALSE')
15
- end
16
-
17
- test "#type_cast_for_json" do
18
- type = Sunstone::Type::Boolean.new
19
-
20
- assert_equal true, type.type_cast_for_json(true)
21
- assert_equal false, type.type_cast_for_json(false)
22
- end
23
-
24
- end
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::Type::DateTimeTest < Minitest::Test
4
-
5
- test "#type_cast_from_user" do
6
- type = Sunstone::Type::DateTime.new
7
-
8
- assert_equal DateTime.new(2001, 2, 3, 4, 5, 6, '+7'), type.type_cast_from_user('2001-02-03T04:05:06+07:00')
9
- assert_equal DateTime.new(2001, 2, 3, 4, 5, 6, '+7'), type.type_cast_from_user('20010203T040506+0700')
10
- assert_equal DateTime.new(2001, 2, 3, 4, 5, 6, '+7'), type.type_cast_from_user('2001-W05-6T04:05:06+07:00')
11
- assert_equal DateTime.new(2014, 7, 14, 16, 44, 15, '-7'), type.type_cast_from_user("2014-07-14T16:44:15-07:00")
12
- assert_equal Rational(123,1000), type.type_cast_from_user('2001-02-03T04:05:06.123+07:00').sec_fraction
13
- end
14
-
15
- test "#type_cast_from_json" do
16
- type = Sunstone::Type::DateTime.new
17
-
18
- assert_equal DateTime.new(2001, 2, 3, 4, 5, 6, '+7'), type.type_cast_from_json('2001-02-03T04:05:06+07:00')
19
- assert_equal DateTime.new(2001, 2, 3, 4, 5, 6, '+7'), type.type_cast_from_json('20010203T040506+0700')
20
- assert_equal DateTime.new(2001, 2, 3, 4, 5, 6, '+7'), type.type_cast_from_json('2001-W05-6T04:05:06+07:00')
21
- assert_equal DateTime.new(2014, 7, 14, 16, 44, 15, '-7'), type.type_cast_from_json("2014-07-14T16:44:15-07:00")
22
- assert_equal Rational(123,1000), type.type_cast_from_json('2001-02-03T04:05:06.123+07:00').sec_fraction
23
- end
24
-
25
- test "#type_cast_for_json" do
26
- type = Sunstone::Type::DateTime.new
27
-
28
- assert_equal '2001-02-03T04:05:06.000+07:00', type.type_cast_for_json(DateTime.new(2001, 2, 3, 4, 5, 6, '+7'))
29
- end
30
-
31
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::Type::DecimalTest < Minitest::Test
4
-
5
- test "#type_cast_from_user" do
6
- type = Sunstone::Type::Decimal.new
7
-
8
- assert_equal BigDecimal.new("10.50"), type.type_cast_from_user(BigDecimal.new("10.50"))
9
- assert_equal BigDecimal.new("10.50"), type.type_cast_from_user(10.50)
10
- assert_equal BigDecimal.new("10.50"), type.type_cast_from_user("10.50")
11
- end
12
-
13
- test "#type_cast_from_json" do
14
- type = Sunstone::Type::Decimal.new
15
-
16
- assert_equal BigDecimal.new("10.50"), type.type_cast_from_json(BigDecimal.new("10.50"))
17
- assert_equal BigDecimal.new("10.50"), type.type_cast_from_json(10.50)
18
- assert_equal BigDecimal.new("10.50"), type.type_cast_from_json("10.50")
19
- end
20
-
21
- test "#type_cast_for_json" do
22
- type = Sunstone::Type::Decimal.new
23
-
24
- assert_equal BigDecimal.new("10.50"), type.type_cast_for_json(BigDecimal.new("10.50"))
25
- end
26
-
27
- end
@@ -1,29 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::Type::IntegerTest < Minitest::Test
4
-
5
- test "#type_cast_from_user" do
6
- type = Sunstone::Type::Integer.new
7
-
8
- assert_equal 10, type.type_cast_from_user(10)
9
- assert_equal 10, type.type_cast_from_user("10")
10
- assert_equal 1, type.type_cast_from_user(true)
11
- assert_equal 0, type.type_cast_from_user(false)
12
- end
13
-
14
- test "#type_cast_from_json" do
15
- type = Sunstone::Type::Integer.new
16
-
17
- assert_equal 10, type.type_cast_from_json(10)
18
- assert_equal 10, type.type_cast_from_json("10")
19
- assert_equal 1, type.type_cast_from_json(true)
20
- assert_equal 0, type.type_cast_from_json(false)
21
- end
22
-
23
- test "#type_cast_for_json" do
24
- type = Sunstone::Type::Integer.new
25
-
26
- assert_equal 10, type.type_cast_for_json(10)
27
- end
28
-
29
- end
@@ -1,54 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::Type::StringTest < Minitest::Test
4
-
5
- test "#type_cast_from_user" do
6
- type = Sunstone::Type::String.new
7
-
8
- assert_equal "1", type.type_cast_from_user(true)
9
- assert_equal "0", type.type_cast_from_user(false)
10
- assert_equal "123", type.type_cast_from_user(123)
11
- assert_equal "string", type.type_cast_from_user("string")
12
- end
13
-
14
- test "#type_cast_from_json" do
15
- type = Sunstone::Type::String.new
16
-
17
- assert_equal "1", type.type_cast_from_json(true)
18
- assert_equal "0", type.type_cast_from_json(false)
19
- assert_equal "123", type.type_cast_from_json(123)
20
- assert_equal "string", type.type_cast_from_json("string")
21
- end
22
-
23
- test "#type_cast_for_json" do
24
- type = Sunstone::Type::String.new
25
-
26
- assert_equal "10", type.type_cast_for_json("10")
27
- end
28
-
29
- test "values are duped coming out" do
30
- s = "foo"
31
- type = Sunstone::Type::String.new
32
-
33
- assert_not_same s, type.type_cast_from_user(s)
34
- assert_not_same s, type.type_cast_from_json(s)
35
- end
36
-
37
- test "string mutations are detected" # do
38
- # klass = Class.new(Model)
39
- # klass.table_name = 'authors'
40
- #
41
- # author = klass.create!(name: 'Sean')
42
- # assert_not author.changed?
43
- #
44
- # author.name << ' Griffin'
45
- # assert author.name_changed?
46
- #
47
- # author.save!
48
- # author.reload
49
- #
50
- # assert_equal 'Sean Griffin', author.name
51
- # assert_not author.changed?
52
- # end
53
-
54
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::Type::ValueTest < Minitest::Test
4
-
5
- test "#readonly?" do
6
- type = Sunstone::Type::Value.new(:readonly => true)
7
- assert_equal true, type.readonly?
8
- end
9
-
10
- test "array support" do
11
- type = Sunstone::Type::Value.new(:array => true)
12
-
13
- type.expects(:_type_cast).with(1).returns(1).twice
14
- type.expects(:_type_cast).with('2').returns('2').twice
15
- type.expects(:_type_cast).with(:a).returns(:a).twice
16
-
17
- assert_equal([1, '2', :a], type.type_cast_from_user([1, '2', :a]))
18
- assert_equal([1, '2', :a], type.type_cast_from_json([1, '2', :a]))
19
- end
20
-
21
- test "#type_cast_for_json" do
22
- type = Sunstone::Type::Value.new(:array => true)
23
-
24
- assert_equal [1, '2', :a], type.type_cast_for_json([1, '2', :a])
25
- end
26
-
27
- end