kojac 0.9.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +4 -0
  3. data/Gemfile +1 -1
  4. data/app/assets/javascripts/kojac.js +393 -125
  5. data/app/assets/javascripts/kojac_canjs.js +34 -34
  6. data/app/assets/javascripts/kojac_ember.js +110 -152
  7. data/app/controllers/{kojac_controller.rb → kojac_base_controller.rb} +18 -11
  8. data/app/policies/kojac_base_policy.rb +114 -0
  9. data/app/serializers/kojac_base_serializer.rb +35 -0
  10. data/kojac.gemspec +12 -10
  11. data/lib/kojac/app_serialize.rb +31 -29
  12. data/lib/kojac/concentric.rb +152 -0
  13. data/lib/kojac/kojac_policy.rb +70 -0
  14. data/lib/kojac/kojac_rails.rb +200 -49
  15. data/lib/kojac/version.rb +1 -1
  16. data/spec/can_cache_spec.js +19 -19
  17. data/spec/demo/.gitignore +16 -0
  18. data/spec/demo/.ruby-gemset +1 -0
  19. data/spec/demo/.ruby-version +1 -0
  20. data/spec/demo/Gemfile +59 -0
  21. data/spec/demo/Gemfile.lock +153 -0
  22. data/spec/demo/README.rdoc +15 -248
  23. data/spec/demo/Rakefile +25 -1
  24. data/spec/demo/app/{mailers/.gitkeep → assets/images/.keep} +0 -0
  25. data/spec/demo/app/assets/javascripts/application.js +3 -3
  26. data/spec/demo/app/controllers/application_controller.rb +6 -1
  27. data/spec/demo/app/{models/.gitkeep → controllers/concerns/.keep} +0 -0
  28. data/spec/demo/app/controllers/users_controller.rb +5 -0
  29. data/spec/demo/{lib/assets/.gitkeep → app/mailers/.keep} +0 -0
  30. data/spec/demo/{log/.gitkeep → app/models/.keep} +0 -0
  31. data/spec/demo/app/models/concerns/.keep +0 -0
  32. data/spec/demo/app/models/user.rb +36 -0
  33. data/spec/demo/app/policies/user_policy.rb +42 -0
  34. data/spec/demo/bin/bundle +3 -0
  35. data/spec/demo/bin/rails +4 -0
  36. data/spec/demo/bin/rake +4 -0
  37. data/spec/demo/config.ru +1 -1
  38. data/spec/demo/config/application.rb +14 -46
  39. data/spec/demo/config/application.yml +4 -0
  40. data/spec/demo/config/boot.rb +3 -9
  41. data/spec/demo/config/database.yml +6 -6
  42. data/spec/demo/config/environment.rb +4 -2
  43. data/spec/demo/config/environments/development.rb +11 -19
  44. data/spec/demo/config/environments/production.rb +40 -27
  45. data/spec/demo/config/environments/test.rb +13 -14
  46. data/spec/demo/config/initializers/concentric_config.rb +9 -0
  47. data/spec/demo/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/spec/demo/config/initializers/inflections.rb +6 -5
  49. data/spec/demo/config/initializers/initialize_kojac.rb +16 -0
  50. data/spec/demo/config/initializers/secret_token.rb +7 -2
  51. data/spec/demo/config/initializers/session_store.rb +0 -5
  52. data/spec/demo/config/initializers/wrap_parameters.rb +6 -6
  53. data/spec/demo/config/locales/en.yml +20 -2
  54. data/spec/demo/config/routes.rb +24 -24
  55. data/spec/demo/db/migrate/20131212034312_add_user.rb +14 -0
  56. data/spec/demo/db/migrate/20140107085351_add_owner_id.rb +5 -0
  57. data/spec/demo/db/schema.rb +28 -0
  58. data/spec/demo/db/seeds.rb +7 -0
  59. data/spec/demo/lib/assets/.keep +0 -0
  60. data/spec/demo/lib/tasks/.keep +0 -0
  61. data/spec/demo/log/.keep +0 -0
  62. data/spec/demo/public/404.html +43 -11
  63. data/spec/demo/public/422.html +43 -11
  64. data/spec/demo/public/500.html +43 -11
  65. data/spec/demo/public/robots.txt +5 -0
  66. data/spec/demo/spec/controllers/allowed_fields_spec.rb +171 -0
  67. data/spec/demo/spec/factories/users.rb +9 -0
  68. data/spec/demo/spec/features/concentric_spec.rb +63 -0
  69. data/spec/demo/spec/features/serialization_spec.rb +86 -0
  70. data/spec/demo/spec/spec_helper.rb +133 -0
  71. data/spec/demo/spec/spec_utils.rb +42 -0
  72. data/spec/demo/vendor/assets/javascripts/.keep +0 -0
  73. data/spec/demo/vendor/assets/stylesheets/.keep +0 -0
  74. data/spec/ember_factory_spec.js +1 -1
  75. data/spec/ember_model_spec.js +13 -3
  76. data/spec/ember_tojsono_spec.js +105 -0
  77. data/spec/error_handling_spec.js +90 -0
  78. data/spec/external/underscore_plus.js +318 -9
  79. data/spec/kojac_caching_spec.js +3 -1
  80. data/spec/kojac_ember_cache_spec.js +9 -0
  81. data/spec/kojac_mock_spec.js +4 -4
  82. data/spec/kojac_operations_spec.js +4 -4
  83. data/spec/local_provider_spec.js +184 -0
  84. data/spec/model_ring_spec.rb +2 -2
  85. data/spec/operation_include_spec.js +2 -2
  86. data/spec/run.html +34 -24
  87. data/spec/type_conversion_spec.js +38 -0
  88. data/vendor/assets/javascripts/jstorage.js +950 -0
  89. metadata +115 -129
  90. data/Gemfile.lock +0 -157
  91. data/app/serializers/default_kojac_serializer.rb +0 -10
  92. data/lib/kojac/ring_strong_parameters.rb +0 -195
  93. data/spec/.DS_Store +0 -0
  94. data/spec/demo/script/rails +0 -6
  95. data/spec/external/.DS_Store +0 -0
@@ -1,5 +1,5 @@
1
1
  Demo::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # The test environment is used exclusively to run your application's
5
5
  # test suite. You never need to work with it otherwise. Remember that
@@ -7,31 +7,30 @@ Demo::Application.configure do
7
7
  # and recreated between test runs. Don't rely on the data there!
8
8
  config.cache_classes = true
9
9
 
10
- # Configure static asset server for tests with Cache-Control for performance
11
- config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
13
14
 
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
15
+ # Configure static asset server for tests with Cache-Control for performance.
16
+ config.serve_static_assets = true
17
+ config.static_cache_control = "public, max-age=3600"
16
18
 
17
- # Show full error reports and disable caching
19
+ # Show full error reports and disable caching.
18
20
  config.consider_all_requests_local = true
19
21
  config.action_controller.perform_caching = false
20
22
 
21
- # Raise exceptions instead of rendering exception templates
23
+ # Raise exceptions instead of rendering exception templates.
22
24
  config.action_dispatch.show_exceptions = false
23
25
 
24
- # Disable request forgery protection in test environment
25
- config.action_controller.allow_forgery_protection = false
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
26
28
 
27
29
  # Tell Action Mailer not to deliver emails to the real world.
28
30
  # The :test delivery method accumulates sent emails in the
29
31
  # ActionMailer::Base.deliveries array.
30
32
  config.action_mailer.delivery_method = :test
31
33
 
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
34
-
35
- # Print deprecation notices to the stderr
34
+ # Print deprecation notices to the stderr.
36
35
  config.active_support.deprecation = :stderr
37
36
  end
@@ -0,0 +1,9 @@
1
+ ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)
2
+
3
+ SYSADMIN_RING = 0
4
+ ADMIN_RING = 10
5
+ USER_RING = 30
6
+ PUBLIC_RING = 100
7
+ Concentric.config = {
8
+ ring_names: { sysadmin: SYSADMIN_RING, admin: ADMIN_RING, user: USER_RING, public: PUBLIC_RING }
9
+ }
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -1,15 +1,16 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # Add new inflection rules using the following format
4
- # (all these examples are active by default):
5
- # ActiveSupport::Inflector.inflections do |inflect|
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
6
7
  # inflect.plural /^(ox)$/i, '\1en'
7
8
  # inflect.singular /^(ox)en/i, '\1'
8
9
  # inflect.irregular 'person', 'people'
9
10
  # inflect.uncountable %w( fish sheep )
10
11
  # end
11
- #
12
+
12
13
  # These inflection rules are supported but not enabled by default:
13
- # ActiveSupport::Inflector.inflections do |inflect|
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
14
15
  # inflect.acronym 'RESTful'
15
16
  # end
@@ -0,0 +1,16 @@
1
+ #ActiveSupport.on_load(:active_model_serializers) do
2
+ # # Disable for all serializers (except ArraySerializer)
3
+ # #ActiveModel::Serializer.root = false
4
+ #
5
+ # # Disable for ArraySerializer
6
+ # #ActiveModel::ArraySerializer.root = false
7
+ #end
8
+
9
+ #[Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass|
10
+ # klass.class_eval do
11
+ # def to_json(opts = {})
12
+ # MultiJson::use(:oj)
13
+ # MultiJson::dump(self, opts)
14
+ # end
15
+ # end
16
+ #end
@@ -1,7 +1,12 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # Your secret key for verifying the integrity of signed cookies.
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
4
  # If you change this key, all old signed cookies will become invalid!
5
+
5
6
  # Make sure the secret is at least 30 characters and all random,
6
7
  # no regular words or you'll be exposed to dictionary attacks.
7
- Demo::Application.config.secret_token = '3be2230ff43ce08d0d092bb0050e18ea53b7b126638562adc66568ed6b2271e509faa11f898f999d9757ff38f67c13d861f2cb5fc325844b981f18babaa5267b'
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure your secret_key_base is kept private
11
+ # if you're sharing your code publicly.
12
+ Demo::Application.config.secret_key_base = 'ece58c951835d6cdcc9b1ce850d805e6651709d60f66329f0d62c2a8d2e26b4e73cfe5b34963b9f398bcdc4a6a50f30196a7402af2b5185706cf86746a75f908'
@@ -1,8 +1,3 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  Demo::Application.config.session_store :cookie_store, key: '_demo_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
- # Demo::Application.config.session_store :active_record_store
@@ -1,14 +1,14 @@
1
1
  # Be sure to restart your server when you modify this file.
2
- #
2
+
3
3
  # This file contains settings for ActionController::ParamsWrapper which
4
4
  # is enabled by default.
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json]
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
9
  end
10
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
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -1,5 +1,23 @@
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.
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
3
21
 
4
22
  en:
5
23
  hello: "Hello world"
@@ -1,19 +1,22 @@
1
1
  Demo::Application.routes.draw do
2
- # The priority is based upon order of creation:
3
- # first created -> highest priority.
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+ # See how all your routes lay out with "rake routes".
4
4
 
5
- # Sample of regular route:
6
- # match 'products/:id' => 'catalog#view'
7
- # Keep in mind you can assign values other than :controller and :action
5
+ # You can have the root of your site routed with "root"
6
+ # root 'welcome#index'
7
+
8
+ post "kojac/receive.json" => "kojac#receive", :constraints => {:format => /json/}
9
+
10
+ # Example of regular route:
11
+ # get 'products/:id' => 'catalog#view'
8
12
 
9
- # Sample of named route:
10
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
- # This route can be invoked with purchase_url(:id => product.id)
13
+ # Example of named route that can be invoked with purchase_url(id: product.id)
14
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
12
15
 
13
- # Sample resource route (maps HTTP verbs to controller actions automatically):
16
+ # Example resource route (maps HTTP verbs to controller actions automatically):
14
17
  # resources :products
15
18
 
16
- # Sample resource route with options:
19
+ # Example resource route with options:
17
20
  # resources :products do
18
21
  # member do
19
22
  # get 'short'
@@ -25,34 +28,31 @@ Demo::Application.routes.draw do
25
28
  # end
26
29
  # end
27
30
 
28
- # Sample resource route with sub-resources:
31
+ # Example resource route with sub-resources:
29
32
  # resources :products do
30
33
  # resources :comments, :sales
31
34
  # resource :seller
32
35
  # end
33
36
 
34
- # Sample resource route with more complex sub-resources
37
+ # Example resource route with more complex sub-resources:
35
38
  # resources :products do
36
39
  # resources :comments
37
40
  # resources :sales do
38
- # get 'recent', :on => :collection
41
+ # get 'recent', on: :collection
39
42
  # end
40
43
  # end
41
44
 
42
- # Sample resource route within a namespace:
45
+ # Example resource route with concerns:
46
+ # concern :toggleable do
47
+ # post 'toggle'
48
+ # end
49
+ # resources :posts, concerns: :toggleable
50
+ # resources :photos, concerns: :toggleable
51
+
52
+ # Example resource route within a namespace:
43
53
  # namespace :admin do
44
54
  # # Directs /admin/products/* to Admin::ProductsController
45
55
  # # (app/controllers/admin/products_controller.rb)
46
56
  # resources :products
47
57
  # end
48
-
49
- # You can have the root of your site routed with "root"
50
- # just remember to delete public/index.html.
51
- # root :to => 'welcome#index'
52
-
53
- # See how all your routes lay out with "rake routes"
54
-
55
- # This is a legacy wild controller route that's not recommended for RESTful applications.
56
- # Note: This route will make all actions in every controller accessible via GET requests.
57
- # match ':controller(/:action(/:id))(.:format)'
58
58
  end
@@ -0,0 +1,14 @@
1
+ class AddUser < ActiveRecord::Migration
2
+ def change
3
+ create_table "users" do |t|
4
+ t.string "email", :null => false
5
+ t.datetime "created_at", :null => false
6
+ t.datetime "updated_at", :null => false
7
+ t.integer "ring"
8
+ t.string "first_name"
9
+ t.string "middle_names"
10
+ t.string "last_name"
11
+ t.date "dob"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ class AddOwnerId < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :owner_id, :integer
4
+ end
5
+ end
@@ -0,0 +1,28 @@
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 that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20140107085351) do
15
+
16
+ create_table "users", force: true do |t|
17
+ t.string "email", null: false
18
+ t.datetime "created_at", null: false
19
+ t.datetime "updated_at", null: false
20
+ t.integer "ring"
21
+ t.string "first_name"
22
+ t.string "middle_names"
23
+ t.string "last_name"
24
+ t.date "dob"
25
+ t.integer "owner_id"
26
+ end
27
+
28
+ 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)
File without changes
File without changes
File without changes
@@ -2,17 +2,48 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>The page you were looking for doesn't exist (404)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
16
47
  </style>
17
48
  </head>
18
49
 
@@ -22,5 +53,6 @@
22
53
  <h1>The page you were looking for doesn't exist.</h1>
23
54
  <p>You may have mistyped the address or the page may have moved.</p>
24
55
  </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
25
57
  </body>
26
58
  </html>
@@ -2,17 +2,48 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>The change you wanted was rejected (422)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
16
47
  </style>
17
48
  </head>
18
49
 
@@ -22,5 +53,6 @@
22
53
  <h1>The change you wanted was rejected.</h1>
23
54
  <p>Maybe you tried to change something you didn't have access to.</p>
24
55
  </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
25
57
  </body>
26
58
  </html>