ability_engine 0.0.1

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 (64) hide show
  1. data/.gitignore +18 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +8 -0
  4. data/Gemfile.lock +118 -0
  5. data/LICENSE +22 -0
  6. data/README.md +57 -0
  7. data/Rakefile +2 -0
  8. data/ability_engine.gemspec +22 -0
  9. data/app/controllers/current_ability_controller.rb +7 -0
  10. data/config/routes.rb +3 -0
  11. data/lib/ability_engine.rb +6 -0
  12. data/lib/ability_engine/version.rb +3 -0
  13. data/spec/controllers/current_ability_controller_spec.rb +16 -0
  14. data/spec/dummy/.gitignore +1 -0
  15. data/spec/dummy/Rakefile +8 -0
  16. data/spec/dummy/app/assets/javascripts/application.js +47 -0
  17. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  18. data/spec/dummy/app/controllers/home_controller.rb +9 -0
  19. data/spec/dummy/app/helpers/application_helper.rb +13 -0
  20. data/spec/dummy/app/mailers/.gitkeep +0 -0
  21. data/spec/dummy/app/models/.gitkeep +0 -0
  22. data/spec/dummy/app/views/layouts/application.html.haml +22 -0
  23. data/spec/dummy/app/views/layouts/common/_agent_banner.html.haml +14 -0
  24. data/spec/dummy/app/views/layouts/common/_footer.html.haml +16 -0
  25. data/spec/dummy/app/views/layouts/common/_login_banner.html.haml +12 -0
  26. data/spec/dummy/app/views/layouts/common/_login_footer.html.haml +26 -0
  27. data/spec/dummy/app/views/layouts/devise/sessions.html.haml +18 -0
  28. data/spec/dummy/config.ru +7 -0
  29. data/spec/dummy/config/application.rb +50 -0
  30. data/spec/dummy/config/boot.rb +17 -0
  31. data/spec/dummy/config/environment.rb +5 -0
  32. data/spec/dummy/config/environments/development.rb +25 -0
  33. data/spec/dummy/config/environments/test.rb +39 -0
  34. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/spec/dummy/config/initializers/inflections.rb +10 -0
  36. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  37. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  38. data/spec/dummy/config/initializers/session_store.rb +8 -0
  39. data/spec/dummy/config/locales/devise.en.yml +56 -0
  40. data/spec/dummy/config/locales/en.yml +7 -0
  41. data/spec/dummy/config/routes.rb +67 -0
  42. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  43. data/spec/dummy/log/.gitkeep +0 -0
  44. data/spec/dummy/public/404.html +26 -0
  45. data/spec/dummy/public/422.html +26 -0
  46. data/spec/dummy/public/500.html +26 -0
  47. data/spec/dummy/public/favicon.ico +0 -0
  48. data/spec/dummy/public/login.html +1 -0
  49. data/spec/dummy/public/robots.txt +5 -0
  50. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  51. data/spec/dummy/public/stylesheets/application.css +4702 -0
  52. data/spec/dummy/public/stylesheets/home.css.css +0 -0
  53. data/spec/dummy/public/stylesheets/ie.css +122 -0
  54. data/spec/dummy/public/stylesheets/ie7.css +199 -0
  55. data/spec/dummy/public/stylesheets/ie8.css +14 -0
  56. data/spec/dummy/public/stylesheets/jquery/fileuploader.css +99 -0
  57. data/spec/dummy/public/stylesheets/jquery/ui-lightness/jquery.ui.autocomplete.css +70 -0
  58. data/spec/dummy/public/stylesheets/jquery/ui-lightness/jquery.ui.datepicker.css +1562 -0
  59. data/spec/dummy/public/stylesheets/jquery/ui-lightness/jquery.ui.dialog.css +131 -0
  60. data/spec/dummy/public/stylesheets/users.css.css +0 -0
  61. data/spec/dummy/script/rails +6 -0
  62. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  63. data/spec/spec_helper.rb +39 -0
  64. metadata +221 -0
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use ree-1.8.7@ability-controller
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ability_engine.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rails', '>= 3.0.0'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,118 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ability_engine (0.0.1)
5
+ devise (>= 1.5.3)
6
+ railties (>= 3.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (3.2.6)
12
+ actionpack (= 3.2.6)
13
+ mail (~> 2.4.4)
14
+ actionpack (3.2.6)
15
+ activemodel (= 3.2.6)
16
+ activesupport (= 3.2.6)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.1)
20
+ rack (~> 1.4.0)
21
+ rack-cache (~> 1.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.1.3)
24
+ activemodel (3.2.6)
25
+ activesupport (= 3.2.6)
26
+ builder (~> 3.0.0)
27
+ activerecord (3.2.6)
28
+ activemodel (= 3.2.6)
29
+ activesupport (= 3.2.6)
30
+ arel (~> 3.0.2)
31
+ tzinfo (~> 0.3.29)
32
+ activeresource (3.2.6)
33
+ activemodel (= 3.2.6)
34
+ activesupport (= 3.2.6)
35
+ activesupport (3.2.6)
36
+ i18n (~> 0.6)
37
+ multi_json (~> 1.0)
38
+ arel (3.0.2)
39
+ bcrypt-ruby (3.0.1)
40
+ builder (3.0.0)
41
+ devise (2.1.2)
42
+ bcrypt-ruby (~> 3.0)
43
+ orm_adapter (~> 0.1)
44
+ railties (~> 3.1)
45
+ warden (~> 1.2.1)
46
+ diff-lcs (1.1.3)
47
+ erubis (2.7.0)
48
+ hike (1.2.1)
49
+ i18n (0.6.0)
50
+ journey (1.0.4)
51
+ json (1.7.3)
52
+ mail (2.4.4)
53
+ i18n (>= 0.4.0)
54
+ mime-types (~> 1.16)
55
+ treetop (~> 1.4.8)
56
+ mime-types (1.19)
57
+ multi_json (1.3.6)
58
+ orm_adapter (0.3.0)
59
+ polyglot (0.3.3)
60
+ rack (1.4.1)
61
+ rack-cache (1.2)
62
+ rack (>= 0.4)
63
+ rack-ssl (1.3.2)
64
+ rack
65
+ rack-test (0.6.1)
66
+ rack (>= 1.0)
67
+ rails (3.2.6)
68
+ actionmailer (= 3.2.6)
69
+ actionpack (= 3.2.6)
70
+ activerecord (= 3.2.6)
71
+ activeresource (= 3.2.6)
72
+ activesupport (= 3.2.6)
73
+ bundler (~> 1.0)
74
+ railties (= 3.2.6)
75
+ railties (3.2.6)
76
+ actionpack (= 3.2.6)
77
+ activesupport (= 3.2.6)
78
+ rack-ssl (~> 1.3.2)
79
+ rake (>= 0.8.7)
80
+ rdoc (~> 3.4)
81
+ thor (>= 0.14.6, < 2.0)
82
+ rake (0.9.2.2)
83
+ rdoc (3.12)
84
+ json (~> 1.4)
85
+ rspec (2.10.0)
86
+ rspec-core (~> 2.10.0)
87
+ rspec-expectations (~> 2.10.0)
88
+ rspec-mocks (~> 2.10.0)
89
+ rspec-core (2.10.1)
90
+ rspec-expectations (2.10.0)
91
+ diff-lcs (~> 1.1.3)
92
+ rspec-mocks (2.10.1)
93
+ rspec-rails (2.10.1)
94
+ actionpack (>= 3.0)
95
+ activesupport (>= 3.0)
96
+ railties (>= 3.0)
97
+ rspec (~> 2.10.0)
98
+ sprockets (2.1.3)
99
+ hike (~> 1.2)
100
+ rack (~> 1.0)
101
+ tilt (~> 1.1, != 1.3.0)
102
+ thor (0.15.4)
103
+ tilt (1.3.3)
104
+ treetop (1.4.10)
105
+ polyglot
106
+ polyglot (>= 0.3.1)
107
+ tzinfo (0.3.33)
108
+ warden (1.2.1)
109
+ rack (>= 1.0)
110
+
111
+ PLATFORMS
112
+ ruby
113
+
114
+ DEPENDENCIES
115
+ ability_engine!
116
+ rails (>= 3.0.0)
117
+ rspec
118
+ rspec-rails
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Siebert Lubbe
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # AbilityEngine
2
+
3
+ AbilityEngine is a Ruby on Rails engine that provides the
4
+ current_ability CanCan (https://github.com/ryanb/cancan/)
5
+ object through a controller action as json:
6
+
7
+ http://<your-server>/ability_engine/current_ability
8
+
9
+ This is very handy when you need to expose the current_ability to,
10
+ for example, a browser client.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'ability_engine'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install ability_engine
25
+
26
+ ## Requirements
27
+
28
+ AbilityEngine expects a current_ability object to be available
29
+ in your applications controller scope. This is provided by
30
+ CanCan's Ability class that defines all the abilities that
31
+ a particular user might have. Refer to cancan's documentation
32
+ for information on how to set this up.
33
+ https://github.com/ryanb/cancan/wiki
34
+
35
+ ## Usage
36
+
37
+ After you've installed ability_engine to your project you need
38
+ to your rails app, you need to add the following line to
39
+ config/routes.rb:
40
+
41
+ mount AbilityEngine::Engine, :at => "ability_engine"
42
+
43
+ This will mount the ability_engine routes under ability_engine/
44
+
45
+ If you now browse to
46
+
47
+ http://<your-server>/ability_engine/current_ability
48
+
49
+ you should see the current_ability object as json
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ability_engine/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Siebert Lubbe"]
6
+ gem.email = ["siebert.lubbe@googlemail.com"]
7
+ gem.description = %q{Exposes cancan current_ability as json through a rails engine controller}
8
+ gem.summary = %q{Exposes cancan current_ability as json through a rails engine controller}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "ability_engine"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = AbilityEngine::VERSION
17
+
18
+ gem.add_development_dependency "rspec"
19
+ gem.add_development_dependency "rspec-rails"
20
+ gem.add_dependency "railties", ">= 3.0.0"
21
+ end
22
+
@@ -0,0 +1,7 @@
1
+ class CurrentAbilityController < ApplicationController
2
+
3
+ def show
4
+ render :json => current_ability.to_json
5
+ end
6
+
7
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ AbilityEngine::Engine.routes.draw do
2
+ get "/current_ability" => "current_ability#show"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "ability_engine/version"
2
+
3
+ module AbilityEngine
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module AbilityEngine
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe CurrentAbilityController do
4
+
5
+ describe "GET 'show'" do
6
+ it "return the current_ability class in json format" do
7
+ rules_json = {:rules => ['rule1', 'rule2']}.to_json
8
+ controller.should_receive(:current_ability).and_return(mock(:current_ability, :to_json => rules_json))
9
+ get 'show', {:use_route => :ability_engine_engine}
10
+ response.body.should == rules_json
11
+ response.should be_success
12
+ end
13
+ end
14
+
15
+ end
16
+
@@ -0,0 +1 @@
1
+ log/*.log
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
8
+
@@ -0,0 +1,47 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require jquery-ui
10
+ //= require ./namespace
11
+ //= require_tree .
12
+
13
+ ns('REA.helpers', function (nsHelpers) {
14
+
15
+ nsHelpers.applicationHelper = {
16
+
17
+ getInternetExplorerVersion: function () {
18
+ var rv = -1; // Return value assumes failure.
19
+ if (nsHelpers.applicationHelper.appName() === 'Microsoft Internet Explorer') {
20
+ var ua = nsHelpers.applicationHelper.userAgent();
21
+ var re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");
22
+ if (re.exec(ua) !== null) {
23
+ rv = parseFloat(RegExp.$1);
24
+ }
25
+ }
26
+ return rv;
27
+ },
28
+
29
+ userAgent: function () {
30
+ return navigator.userAgent;
31
+ },
32
+
33
+ appName: function () {
34
+ return navigator.appName;
35
+ },
36
+
37
+ isIE7: function () {
38
+ var ieVersion = nsHelpers.applicationHelper.getInternetExplorerVersion();
39
+ return ieVersion >= 7.0 && ieVersion < 8.0;
40
+ },
41
+
42
+ isIE: function () {
43
+ return nsHelpers.applicationHelper.getInternetExplorerVersion() > 0;
44
+ }
45
+
46
+ };
47
+ });
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,9 @@
1
+ class HomeController < ApplicationController
2
+
3
+ before_filter :authenticate_cp_user!
4
+
5
+ def index
6
+ render :text => "This is the home contoller, index method"
7
+ end
8
+
9
+ end
@@ -0,0 +1,13 @@
1
+ module ApplicationHelper
2
+ def flash_helper
3
+ f_names = [:notice, :warning, :message, :error, :alert]
4
+ fl = ''
5
+ for name in f_names
6
+ if flash[name].present?
7
+ fl = fl + "<div class=\"#{name}\">#{h(flash[name])}</div>"
8
+ end
9
+ flash[name] = nil
10
+ end
11
+ fl.html_safe
12
+ end
13
+ end
File without changes
File without changes
@@ -0,0 +1,22 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title Agent Administration - realestate.com.au
5
+ != stylesheet_link_tag "auth"
6
+ /[if IE ]
7
+ = stylesheet_link_tag 'auth_ie'
8
+ /[if gt IE 7]
9
+ = stylesheet_link_tag 'auth_ie8'
10
+ != javascript_include_tag "application"
11
+ != csrf_meta_tags
12
+ %body
13
+ = render :partial => "layouts/common/agent_banner"
14
+ #wrapper
15
+ #container
16
+ #left-col
17
+ #right-col
18
+ = yield
19
+ .clear
20
+ = render :partial => "layouts/common/footer"
21
+
22
+ = yield :scripts
@@ -0,0 +1,14 @@
1
+ #agent-banner
2
+ .logo= image_tag('/auth/images/admin-mode-logo.png')
3
+ #client-controls
4
+ %ul
5
+ - if cp_user_signed_in?
6
+ %li.username
7
+ = current_cp_user.first_name
8
+ = current_cp_user.last_name
9
+
10
+ %li.action-point
11
+ = link_to "Contact", "http://www.realestate.com.au/contact-us", :target => "_blank"
12
+ - if cp_user_signed_in?
13
+ %li.action-point
14
+ = link_to "Logout", destroy_cp_user_session_path