embedded_associations 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +17 -0
  2. data/.travis.yml +5 -0
  3. data/Gemfile +14 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +67 -0
  6. data/Rakefile +1 -0
  7. data/embedded_associations.gemspec +21 -0
  8. data/lib/embedded_associations.rb +165 -0
  9. data/lib/embedded_associations/rails.rb +13 -0
  10. data/lib/embedded_associations/version.rb +3 -0
  11. data/spec/embedded_associations_spec.rb +324 -0
  12. data/spec/spec_helper.rb +16 -0
  13. data/spec/support/app/.gitignore +15 -0
  14. data/spec/support/app/Rakefile +7 -0
  15. data/spec/support/app/app/controllers/application_controller.rb +3 -0
  16. data/spec/support/app/app/controllers/posts_controller.rb +40 -0
  17. data/spec/support/app/app/models/account.rb +4 -0
  18. data/spec/support/app/app/models/category.rb +4 -0
  19. data/spec/support/app/app/models/comment.rb +6 -0
  20. data/spec/support/app/app/models/post.rb +8 -0
  21. data/spec/support/app/app/models/tag.rb +4 -0
  22. data/spec/support/app/app/models/user.rb +7 -0
  23. data/spec/support/app/app/serializers/account_serializer.rb +3 -0
  24. data/spec/support/app/app/serializers/category_serializer.rb +3 -0
  25. data/spec/support/app/app/serializers/comment_serializer.rb +5 -0
  26. data/spec/support/app/app/serializers/post_serializer.rb +8 -0
  27. data/spec/support/app/app/serializers/tag_serializer.rb +3 -0
  28. data/spec/support/app/app/serializers/user_serializer.rb +5 -0
  29. data/spec/support/app/config.ru +4 -0
  30. data/spec/support/app/config/application.rb +62 -0
  31. data/spec/support/app/config/boot.rb +6 -0
  32. data/spec/support/app/config/database.yml +11 -0
  33. data/spec/support/app/config/environment.rb +5 -0
  34. data/spec/support/app/config/environments/development.rb +37 -0
  35. data/spec/support/app/config/environments/production.rb +67 -0
  36. data/spec/support/app/config/environments/test.rb +37 -0
  37. data/spec/support/app/config/initializers/backtrace_silencers.rb +7 -0
  38. data/spec/support/app/config/initializers/inflections.rb +15 -0
  39. data/spec/support/app/config/initializers/mime_types.rb +5 -0
  40. data/spec/support/app/config/initializers/secret_token.rb +7 -0
  41. data/spec/support/app/config/initializers/session_store.rb +8 -0
  42. data/spec/support/app/config/initializers/wrap_parameters.rb +14 -0
  43. data/spec/support/app/config/locales/en.yml +5 -0
  44. data/spec/support/app/config/routes.rb +3 -0
  45. data/spec/support/app/db/migrate/20130225045501_create_posts.rb +10 -0
  46. data/spec/support/app/db/migrate/20130225045512_create_comments.rb +10 -0
  47. data/spec/support/app/db/migrate/20130225173707_create_users.rb +9 -0
  48. data/spec/support/app/db/migrate/20130225173717_create_accounts.rb +9 -0
  49. data/spec/support/app/db/migrate/20130226001629_create_tags.rb +9 -0
  50. data/spec/support/app/db/migrate/20130226001639_create_categories.rb +8 -0
  51. data/spec/support/app/db/schema.rb +59 -0
  52. data/spec/support/app/db/seeds.rb +7 -0
  53. data/spec/support/app/db/structure.sql +19 -0
  54. data/spec/support/app/lib/assets/.gitkeep +0 -0
  55. data/spec/support/app/lib/tasks/.gitkeep +0 -0
  56. data/spec/support/app/log/.gitkeep +0 -0
  57. data/spec/support/app/script/rails +6 -0
  58. data/spec/support/serialization_helpers.rb +18 -0
  59. metadata +168 -0
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ App::Application.config.secret_token = 'd510a778c49797a5a102daaff910582af5930ff8c11fc46cac4dac8ad1e69b6a5da23348f0b653d73f7699e5c12e9226afe3942938372f3ab1a80570354f1fb6'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ App::Application.config.session_store :cookie_store, key: '_app_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # App::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,3 @@
1
+ App::Application.routes.draw do
2
+ resources :posts
3
+ end
@@ -0,0 +1,10 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.references :user
6
+ t.references :category
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateComments < ActiveRecord::Migration
2
+ def change
3
+ create_table :comments do |t|
4
+ t.references :post
5
+ t.references :user
6
+ t.string :content
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+ t.string :email
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAccounts < ActiveRecord::Migration
2
+ def change
3
+ create_table :accounts do |t|
4
+ t.references :user
5
+ t.string :note
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateTags < ActiveRecord::Migration
2
+ def change
3
+ create_table :tags do |t|
4
+ t.references :post
5
+ t.string :name
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ class CreateCategories < ActiveRecord::Migration
2
+ def change
3
+ create_table :categories do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20130226001639) do
15
+
16
+ create_table "accounts", :force => true do |t|
17
+ t.integer "user_id"
18
+ t.string "note"
19
+ t.datetime "created_at", :null => false
20
+ t.datetime "updated_at", :null => false
21
+ end
22
+
23
+ create_table "categories", :force => true do |t|
24
+ t.string "name"
25
+ t.datetime "created_at", :null => false
26
+ t.datetime "updated_at", :null => false
27
+ end
28
+
29
+ create_table "comments", :force => true do |t|
30
+ t.integer "post_id"
31
+ t.integer "user_id"
32
+ t.string "content"
33
+ t.datetime "created_at", :null => false
34
+ t.datetime "updated_at", :null => false
35
+ end
36
+
37
+ create_table "posts", :force => true do |t|
38
+ t.string "title"
39
+ t.integer "user_id"
40
+ t.integer "category_id"
41
+ t.datetime "created_at", :null => false
42
+ t.datetime "updated_at", :null => false
43
+ end
44
+
45
+ create_table "tags", :force => true do |t|
46
+ t.integer "post_id"
47
+ t.string "name"
48
+ t.datetime "created_at", :null => false
49
+ t.datetime "updated_at", :null => false
50
+ end
51
+
52
+ create_table "users", :force => true do |t|
53
+ t.string "name"
54
+ t.string "email"
55
+ t.datetime "created_at", :null => false
56
+ t.datetime "updated_at", :null => false
57
+ end
58
+
59
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7
+ # Mayor.create(name: 'Emanuel', city: cities.first)
@@ -0,0 +1,19 @@
1
+ CREATE TABLE "accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer, "note" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
2
+ CREATE TABLE "categories" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
3
+ CREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "post_id" integer, "user_id" integer, "content" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
4
+ CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "user_id" integer, "category_id" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
5
+ CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
6
+ CREATE TABLE "tags" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "post_id" integer, "name" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
7
+ CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
8
+ CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
9
+ INSERT INTO schema_migrations (version) VALUES ('20130225045501');
10
+
11
+ INSERT INTO schema_migrations (version) VALUES ('20130225045512');
12
+
13
+ INSERT INTO schema_migrations (version) VALUES ('20130225173707');
14
+
15
+ INSERT INTO schema_migrations (version) VALUES ('20130225173717');
16
+
17
+ INSERT INTO schema_migrations (version) VALUES ('20130226001629');
18
+
19
+ INSERT INTO schema_migrations (version) VALUES ('20130226001639');
File without changes
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,18 @@
1
+ module SerializationHelpers
2
+
3
+ # helper to serialize in a format that would
4
+ # be passed to the controller from a request
5
+ # (e.g. from the client)
6
+ def serialize(model, root=false)
7
+ options = {}
8
+ options[:root] = false unless root
9
+ params = model.active_model_serializer.new(model, options).as_json
10
+ params[:id] = model.id if root
11
+ params
12
+ end
13
+
14
+ def serialize_array(arr)
15
+ arr.map(&method(:serialize))
16
+ end
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embedded_associations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gordon L. Hempton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>'
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ description: ActiveRecord controller-level support for embedded associations
31
+ email:
32
+ - ghempton@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .travis.yml
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - embedded_associations.gemspec
44
+ - lib/embedded_associations.rb
45
+ - lib/embedded_associations/rails.rb
46
+ - lib/embedded_associations/version.rb
47
+ - spec/embedded_associations_spec.rb
48
+ - spec/spec_helper.rb
49
+ - spec/support/app/.gitignore
50
+ - spec/support/app/Rakefile
51
+ - spec/support/app/app/controllers/application_controller.rb
52
+ - spec/support/app/app/controllers/posts_controller.rb
53
+ - spec/support/app/app/models/account.rb
54
+ - spec/support/app/app/models/category.rb
55
+ - spec/support/app/app/models/comment.rb
56
+ - spec/support/app/app/models/post.rb
57
+ - spec/support/app/app/models/tag.rb
58
+ - spec/support/app/app/models/user.rb
59
+ - spec/support/app/app/serializers/account_serializer.rb
60
+ - spec/support/app/app/serializers/category_serializer.rb
61
+ - spec/support/app/app/serializers/comment_serializer.rb
62
+ - spec/support/app/app/serializers/post_serializer.rb
63
+ - spec/support/app/app/serializers/tag_serializer.rb
64
+ - spec/support/app/app/serializers/user_serializer.rb
65
+ - spec/support/app/config.ru
66
+ - spec/support/app/config/application.rb
67
+ - spec/support/app/config/boot.rb
68
+ - spec/support/app/config/database.yml
69
+ - spec/support/app/config/environment.rb
70
+ - spec/support/app/config/environments/development.rb
71
+ - spec/support/app/config/environments/production.rb
72
+ - spec/support/app/config/environments/test.rb
73
+ - spec/support/app/config/initializers/backtrace_silencers.rb
74
+ - spec/support/app/config/initializers/inflections.rb
75
+ - spec/support/app/config/initializers/mime_types.rb
76
+ - spec/support/app/config/initializers/secret_token.rb
77
+ - spec/support/app/config/initializers/session_store.rb
78
+ - spec/support/app/config/initializers/wrap_parameters.rb
79
+ - spec/support/app/config/locales/en.yml
80
+ - spec/support/app/config/routes.rb
81
+ - spec/support/app/db/migrate/20130225045501_create_posts.rb
82
+ - spec/support/app/db/migrate/20130225045512_create_comments.rb
83
+ - spec/support/app/db/migrate/20130225173707_create_users.rb
84
+ - spec/support/app/db/migrate/20130225173717_create_accounts.rb
85
+ - spec/support/app/db/migrate/20130226001629_create_tags.rb
86
+ - spec/support/app/db/migrate/20130226001639_create_categories.rb
87
+ - spec/support/app/db/schema.rb
88
+ - spec/support/app/db/seeds.rb
89
+ - spec/support/app/db/structure.sql
90
+ - spec/support/app/lib/assets/.gitkeep
91
+ - spec/support/app/lib/tasks/.gitkeep
92
+ - spec/support/app/log/.gitkeep
93
+ - spec/support/app/script/rails
94
+ - spec/support/serialization_helpers.rb
95
+ homepage: https://github.com/GroupTalent/embedded_associations
96
+ licenses: []
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.23
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: ActiveRecord controller-level support for embedded associations
119
+ test_files:
120
+ - spec/embedded_associations_spec.rb
121
+ - spec/spec_helper.rb
122
+ - spec/support/app/.gitignore
123
+ - spec/support/app/Rakefile
124
+ - spec/support/app/app/controllers/application_controller.rb
125
+ - spec/support/app/app/controllers/posts_controller.rb
126
+ - spec/support/app/app/models/account.rb
127
+ - spec/support/app/app/models/category.rb
128
+ - spec/support/app/app/models/comment.rb
129
+ - spec/support/app/app/models/post.rb
130
+ - spec/support/app/app/models/tag.rb
131
+ - spec/support/app/app/models/user.rb
132
+ - spec/support/app/app/serializers/account_serializer.rb
133
+ - spec/support/app/app/serializers/category_serializer.rb
134
+ - spec/support/app/app/serializers/comment_serializer.rb
135
+ - spec/support/app/app/serializers/post_serializer.rb
136
+ - spec/support/app/app/serializers/tag_serializer.rb
137
+ - spec/support/app/app/serializers/user_serializer.rb
138
+ - spec/support/app/config.ru
139
+ - spec/support/app/config/application.rb
140
+ - spec/support/app/config/boot.rb
141
+ - spec/support/app/config/database.yml
142
+ - spec/support/app/config/environment.rb
143
+ - spec/support/app/config/environments/development.rb
144
+ - spec/support/app/config/environments/production.rb
145
+ - spec/support/app/config/environments/test.rb
146
+ - spec/support/app/config/initializers/backtrace_silencers.rb
147
+ - spec/support/app/config/initializers/inflections.rb
148
+ - spec/support/app/config/initializers/mime_types.rb
149
+ - spec/support/app/config/initializers/secret_token.rb
150
+ - spec/support/app/config/initializers/session_store.rb
151
+ - spec/support/app/config/initializers/wrap_parameters.rb
152
+ - spec/support/app/config/locales/en.yml
153
+ - spec/support/app/config/routes.rb
154
+ - spec/support/app/db/migrate/20130225045501_create_posts.rb
155
+ - spec/support/app/db/migrate/20130225045512_create_comments.rb
156
+ - spec/support/app/db/migrate/20130225173707_create_users.rb
157
+ - spec/support/app/db/migrate/20130225173717_create_accounts.rb
158
+ - spec/support/app/db/migrate/20130226001629_create_tags.rb
159
+ - spec/support/app/db/migrate/20130226001639_create_categories.rb
160
+ - spec/support/app/db/schema.rb
161
+ - spec/support/app/db/seeds.rb
162
+ - spec/support/app/db/structure.sql
163
+ - spec/support/app/lib/assets/.gitkeep
164
+ - spec/support/app/lib/tasks/.gitkeep
165
+ - spec/support/app/log/.gitkeep
166
+ - spec/support/app/script/rails
167
+ - spec/support/serialization_helpers.rb
168
+ has_rdoc: