markpercival-quickadmin 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008 Mark Percival
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # quickadmin
2
+
3
+ ### A merb slice that authenticates yaml defined OpenID users.
4
+
5
+ ____
6
+
7
+ ## About
8
+
9
+ Sometime you have an app that doesn't need full authentication, but you'd like to be able to
10
+ limit some pages to admins only. This is the story of that app...
11
+
12
+ ## Installation and use
13
+
14
+ Install the gem from the cloned repo
15
+
16
+ git clone git://github.com/markpercival/quickadmin.git
17
+ cd quickadmin
18
+ sudo rake install
19
+
20
+ Add the following to dependencies.rb
21
+
22
+ dependency 'quickadmin'
23
+
24
+ and then add this to router.rb
25
+
26
+ slice(:quickadmin, :name_prefix => nil, :path_prefix => "")
27
+
28
+ On any page you want to protect just create a before filter:
29
+
30
+ before :ensure_quickadmin, :only => [:index, :edit]
31
+
32
+ Add the authorized OpenID's to 'config/quickadmins.yaml'
33
+
34
+ - mpercival.com
35
+ - gweezelbur.com
36
+ - john.schult.us
37
+
38
+ It will auto-magically create the necessary 'config/quickadmins.yaml'
39
+ on the first load if you don't already have one.
40
+
41
+ ## Author and license info
42
+
43
+ - Official Repo: [http://github.com/markpercival/quickadmin](http://github.com/markpercival/quickadmin)
44
+ - © 2008, [Mark Percival](http://mpercival.com) - [mark@mpercival.com](mailto:mark@mpercival.com)
45
+ - Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php)
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ require 'merb-core'
5
+ require 'merb-core/tasks/merb'
6
+
7
+ GEM_NAME = "quickadmin"
8
+ AUTHOR = "Mark Percival"
9
+ EMAIL = "mark@mpercival.com"
10
+ HOMEPAGE = "http://github.com/markpercival/quickadmin"
11
+ SUMMARY = "Merb Slice adds quick DB'less OpenID authentication to your app"
12
+ GEM_VERSION = "1.0.3"
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.rubyforge_project = 'merb'
16
+ s.name = GEM_NAME
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = ["README.mdown", "LICENSE", 'TODO']
21
+ s.summary = SUMMARY
22
+ s.description = s.summary
23
+ s.author = AUTHOR
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+ s.add_dependency('merb-slices', '>= 1.0.3')
27
+ s.require_path = 'lib'
28
+ s.files = %w(LICENSE README.mdown Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
29
+ end
30
+
31
+ Rake::GemPackageTask.new(spec) do |pkg|
32
+ pkg.gem_spec = spec
33
+ end
34
+
35
+ desc "Install the gem"
36
+ task :install do
37
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
38
+ end
39
+
40
+ desc "Uninstall the gem"
41
+ task :uninstall do
42
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
43
+ end
44
+
45
+ desc "Create a gemspec file"
46
+ task :gemspec do
47
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
48
+ file.puts spec.to_ruby
49
+ end
50
+ end
51
+
52
+ require 'spec/rake/spectask'
53
+ require 'merb-core/test/tasks/spectasks'
54
+ desc 'Default: run spec examples'
55
+ task :default => 'spec'
data/TODO ADDED
@@ -0,0 +1,15 @@
1
+ TODO:
2
+
3
+ - Fix Quickadmin.description and Quickadmin.version
4
+ - Fix LICENSE with your name
5
+ - Fix Rakefile with your name and contact info
6
+ - Add your code to lib/quickadmin.rb
7
+ - Add your Merb rake tasks to lib/quickadmin/merbtasks.rb
8
+
9
+ Remove anything that you don't need:
10
+
11
+ - app/controllers/main.rb Quickadmin::Main controller
12
+ - app/views/layout/quickadmin.html.erb
13
+ - spec/controllers/main_spec.rb controller specs
14
+ - public/* any public files
15
+ - stubs/* any stub files
@@ -0,0 +1,6 @@
1
+ class Quickadmin::Application < Merb::Controller
2
+
3
+ controller_for_slice
4
+
5
+
6
+ end
@@ -0,0 +1,115 @@
1
+ require 'openid'
2
+ require 'openid/store/filesystem'
3
+ require 'openid/extensions/sreg'
4
+
5
+ class Quickadmin::Validates < Quickadmin::Application
6
+
7
+ def openid
8
+ if request.params[:'openid.mode']
9
+ response = consumer.complete(request.send(:query_params), "#{request.protocol}://#{request.host}" + request.path)
10
+ case response.status.to_s
11
+ when 'success'
12
+ # sreg_response = ::OpenID::SReg::Response.from_success_response(response)
13
+ Merb.logger.info("Quickadmin found - #{Quickadmin::Admin.find(response.identity_url)}")
14
+ if session[:quickadmin] = Quickadmin::Admin.find(response.identity_url)
15
+ redirect session[:return_to] ? session[:return_to] : '/'
16
+ else
17
+ render
18
+ end
19
+ when 'failure'
20
+ message[:notice] = "OpenID verification failed!"
21
+ render
22
+ when 'setup_needed'
23
+ message[:notice] = "You're OpenID needs setup!"
24
+ render
25
+ when 'cancel'
26
+ message[:notice] = "You cancelled the OpenID login!"
27
+ render
28
+ end
29
+
30
+ elsif identity_url = params[:openid_url]
31
+ begin
32
+ openid_request = consumer.begin(identity_url)
33
+ openid_reg = ::OpenID::SReg::Request.new
34
+ openid_reg.request_fields(required_reg_fields)
35
+ openid_request.add_extension(openid_reg)
36
+ redirect(openid_request.redirect_url("#{request.protocol}://#{request.host}", openid_callback_url))
37
+ rescue ::OpenID::OpenIDError => e
38
+ message[:notice] = "There was a failure communicating with the OpenID provider"
39
+ render
40
+ end
41
+ else
42
+ render
43
+ end
44
+ end
45
+
46
+ def logout
47
+ session[:quickadmin] = nil
48
+ redirect '/'
49
+ end
50
+
51
+ private
52
+
53
+ def openid_callback_url
54
+ "#{request.protocol}://#{request.host}#{Merb::Router.url(:openid)}"
55
+ end
56
+
57
+ # Overwrite the on_success! method with the required behavior for successful logins
58
+ #
59
+ # @api overwritable
60
+ def on_success!(response, sreg_response)
61
+ if user = find_user_by_identity_url(response.identity_url)
62
+ user
63
+ else
64
+ request.session[:'openid.url'] = response.identity_url
65
+ required_reg_fields.each do |f|
66
+ session[:"openid.#{f}"] = sreg_response.data[f] if sreg_response.data[f]
67
+ end if sreg_response
68
+ redirect!(Merb::Router.url(:signup))
69
+ end
70
+ end
71
+
72
+ # Overwrite the on_failure! method with the required behavior for failed logins
73
+ #
74
+ # @api overwritable
75
+ def on_failure!(response)
76
+ session.authentication.errors.clear!
77
+ session.authentication.errors.add(:openid, 'OpenID verification failed, maybe the provider is down? Or the session timed out')
78
+ nil
79
+ end
80
+
81
+ #
82
+ # @api overwritable
83
+ def on_setup_needed!(response)
84
+ request.session.authentication.errors.clear!
85
+ request.session.authentication.errors.add(:openid, 'OpenID does not seem to be configured correctly')
86
+ nil
87
+ end
88
+
89
+ #
90
+ # @api overwritable
91
+ def on_cancel!(response)
92
+ request.session.authentication.errors.clear!
93
+ request.session.authentication.errors.add(:openid, 'OpenID rejected our request')
94
+ nil
95
+ end
96
+
97
+ #
98
+ # @api overwritable
99
+ def required_reg_fields
100
+ ['email']
101
+ end
102
+
103
+ # Overwrite this method to set your store
104
+ #
105
+ # @api overwritable
106
+ def openid_store
107
+ ::OpenID::Store::Filesystem.new("#{Merb.root}/tmp/openid")
108
+ end
109
+
110
+ private
111
+ def consumer
112
+ @consumer ||= ::OpenID::Consumer.new(request.session, openid_store)
113
+ end
114
+
115
+ end
@@ -0,0 +1,64 @@
1
+ module Merb
2
+ module Quickadmin
3
+ module ApplicationHelper
4
+
5
+ # @param *segments<Array[#to_s]> Path segments to append.
6
+ #
7
+ # @return <String>
8
+ # A path relative to the public directory, with added segments.
9
+ def image_path(*segments)
10
+ public_path_for(:image, *segments)
11
+ end
12
+
13
+ # @param *segments<Array[#to_s]> Path segments to append.
14
+ #
15
+ # @return <String>
16
+ # A path relative to the public directory, with added segments.
17
+ def javascript_path(*segments)
18
+ public_path_for(:javascript, *segments)
19
+ end
20
+
21
+ # @param *segments<Array[#to_s]> Path segments to append.
22
+ #
23
+ # @return <String>
24
+ # A path relative to the public directory, with added segments.
25
+ def stylesheet_path(*segments)
26
+ public_path_for(:stylesheet, *segments)
27
+ end
28
+
29
+ # Construct a path relative to the public directory
30
+ #
31
+ # @param <Symbol> The type of component.
32
+ # @param *segments<Array[#to_s]> Path segments to append.
33
+ #
34
+ # @return <String>
35
+ # A path relative to the public directory, with added segments.
36
+ def public_path_for(type, *segments)
37
+ ::Quickadmin.public_path_for(type, *segments)
38
+ end
39
+
40
+ # Construct an app-level path.
41
+ #
42
+ # @param <Symbol> The type of component.
43
+ # @param *segments<Array[#to_s]> Path segments to append.
44
+ #
45
+ # @return <String>
46
+ # A path within the host application, with added segments.
47
+ def app_path_for(type, *segments)
48
+ ::Quickadmin.app_path_for(type, *segments)
49
+ end
50
+
51
+ # Construct a slice-level path.
52
+ #
53
+ # @param <Symbol> The type of component.
54
+ # @param *segments<Array[#to_s]> Path segments to append.
55
+ #
56
+ # @return <String>
57
+ # A path within the slice source (Gem), with added segments.
58
+ def slice_path_for(type, *segments)
59
+ ::Quickadmin.slice_path_for(type, *segments)
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,23 @@
1
+ class Quickadmin::Admin
2
+
3
+ def self.find(openid_url)
4
+ file = Merb.root / 'config' / 'quickadmins.yaml'
5
+ admins = YAML::load(File.open(file))
6
+ result = nil
7
+ admins.each do |a|
8
+ if normalize_url(a) == normalize_url(openid_url)
9
+ result = normalize_url(a)
10
+ end
11
+ break if result
12
+ end
13
+ result
14
+ end
15
+
16
+ private
17
+
18
+ def self.normalize_url(url)
19
+ url =~ /^(http(s)?:\/\/)?([^\/]+)/
20
+ $3
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5
+ <title>Fresh Quickadmin Slice</title>
6
+ <link href="<%= public_path_for :stylesheet, 'master.css' %>" type="text/css" charset="utf-8" rel="stylesheet" media="all" />
7
+ <script src="<%= public_path_for :javascript, 'master.js' %>" type="text/javascript" charset="utf-8"></script>
8
+ </head>
9
+ <!-- you can override this layout at slices/quickadmin/app/views/layout/quickadmin.html.erb -->
10
+ <body class="quickadmin-slice">
11
+ <div id="container">
12
+ <h1>Quickadmin</h1>
13
+ <div id="main"><%= catch_content :for_layout %></div>
14
+ </div>
15
+ </body>
16
+ </html>
@@ -0,0 +1,6 @@
1
+ %h3.notice= message[:notice]
2
+
3
+ = form :action => slice_url(:quickadmin, :openid) do
4
+ %label OpenID
5
+ %input{:name => 'openid_url'}
6
+ =submit "Login"
@@ -0,0 +1,100 @@
1
+ if defined?(Merb::Plugins)
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ load_dependency 'merb-slices'
6
+ Merb::Plugins.add_rakefiles "quickadmin/merbtasks", "quickadmin/slicetasks", "quickadmin/spectasks"
7
+
8
+ # Register the Slice for the current host application
9
+ Merb::Slices::register(__FILE__)
10
+
11
+ # Slice configuration - set this in a before_app_loads callback.
12
+ # By default a Slice uses its own layout, so you can swicht to
13
+ # the main application layout or no layout at all if needed.
14
+ #
15
+ # Configuration options:
16
+ # :layout - the layout to use; defaults to :quickadmin
17
+ # :mirror - which path component types to use on copy operations; defaults to all
18
+ Merb::Slices::config[:quickadmin][:layout] ||= :application
19
+
20
+ # All Slice code is expected to be namespaced inside a module
21
+
22
+
23
+ module Quickadmin
24
+ require 'quickadmin/mixins/ensure_quickadmin.rb'
25
+
26
+ # Slice metadata
27
+ self.description = "Quickadmin makes admin logins easy"
28
+ self.version = "1.0.3"
29
+ self.author = "Mark Percival"
30
+
31
+ # Stub classes loaded hook - runs before LoadClasses BootLoader
32
+ # right after a slice's classes have been loaded internally.
33
+ def self.loaded
34
+ end
35
+
36
+ # Initialization hook - runs before AfterAppLoads BootLoader
37
+ def self.init
38
+ unless File.exist?(Merb.root / 'config' / 'quickadmins.yaml')
39
+ Merb.logger.info("Creating initial quickadmins.yaml file")
40
+ File.new(Merb.root / 'config' / 'quickadmins.yaml', 'w').puts(sample_yaml)
41
+ end
42
+ end
43
+
44
+ # Activation hook - runs after AfterAppLoads BootLoader
45
+ def self.activate
46
+ result = ::Application.class_eval { include Quickadmin::Mixins::EnsureQuickadmin }
47
+ Merb.logger.info("Including EnsureQuickadmin mixin into #{result}")
48
+ end
49
+
50
+ # Deactivation hook - triggered by Merb::Slices.deactivate(Quickadmin)
51
+ def self.deactivate
52
+ end
53
+
54
+ # Setup routes inside the host application
55
+ #
56
+ # @param scope<Merb::Router::Behaviour>
57
+ # Routes will be added within this scope (namespace). In fact, any
58
+ # router behaviour is a valid namespace, so you can attach
59
+ # routes at any level of your router setup.
60
+ #
61
+ # @note prefix your named routes with :quickadmin_
62
+ # to avoid potential conflicts with global named routes.
63
+ def self.setup_router(scope)
64
+ scope.match('/openid').to(:controller => 'validates', :action => 'openid').name(:openid)
65
+ scope.match('/logout').to(:controller => 'validates', :action => 'logout').name(:logout)
66
+ end
67
+
68
+ protected
69
+
70
+ def self.sample_yaml
71
+ sample = <<EOF
72
+ - mark.mpercival.com
73
+ - barry.change.gov
74
+ EOF
75
+ end
76
+
77
+ end
78
+
79
+ # Setup the slice layout for Quickadmin
80
+ #
81
+ # Use Quickadmin.push_path and Quickadmin.push_app_path
82
+ # to set paths to quickadmin-level and app-level paths. Example:
83
+ #
84
+ # Quickadmin.push_path(:application, Quickadmin.root)
85
+ # Quickadmin.push_app_path(:application, Merb.root / 'slices' / 'quickadmin')
86
+ # ...
87
+ #
88
+ # Any component path that hasn't been set will default to Quickadmin.root
89
+ #
90
+ # Or just call setup_default_structure! to setup a basic Merb MVC structure.
91
+ Quickadmin.setup_default_structure!
92
+
93
+ # Add dependencies for other Quickadmin classes below. Example:
94
+ # dependency "quickadmin/other"
95
+
96
+ dependency "ruby-openid", :require_as => "openid"
97
+ dependency 'merb-haml'
98
+ dependency 'merb-helpers'
99
+
100
+ end
@@ -0,0 +1,103 @@
1
+ namespace :slices do
2
+ namespace :quickadmin do
3
+
4
+ desc "Install Quickadmin"
5
+ task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
6
+
7
+ desc "Test for any dependencies"
8
+ task :preflight do # see slicetasks.rb
9
+ end
10
+
11
+ desc "Setup directories"
12
+ task :setup_directories do
13
+ puts "Creating directories for host application"
14
+ Quickadmin.mirrored_components.each do |type|
15
+ if File.directory?(Quickadmin.dir_for(type))
16
+ if !File.directory?(dst_path = Quickadmin.app_dir_for(type))
17
+ relative_path = dst_path.relative_path_from(Merb.root)
18
+ puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
19
+ mkdir_p(dst_path)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "Copy stub files to host application"
26
+ task :stubs do
27
+ puts "Copying stubs for Quickadmin - resolves any collisions"
28
+ copied, preserved = Quickadmin.mirror_stubs!
29
+ puts "- no files to copy" if copied.empty? && preserved.empty?
30
+ copied.each { |f| puts "- copied #{f}" }
31
+ preserved.each { |f| puts "! preserved override as #{f}" }
32
+ end
33
+
34
+ desc "Copy stub files and views to host application"
35
+ task :patch => [ "stubs", "freeze:views" ]
36
+
37
+ desc "Copy public assets to host application"
38
+ task :copy_assets do
39
+ puts "Copying assets for Quickadmin - resolves any collisions"
40
+ copied, preserved = Quickadmin.mirror_public!
41
+ puts "- no files to copy" if copied.empty? && preserved.empty?
42
+ copied.each { |f| puts "- copied #{f}" }
43
+ preserved.each { |f| puts "! preserved override as #{f}" }
44
+ end
45
+
46
+ desc "Migrate the database"
47
+ task :migrate do # see slicetasks.rb
48
+ end
49
+
50
+ desc "Freeze Quickadmin into your app (only quickadmin/app)"
51
+ task :freeze => [ "freeze:app" ]
52
+
53
+ namespace :freeze do
54
+
55
+ desc "Freezes Quickadmin by installing the gem into application/gems"
56
+ task :gem do
57
+ ENV["GEM"] ||= "quickadmin"
58
+ Rake::Task['slices:install_as_gem'].invoke
59
+ end
60
+
61
+ desc "Freezes Quickadmin by copying all files from quickadmin/app to your application"
62
+ task :app do
63
+ puts "Copying all quickadmin/app files to your application - resolves any collisions"
64
+ copied, preserved = Quickadmin.mirror_app!
65
+ puts "- no files to copy" if copied.empty? && preserved.empty?
66
+ copied.each { |f| puts "- copied #{f}" }
67
+ preserved.each { |f| puts "! preserved override as #{f}" }
68
+ end
69
+
70
+ desc "Freeze all views into your application for easy modification"
71
+ task :views do
72
+ puts "Copying all view templates to your application - resolves any collisions"
73
+ copied, preserved = Quickadmin.mirror_files_for :view
74
+ puts "- no files to copy" if copied.empty? && preserved.empty?
75
+ copied.each { |f| puts "- copied #{f}" }
76
+ preserved.each { |f| puts "! preserved override as #{f}" }
77
+ end
78
+
79
+ desc "Freeze all models into your application for easy modification"
80
+ task :models do
81
+ puts "Copying all models to your application - resolves any collisions"
82
+ copied, preserved = Quickadmin.mirror_files_for :model
83
+ puts "- no files to copy" if copied.empty? && preserved.empty?
84
+ copied.each { |f| puts "- copied #{f}" }
85
+ preserved.each { |f| puts "! preserved override as #{f}" }
86
+ end
87
+
88
+ desc "Freezes Quickadmin as a gem and copies over quickadmin/app"
89
+ task :app_with_gem => [:gem, :app]
90
+
91
+ desc "Freezes Quickadmin by unpacking all files into your application"
92
+ task :unpack do
93
+ puts "Unpacking Quickadmin files to your application - resolves any collisions"
94
+ copied, preserved = Quickadmin.unpack_slice!
95
+ puts "- no files to copy" if copied.empty? && preserved.empty?
96
+ copied.each { |f| puts "- copied #{f}" }
97
+ preserved.each { |f| puts "! preserved override as #{f}" }
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,14 @@
1
+ module Quickadmin::Mixins
2
+
3
+ module EnsureQuickadmin
4
+
5
+ def ensure_quickadmin
6
+ unless session[:quickadmin]
7
+ session[:return_to] = request.uri
8
+ throw :halt, Proc.new{ |c| c.redirect url(:openid) }
9
+ end
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,18 @@
1
+ namespace :slices do
2
+ namespace :quickadmin do
3
+
4
+ # add your own quickadmin tasks here
5
+
6
+ # implement this to test for structural/code dependencies
7
+ # like certain directories or availability of other files
8
+ desc "Test for any dependencies"
9
+ task :preflight do
10
+ end
11
+
12
+ # implement this to perform any database related setup steps
13
+ desc "Migrate the database"
14
+ task :migrate do
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,65 @@
1
+ namespace :slices do
2
+ namespace :quickadmin do
3
+
4
+ desc "Run slice specs within the host application context"
5
+ task :spec => [ "spec:explain", "spec:default" ]
6
+
7
+ namespace :spec do
8
+
9
+ slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
+
11
+ task :explain do
12
+ puts "\nNote: By running Quickadmin specs inside the application context any\n" +
13
+ "overrides could break existing specs. This isn't always a problem,\n" +
14
+ "especially in the case of views. Use these spec tasks to check how\n" +
15
+ "well your application conforms to the original slice implementation."
16
+ end
17
+
18
+ Spec::Rake::SpecTask.new('default') do |t|
19
+ t.spec_opts = ["--format", "specdoc", "--colour"]
20
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
21
+ end
22
+
23
+ desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
24
+ Spec::Rake::SpecTask.new('model') do |t|
25
+ t.spec_opts = ["--format", "specdoc", "--colour"]
26
+ if(ENV['MODEL'])
27
+ t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
28
+ else
29
+ t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
30
+ end
31
+ end
32
+
33
+ desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
34
+ Spec::Rake::SpecTask.new('controller') do |t|
35
+ t.spec_opts = ["--format", "specdoc", "--colour"]
36
+ if(ENV['CONTROLLER'])
37
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
38
+ else
39
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
40
+ end
41
+ end
42
+
43
+ desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
44
+ Spec::Rake::SpecTask.new('view') do |t|
45
+ t.spec_opts = ["--format", "specdoc", "--colour"]
46
+ if(ENV['CONTROLLER'] and ENV['VIEW'])
47
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
48
+ elsif(ENV['CONTROLLER'])
49
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
50
+ else
51
+ t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
52
+ end
53
+ end
54
+
55
+ desc "Run all specs and output the result in html"
56
+ Spec::Rake::SpecTask.new('html') do |t|
57
+ t.spec_opts = ["--format", "html"]
58
+ t.libs = ['lib', 'server/lib' ]
59
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ html, body { margin: 0; padding: 0; }
2
+ #container { width: 800px; margin: 4em auto; padding: 4em 4em 6em 4em; background: #DDDDDD; }
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Quickadmin::Validates (controller)" do
4
+
5
+ # Feel free to remove the specs below
6
+
7
+ before :all do
8
+ Merb::Router.prepare { add_slice(:Quickadmin) } if standalone?
9
+ end
10
+
11
+ after :all do
12
+ Merb::Router.reset! if standalone?
13
+ end
14
+
15
+ it "should have access to the slice module" do
16
+ controller = dispatch_to(Quickadmin::Main, :index)
17
+ controller.slice.should == Quickadmin
18
+ controller.slice.should == Quickadmin::Main.slice
19
+ end
20
+
21
+ it "should have an index action" do
22
+ controller = dispatch_to(Quickadmin::Main, :index)
23
+ controller.status.should == 200
24
+ controller.body.should contain('Quickadmin')
25
+ end
26
+
27
+ it "should work with the default route" do
28
+ controller = get("/quickadmin/main/index")
29
+ controller.should be_kind_of(Quickadmin::Main)
30
+ controller.action_name.should == 'index'
31
+ end
32
+
33
+ it "should work with the example named route" do
34
+ controller = get("/quickadmin/index.html")
35
+ controller.should be_kind_of(Quickadmin::Main)
36
+ controller.action_name.should == 'index'
37
+ end
38
+
39
+ it "should have a slice_url helper method for slice-specific routes" do
40
+ controller = dispatch_to(Quickadmin::Main, 'index')
41
+
42
+ url = controller.url(:quickadmin_default, :controller => 'main', :action => 'show', :format => 'html')
43
+ url.should == "/quickadmin/main/show.html"
44
+ controller.slice_url(:controller => 'main', :action => 'show', :format => 'html').should == url
45
+
46
+ url = controller.url(:quickadmin_index, :format => 'html')
47
+ url.should == "/quickadmin/index.html"
48
+ controller.slice_url(:index, :format => 'html').should == url
49
+
50
+ url = controller.url(:quickadmin_home)
51
+ url.should == "/quickadmin/"
52
+ controller.slice_url(:home).should == url
53
+ end
54
+
55
+ it "should have helper methods for dealing with public paths" do
56
+ controller = dispatch_to(Quickadmin::Main, :index)
57
+ controller.public_path_for(:image).should == "/slices/quickadmin/images"
58
+ controller.public_path_for(:javascript).should == "/slices/quickadmin/javascripts"
59
+ controller.public_path_for(:stylesheet).should == "/slices/quickadmin/stylesheets"
60
+
61
+ controller.image_path.should == "/slices/quickadmin/images"
62
+ controller.javascript_path.should == "/slices/quickadmin/javascripts"
63
+ controller.stylesheet_path.should == "/slices/quickadmin/stylesheets"
64
+ end
65
+
66
+ it "should have a slice-specific _template_root" do
67
+ Quickadmin::Main._template_root.should == Quickadmin.dir_for(:view)
68
+ Quickadmin::Main._template_root.should == Quickadmin::Application._template_root
69
+ end
70
+
71
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Quickadmin (module)" do
4
+
5
+ # Implement your Quickadmin specs here
6
+
7
+ it "should have proper specs"
8
+
9
+ # To spec Quickadmin you need to hook it up to the router like this:
10
+
11
+ # before :all do
12
+ # Merb::Router.prepare { add_slice(:Quickadmin) } if standalone?
13
+ # end
14
+ #
15
+ # after :all do
16
+ # Merb::Router.reset! if standalone?
17
+ # end
18
+
19
+ end
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'merb-core'
3
+ require 'merb-slices'
4
+ require 'spec'
5
+
6
+ # Add quickadmin.rb to the search path
7
+ Merb::Plugins.config[:merb_slices][:auto_register] = true
8
+ Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'quickadmin.rb')
9
+
10
+ # Require quickadmin.rb explicitly so any dependencies are loaded
11
+ require Merb::Plugins.config[:merb_slices][:search_path]
12
+
13
+ # Using Merb.root below makes sure that the correct root is set for
14
+ # - testing standalone, without being installed as a gem and no host application
15
+ # - testing from within the host application; its root will be used
16
+ Merb.start_environment(
17
+ :testing => true,
18
+ :adapter => 'runner',
19
+ :environment => ENV['MERB_ENV'] || 'test',
20
+ :session_store => 'memory'
21
+ )
22
+
23
+ module Merb
24
+ module Test
25
+ module SliceHelper
26
+
27
+ # The absolute path to the current slice
28
+ def current_slice_root
29
+ @current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
30
+ end
31
+
32
+ # Whether the specs are being run from a host application or standalone
33
+ def standalone?
34
+ Merb.root == ::Quickadmin.root
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+
41
+ Spec::Runner.configure do |config|
42
+ config.include(Merb::Test::ViewHelper)
43
+ config.include(Merb::Test::RouteHelper)
44
+ config.include(Merb::Test::ControllerHelper)
45
+ config.include(Merb::Test::SliceHelper)
46
+ end
@@ -0,0 +1,2 @@
1
+ class Quickadmin::Application < Merb::Controller
2
+ end
@@ -0,0 +1,2 @@
1
+ class Quickadmin::Main < Quickadmin::Application
2
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markpercival-quickadmin
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Mark Percival
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-03 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-slices
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.3
23
+ version:
24
+ description: Merb Slice adds quick DB'less OpenID authentication to your app
25
+ email: mark@mpercival.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.mdown
32
+ - LICENSE
33
+ - TODO
34
+ files:
35
+ - LICENSE
36
+ - README.mdown
37
+ - Rakefile
38
+ - TODO
39
+ - lib/quickadmin
40
+ - lib/quickadmin/merbtasks.rb
41
+ - lib/quickadmin/mixins
42
+ - lib/quickadmin/mixins/ensure_quickadmin.rb
43
+ - lib/quickadmin/slicetasks.rb
44
+ - lib/quickadmin/spectasks.rb
45
+ - lib/quickadmin.rb
46
+ - spec/controllers
47
+ - spec/controllers/main_spec.rb
48
+ - spec/quickadmin_spec.rb
49
+ - spec/spec_helper.rb
50
+ - app/controllers
51
+ - app/controllers/application.rb
52
+ - app/controllers/validates.rb
53
+ - app/helpers
54
+ - app/helpers/application_helper.rb
55
+ - app/models
56
+ - app/models/admin.rb
57
+ - app/views
58
+ - app/views/layout
59
+ - app/views/layout/quickadmin.html.erb
60
+ - app/views/validates
61
+ - app/views/validates/openid.html.haml
62
+ - public/javascripts
63
+ - public/javascripts/master.js
64
+ - public/stylesheets
65
+ - public/stylesheets/master.css
66
+ - stubs/app
67
+ - stubs/app/controllers
68
+ - stubs/app/controllers/application.rb
69
+ - stubs/app/controllers/main.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/markpercival/quickadmin
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project: merb
92
+ rubygems_version: 1.2.0
93
+ signing_key:
94
+ specification_version: 2
95
+ summary: Merb Slice adds quick DB'less OpenID authentication to your app
96
+ test_files: []
97
+