towsta 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/Rakefile +3 -0
  2. data/lib/towsta/envs/development.rb +7 -0
  3. data/lib/towsta/envs/production.rb +13 -0
  4. data/lib/towsta/envs/test.rb +5 -0
  5. data/lib/towsta/kinds/boolean.rb +2 -1
  6. data/lib/towsta/kinds/formated.rb +0 -4
  7. data/lib/towsta/kinds/gallery.rb +2 -3
  8. data/lib/towsta/kinds/money.rb +6 -0
  9. data/lib/towsta/kinds/multiple.rb +3 -10
  10. data/lib/towsta/kinds/user.rb +6 -8
  11. data/lib/towsta/kinds/vertical.rb +5 -9
  12. data/lib/towsta/memory.rb +2 -4
  13. data/lib/towsta/sinatra_extension.rb +1 -1
  14. data/lib/towsta/synchronizer.rb +29 -32
  15. data/lib/towsta/version.rb +1 -1
  16. data/lib/towsta/vertical-core/attributes.rb +52 -0
  17. data/lib/towsta/vertical-core/base.rb +24 -0
  18. data/lib/towsta/vertical-core/crud.rb +41 -0
  19. data/lib/towsta/vertical-core/locales.rb +21 -0
  20. data/lib/towsta/vertical-core/mail.rb +17 -0
  21. data/lib/towsta/vertical-core/references.rb +44 -0
  22. data/lib/towsta/vertical.rb +19 -134
  23. data/lib/towsta.rb +9 -21
  24. data/spec/kinds/boolean_spec.rb +54 -0
  25. data/spec/kinds/date_spec.rb +37 -0
  26. data/spec/kinds/datetime_spec.rb +37 -0
  27. data/spec/kinds/gallery_spec.rb +43 -0
  28. data/spec/kinds/image_spec.rb +39 -0
  29. data/spec/kinds/integer_spec.rb +33 -0
  30. data/spec/kinds/list_spec.rb +37 -0
  31. data/spec/kinds/main_spec.rb +24 -0
  32. data/spec/kinds/money_spec.rb +37 -0
  33. data/spec/kinds/multiple_spec.rb +41 -0
  34. data/spec/kinds/user_spec.rb +41 -0
  35. data/spec/kinds/vertical_spec.rb +41 -0
  36. data/spec/kinds/video_spec.rb +37 -0
  37. data/spec/spec_helper.rb +9 -0
  38. data/spec/synchronizer/base_spec.rb +6 -0
  39. data/spec/synchronizer/cache_string_spec.rb +25 -0
  40. data/spec/synchronizer/has_secret_spec.rb +25 -0
  41. data/spec/synchronizer/parse_json_spec.rb +26 -0
  42. data/spec/synchronizer/populate_verticals_spec.rb +25 -0
  43. data/spec/synchronizer/populate_verticals_spec.rb~ +25 -0
  44. data/spec/synchronizer/remote_string_spec.rb +25 -0
  45. data/spec/synchronizer/solve_params_spec.rb +28 -0
  46. data/spec/synchronizer/validate_response_spec.rb +25 -0
  47. data/spec/synchronizer/validate_secret_spec.rb +25 -0
  48. data/spec/towsta_spec.rb +7 -0
  49. data/spec/vertical/vertical_spec.rb +17 -0
  50. data/spec/webmock.json +1 -0
  51. data/towsta.gemspec +19 -13
  52. metadata +90 -16
  53. data/lib/towsta/string_extension.rb +0 -5
@@ -0,0 +1,37 @@
1
+ describe Towsta::Kinds::VideoKind do
2
+
3
+ let(:input) {{id: '2PuD3XrF9Hg', source: 'YouTube'}}
4
+
5
+ let(:video) {Cameraman::VideoReference.new input}
6
+
7
+ context 'when sets with string' do
8
+
9
+ subject {Towsta::Kinds::VideoKind.new input.to_json}
10
+
11
+ #its(:get) {should == video}
12
+
13
+ its(:export) {should == input.to_json}
14
+
15
+ end
16
+
17
+ context 'when sets with a bad string' do
18
+
19
+ subject {Towsta::Kinds::VideoKind.new 'Bad String'}
20
+
21
+ its(:get) {should be_nil}
22
+
23
+ its(:export) {should be_blank}
24
+
25
+ end
26
+
27
+ context 'when sets with a User' do
28
+
29
+ subject {Towsta::Kinds::VideoKind.new video}
30
+
31
+ its(:get) {should == video}
32
+
33
+ its(:export) {should == input.to_json}
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,9 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'rspec'
4
+ require 'towsta'
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ config.formatter = 'documentation'
9
+ end
@@ -0,0 +1,6 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ it {should respond_to(:params, :cache, :response, :status)}
4
+
5
+ end
6
+
@@ -0,0 +1,25 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ describe '#cache_string' do
4
+
5
+ subject {Towsta::Synchronizer.new}
6
+
7
+ context 'when cache is set' do
8
+
9
+ before(:each) {subject.cache = '{"status":"true"}'}
10
+
11
+ its(:cache_string) {should be_true}
12
+
13
+ end
14
+
15
+ context 'when cache is nil' do
16
+
17
+ before(:each) {subject.cache = nil}
18
+
19
+ its(:cache_string) {should_not be_true}
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ describe '#has_secret' do
4
+
5
+ subject {Towsta::Synchronizer.new}
6
+
7
+ context 'when secret is set' do
8
+
9
+ before(:each) {Towsta.secret = 'somesecretstring'}
10
+
11
+ its(:has_secret) {should be_true}
12
+
13
+ end
14
+
15
+ context 'when secret is nil' do
16
+
17
+ before(:each) {Towsta.secret = nil}
18
+
19
+ its(:has_secret) {should_not be_true}
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,26 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ describe "#parse_json" do
4
+
5
+ subject {Towsta::Synchronizer.new}
6
+
7
+ context 'when parse a valid response' do
8
+
9
+ before(:each) {subject.response = {lorem: 'ipsum'}.to_json}
10
+
11
+ its(:parse_json) {should be_true}
12
+
13
+ end
14
+
15
+ context 'when parse a bad response' do
16
+
17
+ before(:each) {subject.response = 'Bad Response'}
18
+
19
+ its(:parse_json) {should_not be_true}
20
+
21
+ end
22
+
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,25 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ before :all do
4
+ Net::HTTP.stub(:start).and_return(File.read('./spec/webmock.json'))
5
+ Towsta::Vertical.clear
6
+ Towsta::Synchronizer.new(params: {}, request: :all)
7
+ end
8
+
9
+ describe '#create_verticals' do
10
+
11
+ it 'creates User class' do
12
+ Object.const_defined?(:User).should be_true
13
+ end
14
+
15
+ end
16
+
17
+ describe '#populate_verticals' do
18
+
19
+ it 'populates Users' do
20
+ User.all.should_not be_empty
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ before :all do
4
+ Net::HTTP.stub(:start).and_return(File.read('./spec/webmock.json'))
5
+ Towsta::Vertical.clear
6
+ Towsta::Synchronizer.new(params: {Carro: {all: true}}, request: :all)
7
+ end
8
+
9
+ describe '#create_verticals' do
10
+
11
+ it 'creates User class' do
12
+ Object.const_defined?(:User).should be_true
13
+ end
14
+
15
+ end
16
+
17
+ describe '#populate_verticals' do
18
+
19
+ it 'populates Users' do
20
+ User.all.should_not be_empty
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ describe '#remote_string' do
4
+
5
+ subject {Towsta::Synchronizer.new}
6
+
7
+ context 'when towsta responds correctly' do
8
+
9
+ before(:all) {Net::HTTP.stub(:start).and_return(File.read('./spec/webmock.json'))}
10
+
11
+ its(:remote_string) {should be_true}
12
+
13
+ end
14
+
15
+ context 'when response fails' do
16
+
17
+ before(:all) {Net::HTTP.stub(:start).and_raise('Something wrong with towsta')}
18
+
19
+ its(:remote_string) {should_not be_true}
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,28 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ describe "#solve_params" do
4
+
5
+ subject{ Towsta::Synchronizer.new}
6
+
7
+ let(:input) {{lorem: 'ipsum'}}
8
+
9
+ context 'when Towsta.global is nil' do
10
+
11
+ it 'returns the param itself' do
12
+ subject.send(:solve_params, input).should == input
13
+ end
14
+
15
+ end
16
+
17
+ context 'when Towsta.global is set' do
18
+
19
+ it 'merges with params' do
20
+ Towsta.global = {lorem: 'another ipsum', dolor: 'sit'}
21
+ subject.send(:solve_params, input).should == {lorem: 'ipsum', dolor: 'sit'}
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,25 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ describe '#validate_response' do
4
+
5
+ subject {Towsta::Synchronizer.new}
6
+
7
+ context 'when response is valid' do
8
+
9
+ before(:each) {subject.response = '{"status":"true"}'}
10
+
11
+ its(:validate_response) {should be_true}
12
+
13
+ end
14
+
15
+ context 'when response is invalid' do
16
+
17
+ before(:each) {subject.response = ''}
18
+
19
+ its(:validate_response) {should_not be_true}
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ describe Towsta::Synchronizer do
2
+
3
+ describe '#validate_secret' do
4
+
5
+ subject {Towsta::Synchronizer.new}
6
+
7
+ context 'when response is valid' do
8
+
9
+ before(:each) {subject.response = '{"status":"true"}'}
10
+
11
+ its(:validate_secret) {should be_true}
12
+
13
+ end
14
+
15
+ context 'when response is invalid' do
16
+
17
+ before(:each) {subject.response = ' '}
18
+
19
+ its(:validate_secret) {should_not be_true}
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Towsta do
4
+
5
+ it { should respond_to(:secret, :global, :author) }
6
+
7
+ end
@@ -0,0 +1,17 @@
1
+ describe Towsta::Vertical do
2
+
3
+ before :all do
4
+ Towsta::Vertical.clear
5
+ Towsta::Vertical.create name: 'Dog', slices: {id: 'integer', name: 'text'}
6
+ Towsta::Vertical.populate 'Dog', [{id: '1', name: 'Bandita'}]
7
+ end
8
+
9
+ it 'responds with an array to :all' do
10
+ Towsta::Vertical.all.class.should == Array
11
+ end
12
+
13
+ it 'populates the class' do
14
+ Dog.all.should_not be_empty
15
+ end
16
+
17
+ end
data/spec/webmock.json ADDED
@@ -0,0 +1 @@
1
+ {"revision":2,"name":"Site de Carros","users":[{"id":10,"nick":"Christian Mortaro","email":"mortaro@towsta.com"}],"structures":[{"name":"Carro","slices":{"id":"integer","author":"user","created_at":"datetime","updated_at":"datetime","model":"text"},"count":2}],"verticals":[{"horizontals":[{"id":3122,"author":10,"created_at":"01/30/2012 02:34","updated_at":"01/30/2012 02:34","model":"Fusca"},{"id":3038,"author":10,"created_at":"01/27/2012 00:33","updated_at":"01/27/2012 00:33","model":"Kadett"}],"id":271,"occurrences":[]}]}
data/towsta.gemspec CHANGED
@@ -3,6 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "towsta/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
+
6
7
  s.name = "towsta"
7
8
  s.version = Towsta::VERSION
8
9
  s.platform = Gem::Platform::RUBY
@@ -14,22 +15,27 @@ Gem::Specification.new do |s|
14
15
 
15
16
  s.rubyforge_project = "towsta"
16
17
 
17
- s.add_dependency("json")
18
- s.add_dependency("bresson")
19
- s.add_dependency("dalli")
20
- s.add_dependency("compass")
21
- s.add_dependency("haml")
22
- s.add_dependency("sinatra")
23
- s.add_dependency("cameraman")
24
- s.add_dependency("shotgun")
25
- s.add_dependency("sinatra-content-for")
26
- s.add_dependency("i18n-router")
27
- s.add_dependency("pony")
28
- s.add_dependency("coffee-script")
29
- s.add_dependency("therubyracer")
18
+ s.add_dependency "json"
19
+ s.add_dependency "bresson"
20
+ s.add_dependency "compass"
21
+ s.add_dependency "haml"
22
+ s.add_dependency "sinatra"
23
+ s.add_dependency "cameraman"
24
+ s.add_dependency "sinatra-content-for"
25
+ s.add_dependency "i18n-router"
26
+ s.add_dependency "pony"
27
+ s.add_dependency "coffee-script"
28
+ s.add_dependency "therubyracer"
29
+ s.add_dependency "active_support"
30
+ s.add_dependency 'dalli'
31
+
32
+ s.add_development_dependency 'rspec'
33
+ s.add_development_dependency 'shotgun'
34
+ s.add_development_dependency 'heroku'
30
35
 
31
36
  s.files = `git ls-files`.split("\n")
32
37
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
33
38
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
34
39
  s.require_paths = ["lib"]
40
+
35
41
  end
metadata CHANGED
@@ -3,10 +3,10 @@ name: towsta
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 1
7
- - 3
6
+ - 2
8
7
  - 0
9
- version: 1.3.0
8
+ - 0
9
+ version: 2.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mortaro
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-01-30 00:00:00 -02:00
17
+ date: 2012-02-13 00:00:00 -02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -44,7 +44,7 @@ dependencies:
44
44
  type: :runtime
45
45
  version_requirements: *id002
46
46
  - !ruby/object:Gem::Dependency
47
- name: dalli
47
+ name: compass
48
48
  prerelease: false
49
49
  requirement: &id003 !ruby/object:Gem::Requirement
50
50
  none: false
@@ -57,7 +57,7 @@ dependencies:
57
57
  type: :runtime
58
58
  version_requirements: *id003
59
59
  - !ruby/object:Gem::Dependency
60
- name: compass
60
+ name: haml
61
61
  prerelease: false
62
62
  requirement: &id004 !ruby/object:Gem::Requirement
63
63
  none: false
@@ -70,7 +70,7 @@ dependencies:
70
70
  type: :runtime
71
71
  version_requirements: *id004
72
72
  - !ruby/object:Gem::Dependency
73
- name: haml
73
+ name: sinatra
74
74
  prerelease: false
75
75
  requirement: &id005 !ruby/object:Gem::Requirement
76
76
  none: false
@@ -83,7 +83,7 @@ dependencies:
83
83
  type: :runtime
84
84
  version_requirements: *id005
85
85
  - !ruby/object:Gem::Dependency
86
- name: sinatra
86
+ name: cameraman
87
87
  prerelease: false
88
88
  requirement: &id006 !ruby/object:Gem::Requirement
89
89
  none: false
@@ -96,7 +96,7 @@ dependencies:
96
96
  type: :runtime
97
97
  version_requirements: *id006
98
98
  - !ruby/object:Gem::Dependency
99
- name: cameraman
99
+ name: sinatra-content-for
100
100
  prerelease: false
101
101
  requirement: &id007 !ruby/object:Gem::Requirement
102
102
  none: false
@@ -109,7 +109,7 @@ dependencies:
109
109
  type: :runtime
110
110
  version_requirements: *id007
111
111
  - !ruby/object:Gem::Dependency
112
- name: shotgun
112
+ name: i18n-router
113
113
  prerelease: false
114
114
  requirement: &id008 !ruby/object:Gem::Requirement
115
115
  none: false
@@ -122,7 +122,7 @@ dependencies:
122
122
  type: :runtime
123
123
  version_requirements: *id008
124
124
  - !ruby/object:Gem::Dependency
125
- name: sinatra-content-for
125
+ name: pony
126
126
  prerelease: false
127
127
  requirement: &id009 !ruby/object:Gem::Requirement
128
128
  none: false
@@ -135,7 +135,7 @@ dependencies:
135
135
  type: :runtime
136
136
  version_requirements: *id009
137
137
  - !ruby/object:Gem::Dependency
138
- name: i18n-router
138
+ name: coffee-script
139
139
  prerelease: false
140
140
  requirement: &id010 !ruby/object:Gem::Requirement
141
141
  none: false
@@ -148,7 +148,7 @@ dependencies:
148
148
  type: :runtime
149
149
  version_requirements: *id010
150
150
  - !ruby/object:Gem::Dependency
151
- name: pony
151
+ name: therubyracer
152
152
  prerelease: false
153
153
  requirement: &id011 !ruby/object:Gem::Requirement
154
154
  none: false
@@ -161,7 +161,7 @@ dependencies:
161
161
  type: :runtime
162
162
  version_requirements: *id011
163
163
  - !ruby/object:Gem::Dependency
164
- name: coffee-script
164
+ name: active_support
165
165
  prerelease: false
166
166
  requirement: &id012 !ruby/object:Gem::Requirement
167
167
  none: false
@@ -174,7 +174,7 @@ dependencies:
174
174
  type: :runtime
175
175
  version_requirements: *id012
176
176
  - !ruby/object:Gem::Dependency
177
- name: therubyracer
177
+ name: dalli
178
178
  prerelease: false
179
179
  requirement: &id013 !ruby/object:Gem::Requirement
180
180
  none: false
@@ -186,6 +186,45 @@ dependencies:
186
186
  version: "0"
187
187
  type: :runtime
188
188
  version_requirements: *id013
189
+ - !ruby/object:Gem::Dependency
190
+ name: rspec
191
+ prerelease: false
192
+ requirement: &id014 !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ segments:
198
+ - 0
199
+ version: "0"
200
+ type: :development
201
+ version_requirements: *id014
202
+ - !ruby/object:Gem::Dependency
203
+ name: shotgun
204
+ prerelease: false
205
+ requirement: &id015 !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ segments:
211
+ - 0
212
+ version: "0"
213
+ type: :development
214
+ version_requirements: *id015
215
+ - !ruby/object:Gem::Dependency
216
+ name: heroku
217
+ prerelease: false
218
+ requirement: &id016 !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ segments:
224
+ - 0
225
+ version: "0"
226
+ type: :development
227
+ version_requirements: *id016
189
228
  description: Simply integrates the towsta api
190
229
  email:
191
230
  - mortaro@towsta.com
@@ -201,6 +240,9 @@ files:
201
240
  - Rakefile
202
241
  - bin/towsta
203
242
  - lib/towsta.rb
243
+ - lib/towsta/envs/development.rb
244
+ - lib/towsta/envs/production.rb
245
+ - lib/towsta/envs/test.rb
204
246
  - lib/towsta/kinds/boolean.rb
205
247
  - lib/towsta/kinds/date.rb
206
248
  - lib/towsta/kinds/datetime.rb
@@ -222,10 +264,42 @@ files:
222
264
  - lib/towsta/login.rb
223
265
  - lib/towsta/memory.rb
224
266
  - lib/towsta/sinatra_extension.rb
225
- - lib/towsta/string_extension.rb
226
267
  - lib/towsta/synchronizer.rb
227
268
  - lib/towsta/version.rb
269
+ - lib/towsta/vertical-core/attributes.rb
270
+ - lib/towsta/vertical-core/base.rb
271
+ - lib/towsta/vertical-core/crud.rb
272
+ - lib/towsta/vertical-core/locales.rb
273
+ - lib/towsta/vertical-core/mail.rb
274
+ - lib/towsta/vertical-core/references.rb
228
275
  - lib/towsta/vertical.rb
276
+ - spec/kinds/boolean_spec.rb
277
+ - spec/kinds/date_spec.rb
278
+ - spec/kinds/datetime_spec.rb
279
+ - spec/kinds/gallery_spec.rb
280
+ - spec/kinds/image_spec.rb
281
+ - spec/kinds/integer_spec.rb
282
+ - spec/kinds/list_spec.rb
283
+ - spec/kinds/main_spec.rb
284
+ - spec/kinds/money_spec.rb
285
+ - spec/kinds/multiple_spec.rb
286
+ - spec/kinds/user_spec.rb
287
+ - spec/kinds/vertical_spec.rb
288
+ - spec/kinds/video_spec.rb
289
+ - spec/spec_helper.rb
290
+ - spec/synchronizer/base_spec.rb
291
+ - spec/synchronizer/cache_string_spec.rb
292
+ - spec/synchronizer/has_secret_spec.rb
293
+ - spec/synchronizer/parse_json_spec.rb
294
+ - spec/synchronizer/populate_verticals_spec.rb
295
+ - spec/synchronizer/populate_verticals_spec.rb~
296
+ - spec/synchronizer/remote_string_spec.rb
297
+ - spec/synchronizer/solve_params_spec.rb
298
+ - spec/synchronizer/validate_response_spec.rb
299
+ - spec/synchronizer/validate_secret_spec.rb
300
+ - spec/towsta_spec.rb
301
+ - spec/vertical/vertical_spec.rb
302
+ - spec/webmock.json
229
303
  - towsta.gemspec
230
304
  has_rdoc: true
231
305
  homepage: http://rubygems.org/gems/towsta
@@ -1,5 +0,0 @@
1
- class String
2
- def parameterize
3
- self.gsub(' ', '-').downcase.delete('^a-zA-Z0-9\-')
4
- end
5
- end