vodka 0.1.0 → 0.1.2

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 (58) hide show
  1. data/.travis.yml +2 -0
  2. data/README.md +33 -10
  3. data/lib/party.rb +2 -1
  4. data/lib/vodka/client.rb +0 -2
  5. data/lib/vodka/client/middleware/signed_request.rb +1 -1
  6. data/lib/vodka/client/middleware/signed_response.rb +1 -1
  7. data/lib/vodka/configuration.rb +27 -12
  8. data/lib/vodka/server.rb +3 -0
  9. data/lib/vodka/server/controllers/vodka_controller.rb +1 -5
  10. data/lib/vodka/server/handlers/resource.rb +6 -2
  11. data/lib/vodka/server/handlers/response.rb +10 -6
  12. data/lib/vodka/server/handlers/scaffold.rb +5 -35
  13. data/lib/vodka/server/middleware/signed_request.rb +6 -4
  14. data/lib/vodka/server/plugins/presentable.rb +24 -9
  15. data/lib/vodka/server/presenters/vodka_presenter.rb +23 -0
  16. data/lib/vodka/server/railtie.rb +13 -0
  17. data/lib/vodka/server/relation.rb +95 -0
  18. data/lib/vodka/server/response.rb +18 -7
  19. data/lib/vodka/version.rb +1 -1
  20. data/script/dummy_console +6 -0
  21. data/script/setup_db +2 -2
  22. data/script/show_logs +1 -1
  23. data/script/spec +5 -9
  24. data/script/start_server +2 -2
  25. data/script/stop_server +1 -1
  26. data/spec/client/article.rb +2 -0
  27. data/spec/client/author.rb +3 -0
  28. data/spec/client/comment.rb +4 -0
  29. data/spec/dummy/Gemfile +6 -5
  30. data/spec/dummy/Gemfile.lock +19 -4
  31. data/spec/dummy/app/controllers/articles_controller.rb +5 -0
  32. data/spec/dummy/app/controllers/vodka/authors_controller.rb +4 -0
  33. data/spec/dummy/app/controllers/vodka/comments_controller.rb +4 -0
  34. data/spec/dummy/app/models/article.rb +9 -2
  35. data/spec/dummy/app/models/author.rb +5 -0
  36. data/spec/dummy/app/models/comment.rb +12 -0
  37. data/spec/dummy/app/models/like.rb +9 -0
  38. data/spec/dummy/app/presenters/article_presenter.rb +9 -0
  39. data/spec/dummy/app/presenters/author_custom_presenter.rb +5 -0
  40. data/spec/dummy/app/presenters/comment_presenter.rb +13 -0
  41. data/spec/dummy/config/database.yml +3 -3
  42. data/spec/dummy/config/initializers/mongo_mapper_connection.rb +4 -0
  43. data/spec/dummy/config/initializers/vodka_setup.rb +1 -0
  44. data/spec/dummy/config/mongoid.yml +32 -0
  45. data/spec/dummy/config/routes.rb +4 -0
  46. data/spec/dummy/config/thin.yml +1 -1
  47. data/spec/dummy/db/migrate/20130217185353_create_articles.rb +1 -0
  48. data/spec/dummy/db/schema.rb +1 -0
  49. data/spec/dummy/db/seeds.rb +18 -1
  50. data/spec/her/extensions/paginated/paginate_spec.rb +32 -0
  51. data/spec/middleware/response_locale_spec.rb +2 -0
  52. data/spec/requests/relations_spec.rb +9 -0
  53. data/spec/spec_helper.rb +2 -1
  54. data/vodka.gemspec +1 -1
  55. metadata +23 -8
  56. data/lib/vodka/her/extensions/extended_orm.rb +0 -92
  57. data/lib/vodka/her/extensions/will_paginate.rb +0 -32
  58. data/spec/her/extensions/will_paginate/paginate_spec.rb +0 -16
@@ -0,0 +1,4 @@
1
+ config = YAML::load_file(Rails.root + 'config/mongoid.yml')[Rails.env]['sessions']['default']
2
+ host, port = *config['hosts'].first.split(?:)
3
+ MongoMapper.connection = Mongo::Connection.new(host, port)
4
+ MongoMapper.database = config['database']
@@ -1,4 +1,5 @@
1
1
  Vodka::Server.configure do |c|
2
2
  c.request_secret = '8089c2189321798bf60df6b8c01bb661fb585080'
3
3
  c.response_secret = '3ecb42ac23cd58994a6518971e7e31d2f4545e3c'
4
+ c.prefix = '/vodka/'
4
5
  end
@@ -0,0 +1,32 @@
1
+ development:
2
+ sessions:
3
+ default:
4
+ database: dummy_test
5
+ hosts:
6
+ - localhost:27017
7
+ options:
8
+ consistency: :strong
9
+ max_retries: 1
10
+ retry_interval: 0
11
+
12
+ test:
13
+ sessions:
14
+ default:
15
+ database: dummy_test
16
+ hosts:
17
+ - localhost:27017
18
+ options:
19
+ consistency: :strong
20
+ max_retries: 1
21
+ retry_interval: 0
22
+
23
+ production:
24
+ sessions:
25
+ default:
26
+ database: dummy_test
27
+ hosts:
28
+ - localhost:27017
29
+ options:
30
+ consistency: :strong
31
+ max_retries: 1
32
+ retry_interval: 0
@@ -2,6 +2,10 @@ Dummy::Application.routes.draw do
2
2
  namespace :vodka do
3
3
  resources :articles do
4
4
  collection{ get :hello }
5
+ resources :comments
5
6
  end
7
+ resources :authors
6
8
  end
9
+
10
+ resources :articles
7
11
  end
@@ -4,7 +4,7 @@ timeout: 30
4
4
  max_conns: 1024
5
5
  port: 3000
6
6
  max_persistent_conns: 512
7
- environment: test
7
+ environment: development
8
8
  servers: 1
9
9
  address: 0.0.0.0
10
10
  daemonize: true
@@ -2,6 +2,7 @@ class CreateArticles < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :articles do |t|
4
4
  t.string :title
5
+ t.string :author_id
5
6
 
6
7
  t.timestamps
7
8
  end
@@ -15,6 +15,7 @@ ActiveRecord::Schema.define(:version => 20130217185353) do
15
15
 
16
16
  create_table "articles", :force => true do |t|
17
17
  t.string "title"
18
+ t.string "author_id"
18
19
  t.datetime "created_at", :null => false
19
20
  t.datetime "updated_at", :null => false
20
21
  end
@@ -1 +1,18 @@
1
- 10.times{ Article.create(title: 'Whatever') }
1
+ Article.delete_all
2
+ ActiveRecord::Base.connection.execute('VACUUM')
3
+ ActiveRecord::Base.connection.execute('DELETE FROM SQLITE_SEQUENCE WHERE name="articles"')
4
+ Author.delete_all
5
+ Comment.delete_all
6
+
7
+ authors = 10.times.map{ Author.create(name: 'John Doe') }
8
+
9
+ 10.times do
10
+ article = Article.create(title: 'Whatever', author_id: authors.sample.id.to_s)
11
+ 5.times do
12
+ comment = Comment.create(article_id: article.id.to_s, author_id: authors.sample.id.to_s, body: 'Nice!')
13
+ 5.times do
14
+ comment.likes << Like.new(author_id: authors.sample.id.to_s)
15
+ end
16
+ comment.save
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vodka::Her::Extensions::Paginated do
4
+ describe '.paginate' do
5
+ it 'should return a collection with desired page, items per page and page info in metadata' do
6
+ total = Article.all.count
7
+ articles = Article.paginate(page: 2, per_page: 5)
8
+
9
+ articles.should be_instance_of(Vodka::Her::Extensions::PaginatedCollection)
10
+ articles.size.should == 5
11
+ articles.current_page.should == 2
12
+ articles.per_page.should == 5
13
+ articles.total_entries.should == total
14
+ end
15
+
16
+ it 'should work with where-conditions correctly' do
17
+ total = Article.all.count
18
+ articles = Article.where('id > ?', 1).where(title: 'Whatever').paginate(page: 1, per_page: 3)
19
+
20
+ articles.should be_instance_of(Vodka::Her::Extensions::PaginatedCollection)
21
+ articles.size.should == 3
22
+ articles.current_page.should == 1
23
+ articles.per_page.should == 3
24
+ articles.total_entries.should == total
25
+
26
+ articles.each do |article|
27
+ article.id.should > 1
28
+ article.title.should == 'Whatever'
29
+ end
30
+ end
31
+ end
32
+ end
@@ -8,5 +8,7 @@ describe Vodka::Client::Middleware::SignedRequest do
8
8
 
9
9
  I18n.locale = :ru
10
10
  Article.hello.metadata[:hello].should == 'Привет, мир!'
11
+
12
+ I18n.locale = :en
11
13
  end
12
14
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Nested resources" do
4
+ it 'should work' do
5
+ comments = Article.first.comments
6
+ comments.size.should > 0
7
+ comments.first.should be_instance_of(Comment)
8
+ end
9
+ end
@@ -5,13 +5,14 @@ require 'vodka/client'
5
5
 
6
6
  # Dummy Client
7
7
  require 'client/article'
8
+ require 'client/author'
9
+ require 'client/comment'
8
10
 
9
11
  Vodka::Client.configure do |c|
10
12
  c.api_url = 'http://0.0.0.0:3000/vodka'
11
13
  c.request_secret = '8089c2189321798bf60df6b8c01bb661fb585080'
12
14
  c.response_secret = '3ecb42ac23cd58994a6518971e7e31d2f4545e3c'
13
15
  end
14
- Vodka::Client.configure_her!
15
16
 
16
17
  RSpec.configure do |c|
17
18
  # Use color in STDOUT
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ['lib']
15
15
  gem.version = Vodka::VERSION
16
16
 
17
- gem.add_runtime_dependency 'her', '~> 0.4'
17
+ gem.add_runtime_dependency 'extended_her', '~> 0.5'
18
18
  gem.add_runtime_dependency 'multi_json', '~> 1.6.1'
19
19
  gem.add_development_dependency 'rspec', '~> 2.12.0'
20
20
  gem.add_development_dependency 'i18n', '~> 0.6.1'
metadata CHANGED
@@ -2,30 +2,30 @@
2
2
  name: vodka
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gregory Eremin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-18 00:00:00.000000000 Z
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: '0.5'
20
20
  none: false
21
- name: her
21
+ name: extended_her
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  requirement: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- version: '0.4'
28
+ version: '0.5'
29
29
  none: false
30
30
  - !ruby/object:Gem::Dependency
31
31
  version_requirements: !ruby/object:Gem::Requirement
@@ -100,8 +100,6 @@ files:
100
100
  - lib/vodka/client/middleware/signed_request.rb
101
101
  - lib/vodka/client/middleware/signed_response.rb
102
102
  - lib/vodka/configuration.rb
103
- - lib/vodka/her/extensions/extended_orm.rb
104
- - lib/vodka/her/extensions/will_paginate.rb
105
103
  - lib/vodka/server.rb
106
104
  - lib/vodka/server/controllers/vodka_controller.rb
107
105
  - lib/vodka/server/handlers/resource.rb
@@ -109,23 +107,37 @@ files:
109
107
  - lib/vodka/server/handlers/scaffold.rb
110
108
  - lib/vodka/server/middleware/signed_request.rb
111
109
  - lib/vodka/server/plugins/presentable.rb
110
+ - lib/vodka/server/presenters/vodka_presenter.rb
112
111
  - lib/vodka/server/railtie.rb
112
+ - lib/vodka/server/relation.rb
113
113
  - lib/vodka/server/response.rb
114
114
  - lib/vodka/version.rb
115
115
  - script/bundle_dummy
116
116
  - script/ci
117
+ - script/dummy_console
117
118
  - script/setup_db
118
119
  - script/show_logs
119
120
  - script/spec
120
121
  - script/start_server
121
122
  - script/stop_server
122
123
  - spec/client/article.rb
124
+ - spec/client/author.rb
125
+ - spec/client/comment.rb
123
126
  - spec/dummy/Gemfile
124
127
  - spec/dummy/Gemfile.lock
125
128
  - spec/dummy/Rakefile
126
129
  - spec/dummy/app/controllers/application_controller.rb
130
+ - spec/dummy/app/controllers/articles_controller.rb
127
131
  - spec/dummy/app/controllers/vodka/articles_controller.rb
132
+ - spec/dummy/app/controllers/vodka/authors_controller.rb
133
+ - spec/dummy/app/controllers/vodka/comments_controller.rb
128
134
  - spec/dummy/app/models/article.rb
135
+ - spec/dummy/app/models/author.rb
136
+ - spec/dummy/app/models/comment.rb
137
+ - spec/dummy/app/models/like.rb
138
+ - spec/dummy/app/presenters/article_presenter.rb
139
+ - spec/dummy/app/presenters/author_custom_presenter.rb
140
+ - spec/dummy/app/presenters/comment_presenter.rb
129
141
  - spec/dummy/config.ru
130
142
  - spec/dummy/config/application.rb
131
143
  - spec/dummy/config/boot.rb
@@ -137,12 +149,14 @@ files:
137
149
  - spec/dummy/config/initializers/backtrace_silencers.rb
138
150
  - spec/dummy/config/initializers/inflections.rb
139
151
  - spec/dummy/config/initializers/mime_types.rb
152
+ - spec/dummy/config/initializers/mongo_mapper_connection.rb
140
153
  - spec/dummy/config/initializers/secret_token.rb
141
154
  - spec/dummy/config/initializers/session_store.rb
142
155
  - spec/dummy/config/initializers/vodka_setup.rb
143
156
  - spec/dummy/config/initializers/wrap_parameters.rb
144
157
  - spec/dummy/config/locales/en.yml
145
158
  - spec/dummy/config/locales/ru.yml
159
+ - spec/dummy/config/mongoid.yml
146
160
  - spec/dummy/config/routes.rb
147
161
  - spec/dummy/config/thin.yml
148
162
  - spec/dummy/db/migrate/20130217185353_create_articles.rb
@@ -158,11 +172,12 @@ files:
158
172
  - spec/her/extensions/extended_orm/update_attribute_spec.rb
159
173
  - spec/her/extensions/extended_orm/update_attributes_spec.rb
160
174
  - spec/her/extensions/extended_orm/where_spec.rb
161
- - spec/her/extensions/will_paginate/paginate_spec.rb
175
+ - spec/her/extensions/paginated/paginate_spec.rb
162
176
  - spec/middleware/error_aware_spec.rb
163
177
  - spec/middleware/response_locale_spec.rb
164
178
  - spec/middleware/signed_request_spec.rb
165
179
  - spec/middleware/signed_response_spec.rb
180
+ - spec/requests/relations_spec.rb
166
181
  - spec/spec_helper.rb
167
182
  - vodka.gemspec
168
183
  homepage: https://github.com/magnolia-fan/vodka
@@ -1,92 +0,0 @@
1
- module Vodka
2
- module Her
3
- module Extensions
4
- module ExtendedOrm
5
- extend ActiveSupport::Concern
6
-
7
- module ClassMethods
8
- def create!(*args)
9
- resource = create(*args)
10
- unless resource.errors.empty?
11
- error = [resource.errors.keys.first, resource.errors.values.first].join(' ')
12
- raise Vodka::Client::ResourceException.new(error)
13
- end
14
-
15
- resource
16
- end
17
-
18
- def first
19
- resources = all(vodka_special_action: 'first')
20
- resource = resources.first
21
- resource.errors = resources.errors
22
- resource.metadata = resources.metadata
23
- resource
24
- end
25
-
26
- def last
27
- resources = all(vodka_special_action: 'last')
28
- resource = resources.first
29
- resource.errors = resources.errors
30
- resource.metadata = resources.metadata
31
- resource
32
- end
33
-
34
- def where(*args)
35
- @where_conditions ||= []
36
- @where_conditions << args
37
- self
38
- end
39
-
40
- def all(params = {})
41
- unless @where_conditions.nil?
42
- params[:vodka_special_where] = MultiJson.dump(@where_conditions)
43
- @where_conditions = nil
44
- end
45
- super(params)
46
- end
47
- end
48
-
49
- def update_attributes(params)
50
- params.each do |attribute, value|
51
- send(:"#{attribute}=", value)
52
- end
53
- save
54
- end
55
-
56
- def update_attributes!(params)
57
- update_attributes(params)
58
- unless errors.empty?
59
- error = [errors.keys.first, errors.values.first].join(' ')
60
- raise Vodka::Client::ResourceException.new(error)
61
- end
62
-
63
- self
64
- end
65
-
66
- def update_attribute(attribute, value)
67
- update_attributes(attribute => value)
68
- end
69
-
70
- def update_attribute!(attribute, value)
71
- update_attributes!(attribute => value)
72
- end
73
-
74
- def destroy!
75
- destroy
76
- raise Vodka::Client::FailedActionException.new('Destroy failed') if metadata[:vodka_action_success] == false
77
- self
78
- end
79
-
80
- def delete
81
- destroy
82
- end
83
-
84
- def delete!
85
- destroy!
86
- end
87
- end
88
- end
89
- end
90
- end
91
-
92
- Her::Model.send(:include, Vodka::Her::Extensions::ExtendedOrm)
@@ -1,32 +0,0 @@
1
- module Vodka
2
- module Her
3
- module Extensions
4
- module WillPaginate
5
- extend ActiveSupport::Concern
6
-
7
- module ClassMethods
8
- def paginate(params)
9
- response = all(params)
10
- PaginatedCollection.new(response, response.metadata, response.errors)
11
- end
12
- end
13
- end
14
-
15
- class PaginatedCollection < ::Her::Collection
16
- def current_page
17
- metadata[:page].to_i
18
- end
19
-
20
- def per_page
21
- metadata[:per_page].to_i
22
- end
23
-
24
- def total_entries
25
- metadata[:total].to_i
26
- end
27
- end
28
- end
29
- end
30
- end
31
-
32
- Her::Model.send(:include, Vodka::Her::Extensions::WillPaginate)
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Vodka::Her::Extensions::WillPaginate do
4
- describe '.paginate' do
5
- it 'should return a collection with desired page, items per page and page info in metadata' do
6
- total = Article.all.count
7
- articles = Article.paginate(page: 2, per_page: 5)
8
-
9
- articles.should be_instance_of(Vodka::Her::Extensions::PaginatedCollection)
10
- articles.size.should == 5
11
- articles.current_page.should == 2
12
- articles.per_page.should == 5
13
- articles.total_entries.should == total
14
- end
15
- end
16
- end