syncano 3.1.4 → 4.0.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +3 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +25 -1
  7. data/Guardfile +22 -4
  8. data/README.md +68 -447
  9. data/Rakefile +48 -5
  10. data/circle.yml +10 -0
  11. data/lib/active_attr/dirty.rb +3 -17
  12. data/lib/active_attr/typecasting/hash_typecaster.rb +34 -0
  13. data/lib/active_attr/typecasting_override.rb +29 -0
  14. data/lib/syncano.rb +53 -92
  15. data/lib/syncano/api.rb +13 -0
  16. data/lib/syncano/connection.rb +97 -0
  17. data/lib/syncano/model/associations.rb +121 -0
  18. data/lib/syncano/{active_record/association → model/associations}/base.rb +5 -5
  19. data/lib/syncano/{active_record/association → model/associations}/belongs_to.rb +6 -6
  20. data/lib/syncano/{active_record/association → model/associations}/has_many.rb +15 -9
  21. data/lib/syncano/{active_record/association → model/associations}/has_one.rb +4 -4
  22. data/lib/syncano/model/base.rb +257 -0
  23. data/lib/syncano/{active_record → model}/callbacks.rb +16 -13
  24. data/lib/syncano/{active_record → model}/scope_builder.rb +53 -69
  25. data/lib/syncano/query_builder.rb +19 -129
  26. data/lib/syncano/resources.rb +126 -0
  27. data/lib/syncano/resources/base.rb +304 -300
  28. data/lib/syncano/resources/collection.rb +19 -223
  29. data/lib/syncano/resources/space.rb +29 -0
  30. data/lib/syncano/schema.rb +86 -0
  31. data/lib/syncano/schema/attribute_definition.rb +83 -0
  32. data/lib/syncano/schema/resource_definition.rb +36 -0
  33. data/lib/syncano/scope.rb +10 -0
  34. data/lib/syncano/version.rb +3 -4
  35. data/spec/integration/syncano_spec.rb +228 -0
  36. data/spec/spec_helper.rb +15 -9
  37. data/spec/unit/api_spec.rb +5 -0
  38. data/spec/unit/connection_spec.rb +137 -0
  39. data/spec/unit/query_builder_spec.rb +75 -0
  40. data/spec/unit/resources/collection_spec.rb +36 -0
  41. data/spec/unit/resources/space_spec.rb +28 -0
  42. data/spec/unit/resources_base_spec.rb +185 -0
  43. data/spec/unit/schema/attribute_definition_spec.rb +18 -0
  44. data/spec/unit/schema/resource_definition_spec.rb +25 -0
  45. data/spec/unit/schema_spec.rb +3532 -0
  46. data/spec/unit/syncano_spec.rb +63 -0
  47. data/syncano.gemspec +8 -14
  48. metadata +85 -210
  49. data/lib/generators/syncano/install_generator.rb +0 -17
  50. data/lib/generators/syncano/templates/initializers/syncano.rb +0 -7
  51. data/lib/syncano/active_record/associations.rb +0 -112
  52. data/lib/syncano/active_record/base.rb +0 -318
  53. data/lib/syncano/batch_queue.rb +0 -58
  54. data/lib/syncano/batch_queue_element.rb +0 -33
  55. data/lib/syncano/clients/base.rb +0 -123
  56. data/lib/syncano/clients/rest.rb +0 -79
  57. data/lib/syncano/clients/sync.rb +0 -164
  58. data/lib/syncano/errors.rb +0 -17
  59. data/lib/syncano/jimson_client.rb +0 -66
  60. data/lib/syncano/packets/auth.rb +0 -27
  61. data/lib/syncano/packets/base.rb +0 -70
  62. data/lib/syncano/packets/call.rb +0 -34
  63. data/lib/syncano/packets/call_response.rb +0 -33
  64. data/lib/syncano/packets/error.rb +0 -19
  65. data/lib/syncano/packets/message.rb +0 -30
  66. data/lib/syncano/packets/notification.rb +0 -39
  67. data/lib/syncano/packets/ping.rb +0 -12
  68. data/lib/syncano/resources/admin.rb +0 -26
  69. data/lib/syncano/resources/api_key.rb +0 -108
  70. data/lib/syncano/resources/data_object.rb +0 -316
  71. data/lib/syncano/resources/folder.rb +0 -88
  72. data/lib/syncano/resources/notifications/base.rb +0 -103
  73. data/lib/syncano/resources/notifications/create.rb +0 -20
  74. data/lib/syncano/resources/notifications/destroy.rb +0 -20
  75. data/lib/syncano/resources/notifications/message.rb +0 -9
  76. data/lib/syncano/resources/notifications/update.rb +0 -24
  77. data/lib/syncano/resources/project.rb +0 -96
  78. data/lib/syncano/resources/role.rb +0 -11
  79. data/lib/syncano/resources/subscription.rb +0 -12
  80. data/lib/syncano/resources/user.rb +0 -65
  81. data/lib/syncano/response.rb +0 -22
  82. data/lib/syncano/sync_connection.rb +0 -133
  83. data/spec/admins_spec.rb +0 -16
  84. data/spec/api_keys_spec.rb +0 -34
  85. data/spec/collections_spec.rb +0 -67
  86. data/spec/data_objects_spec.rb +0 -113
  87. data/spec/folders_spec.rb +0 -39
  88. data/spec/notifications_spec.rb +0 -43
  89. data/spec/projects_spec.rb +0 -35
  90. data/spec/roles_spec.rb +0 -13
  91. data/spec/sync_resources_spec.rb +0 -35
  92. data/spec/syncano_spec.rb +0 -9
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Syncano::Resource::ApiKey' do
4
- it 'should create new api key in Syncano' do
5
- count_before = @client.api_keys.count
6
- api_key = @client.api_keys.create(role_id: '2', description: 'Just testing')
7
- count_after = @client.api_keys.count
8
-
9
- (count_after - count_before).should == 1
10
- @client.api_keys.last[:description].should == 'Just testing'
11
- end
12
-
13
- it 'should get api keys' do
14
- @client.api_keys.all.each do |api_key|
15
- api_key.id.should_not be_nil
16
- api_key[:description].should_not be_nil
17
- end
18
- end
19
-
20
- it 'should get one project' do
21
- api_keys = @client.api_keys.all
22
-
23
- api_key = @client.api_keys.find(api_keys.last.id)
24
- api_key[:description].should == api_keys.last[:description]
25
- end
26
-
27
- it 'should destroy project' do
28
- count_before = @client.api_keys.count
29
- @client.api_keys.last.destroy
30
- count_after = @client.api_keys.count
31
-
32
- (count_before - count_after).should == 1
33
- end
34
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Syncano::Resource::Collection' do
4
- before(:all) do
5
- @project = @client.projects.last || @client.projects.create(name: 'Test project')
6
- end
7
-
8
- it 'should create a new collection in Syncano' do
9
- count_before = @project.collections.count
10
-
11
- collection = @project.collections.create(name: 'Test collection', description: 'Just testing')
12
- collection.id.should_not be_nil
13
-
14
- count_after = @project.collections.count
15
-
16
- (count_after - count_before).should == 1
17
- @project.collections.last[:name].should == 'Test collection'
18
- end
19
-
20
- it 'should get all collections' do
21
- @project.collections.all.each do |collection|
22
- collection.id.should_not be_nil
23
- collection[:name].should_not be_nil
24
- end
25
- end
26
-
27
- it 'should get a one collection' do
28
- collection = @project.collections.last
29
- @project.collections.find(collection.id)[:name].should == collection[:name]
30
- end
31
-
32
- it 'should activate inactive collection' do
33
- collection = @project.collections.last
34
-
35
- if collection[:status] == 'active'
36
- collection.deactivate
37
- collection.reload!
38
- end
39
- collection[:status].should == 'inactive'
40
-
41
- collection.activate
42
- collection.reload!
43
- collection['status'].should == 'active'
44
- end
45
-
46
- it 'should deactivate active collection' do
47
- collection = @project.collections.last
48
-
49
- if collection[:status] == 'inactive'
50
- collection.activate
51
- collection.reload!
52
- end
53
- collection[:status].should == 'active'
54
-
55
- collection.deactivate
56
- collection.reload!
57
- collection[:status].should == 'inactive'
58
- end
59
-
60
- it 'should destroy a collection' do
61
- count_before = @project.collections.count
62
- @project.collections.last.destroy
63
- count_after = @project.collections.count
64
-
65
- (count_before - count_after).should == 1
66
- end
67
- end
@@ -1,113 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Syncano::Resource::DataObject' do
4
- before(:all) do
5
- @project = @client.projects.last || @client.projects.create(name: 'Test project')
6
- @collection = @project.collections.last || @project.collections.create(name: 'Test collection')
7
- end
8
-
9
- after(:all) do
10
- @client.batch do |q|
11
- @collection.data_objects.all.each do |data_object|
12
- q << data_object.batch.destroy
13
- end
14
- end
15
- end
16
-
17
- it 'should create new data object in Syncano' do
18
- count_before = @collection.data_objects.count
19
- @collection.data_objects.create(title: 'Test data object', test_attribute: 'test_value')
20
- count_after = @collection.data_objects.count
21
-
22
- (count_after - count_before).should == 1
23
- data_object = @collection.data_objects.last
24
- data_object[:title].should == 'Test data object'
25
- data_object[:test_attribute].should == 'test_value'
26
- end
27
-
28
- it 'should copy data object in Syncano' do
29
- count_before = @collection.data_objects.count
30
- data_object = @collection.data_objects.last
31
- data_object.copy
32
- data_object_copy = @collection.data_objects.last
33
- count_after = @collection.data_objects.count
34
-
35
- (count_after - count_before).should == 1
36
- data_object_copy[:title].should == data_object[:title]
37
- data_object_copy.id.should_not == data_object.id
38
- end
39
-
40
- it 'should get data objects' do
41
- @collection.data_objects.all.each do |data_object|
42
- data_object.id.should_not be_nil
43
- data_object[:state].should_not be_nil
44
- end
45
- end
46
-
47
- it 'should check amount of objects' do
48
- @collection.data_objects.count.should == @collection.data_objects.all.count
49
- end
50
-
51
- it 'should get one data object' do
52
- data_objects = @collection.data_objects.all
53
-
54
- data_object = @collection.data_objects.find(data_objects.last.id)
55
- data_object[:title].should == data_objects.last[:title]
56
- end
57
-
58
- context 'managing parents and children' do
59
- before(:all) do
60
- @parent = @collection.data_objects.first(include_children: true)
61
- @parent = @collection.data_objects.create(title: "Parent object")
62
- @child = @collection.data_objects.last
63
- @child = @collection.data_objects.create(title: 'Child object') if @child.id == @parent.id
64
- @parent.id.should_not == @child.id
65
- end
66
-
67
- it 'should add parent to the data object' do
68
- @parent.remove_child(@child.id) if @parent[:children].present? && @parent[:children].map(&:id).include?(@child.id)
69
-
70
- @child.add_parent(@parent.id)
71
- @parent.reload!(include_children: true)
72
-
73
- @parent[:children].should_not be_nil
74
- @parent[:children].select{ |c| c.id == @child.id }.first.should_not be_nil
75
- end
76
-
77
- it 'should remove parent from the data object' do
78
- @parent.add_child(@child.id) unless @parent[:children].present? && @parent[:children].map(&:id).include?(@child.id)
79
-
80
- @child.remove_parent(@parent.id)
81
- @parent.reload!(include_children: true)
82
-
83
- @parent[:children].should be_nil
84
- end
85
-
86
- it 'should add child to the data object' do
87
- @parent.remove_child(@child.id) if @parent[:children].present? && @parent[:children].map(&:id).include?(@child.id)
88
-
89
- @parent.add_child(@child.id)
90
- @parent.reload!(include_children: true)
91
-
92
- @parent[:children].should_not be_nil
93
- @parent[:children].select{ |c| c.id == @child.id }.first.should_not be_nil
94
- end
95
-
96
- it 'should remove child from the data object' do
97
- @parent.add_child(@child.id) unless @parent[:children].present? && @parent[:children].map(&:id).include?(@child.id)
98
-
99
- @parent.remove_child(@child.id)
100
- @parent.reload!(include_children: true)
101
-
102
- @parent[:children].should be_nil
103
- end
104
- end
105
-
106
- it 'should destroy data object' do
107
- count_before = @collection.data_objects.count
108
- @collection.data_objects.last.destroy
109
- count_after = @collection.data_objects.count
110
-
111
- (count_before - count_after).should == 1
112
- end
113
- end
data/spec/folders_spec.rb DELETED
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Syncano::Resource::Folder' do
4
- before(:all) do
5
- @project = @client.projects.last || @client.projects.create(name: 'Test project')
6
- @collection = @project.collections.last || @project.collections.create(name: 'Test collection')
7
- end
8
-
9
- it 'should create new folder in Syncano' do
10
- folder_name = "Test folder ##{Time.now.to_i}"
11
- count_before = @collection.folders.count
12
- folder = @collection.folders.create(name: folder_name)
13
- count_after = @collection.folders.count
14
-
15
- (count_after - count_before).should == 1
16
- @collection.folders.last[:name].should == folder_name
17
- end
18
-
19
- it 'should get folders' do
20
- @collection.folders.all.each do |folder|
21
- folder.id.should_not be_nil
22
- folder[:name].should_not be_nil
23
- end
24
- end
25
-
26
- it 'should get one folder' do
27
- folder = @collection.folders.last
28
- @collection.folders.find(folder[:name])[:name].should == folder[:name]
29
- @collection.folders.find_by_name(folder[:name])[:name].should == folder[:name]
30
- end
31
-
32
- it 'should destroy folder' do
33
- count_before = @collection.folders.count
34
- @collection.folders.last.destroy
35
- count_after = @collection.folders.count
36
-
37
- (count_before - count_after).should == 1
38
- end
39
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Handling notifications' do
4
- before(:all) do
5
- @project = @sync_client.projects.last || @sync_client.projects.create(name: 'Test project')
6
- @collection = @project.collections.last || @project.collections.create(name: 'Test collection')
7
- @object = @collection.data_objects.last || @collection.data_objects.create(title: 'Test object')
8
- @object.update(title: 'Test object')
9
- sleep 3
10
-
11
- @sync_client.append_callback(:test) do |notification|
12
- p "Notification received: #{notification.inspect}" if ENV['VERBOSE']
13
- end
14
- end
15
-
16
- it 'should subscribe to project' do
17
- @project.subscribe
18
- p 'Notification should be seen' if ENV['VERBOSE']
19
- @object.update(title: 'Test object 2')
20
- sleep 3
21
- end
22
-
23
- it 'should unsubscribe from project' do
24
- @project.unsubscribe
25
- p 'Notification should not be seen' if ENV['VERBOSE']
26
- @object.update(title: 'Test object 3')
27
- sleep 3
28
- end
29
-
30
- it 'should subscribe to collection' do
31
- @collection.subscribe
32
- p 'Notification should be seen' if ENV['VERBOSE']
33
- @object.update(title: 'Test object 4')
34
- sleep 3
35
- end
36
-
37
- it 'should unsubscribe from collection' do
38
- @collection.unsubscribe
39
- p 'Notification should not be seen' if ENV['VERBOSE']
40
- @object.update(title: 'Test object 5')
41
- sleep 3
42
- end
43
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Syncano::Resource::Project' do
4
- it 'should create new project in Syncano' do
5
- count_before = @client.projects.count
6
- @client.projects.create(name: 'Test project', description: 'Just testing')
7
- count_after = @client.projects.count
8
-
9
- (count_after - count_before).should == 1
10
- @client.projects.last[:name].should == 'Test project'
11
- end
12
-
13
- it 'should get projects' do
14
- projects = @client.projects.all
15
- projects.each do |project|
16
- project.id.should_not be_nil
17
- project[:name].should_not be_nil
18
- end
19
- end
20
-
21
- it 'should get one project' do
22
- projects = @client.projects.all
23
-
24
- project = @client.projects.find(projects.last.id)
25
- project[:name].should == projects.last[:name]
26
- end
27
-
28
- it 'should destroy project' do
29
- count_before = @client.projects.count
30
- @client.projects.last.destroy
31
- count_after = @client.projects.count
32
-
33
- (count_before - count_after).should == 1
34
- end
35
- end
data/spec/roles_spec.rb DELETED
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Syncano::Resource::Role' do
4
- it 'should get roles' do
5
- roles = @client.roles.all
6
- roles.count.should_not == 0
7
-
8
- roles.each do |role|
9
- role.id.should_not be_nil
10
- role[:name].should_not be_nil
11
- end
12
- end
13
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Using resources through sync api' do
4
- it 'should create new project in Syncano' do
5
- count_before = @sync_client.projects.count
6
- @sync_client.projects.create(name: 'Test project', description: 'Just testing')
7
- count_after = @sync_client.projects.count
8
-
9
- (count_after - count_before).should == 1
10
- @sync_client.projects.last[:name].should == 'Test project'
11
- end
12
-
13
- it 'should get projects' do
14
- projects = @sync_client.projects.all
15
- projects.each do |project|
16
- project.id.should_not be_nil
17
- project[:name].should_not be_nil
18
- end
19
- end
20
-
21
- it 'should get one project' do
22
- projects = @sync_client.projects.all
23
-
24
- project = @sync_client.projects.find(projects.last.id)
25
- project[:name].should == projects.last[:name]
26
- end
27
-
28
- it 'should destroy project' do
29
- count_before = @sync_client.projects.count
30
- @sync_client.projects.last.destroy
31
- count_after = @sync_client.projects.count
32
-
33
- (count_before - count_after).should == 1
34
- end
35
- end
data/spec/syncano_spec.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Syncano do
4
- it 'should allow to init a client' do
5
- expect(@client).to be_a(Syncano::Clients::Rest)
6
- @client.instance_name.should == @syncano_instance_name
7
- @client.api_key.should == @syncano_api_key
8
- end
9
- end