i0n_rails3_generators 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +71 -0
- data/config/version.yml +4 -0
- data/lib/generators/authlogic/authlogic.rb +11 -0
- data/lib/generators/authlogic/complete/complete_generator.rb +75 -0
- data/lib/generators/authlogic/complete/templates/_application_controller.rb +50 -0
- data/lib/generators/authlogic/complete/templates/_populate.rake +16 -0
- data/lib/generators/authlogic/complete/templates/_routes.rb +8 -0
- data/lib/generators/authlogic/complete/templates/_test_helper_fixture_settings.rb +3 -0
- data/lib/generators/authlogic/complete/templates/_test_helper_require.rb +2 -0
- data/lib/generators/authlogic/complete/templates/_test_helper_setup.rb +4 -0
- data/lib/generators/authlogic/complete/templates/migration_create_users.rb +28 -0
- data/lib/generators/authlogic/complete/templates/user.rb +11 -0
- data/lib/generators/authlogic/complete/templates/user_session.rb +9 -0
- data/lib/generators/authlogic/complete/templates/user_sessions_controller.rb +26 -0
- data/lib/generators/authlogic/complete/templates/user_sessions_controller_test.rb +21 -0
- data/lib/generators/authlogic/complete/templates/user_test.rb +8 -0
- data/lib/generators/authlogic/complete/templates/users.yml +8 -0
- data/lib/generators/authlogic/complete/templates/users_controller.rb +38 -0
- data/lib/generators/authlogic/complete/templates/users_controller_test.rb +34 -0
- data/lib/i0n_rails3_generators.rb +70 -0
- data/test/i0n_rails3_generators/test_base.rb +20 -0
- data/test/test_i0n_rails3_generators.rb +110 -0
- metadata +115 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Ian Alexander Wood (i0n)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
=i0n_rails3_generators
|
2
|
+
|
3
|
+
==Description:
|
4
|
+
Custom Rails 3 generators.
|
5
|
+
|
6
|
+
==Current Generators:
|
7
|
+
* authlogic:complete
|
8
|
+
|
9
|
+
==Note on Patches/Pull Requests
|
10
|
+
|
11
|
+
* Fork the project.
|
12
|
+
* Make your feature addition or bug fix.
|
13
|
+
* Add tests for it. This is important so I don't break it in a
|
14
|
+
future version unintentionally.
|
15
|
+
* Commit, do not mess with rakefile, version, or history.
|
16
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
17
|
+
* Send me a pull request. Bonus points for topic branches.
|
data/Rakefile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'i0n_rails3_generators'
|
6
|
+
|
7
|
+
# Runs all tests
|
8
|
+
require 'rake/testtask'
|
9
|
+
Rake::TestTask.new(:test) do |test|
|
10
|
+
test.libs << 'lib' << 'test'
|
11
|
+
test.pattern = 'test/**/test_*.rb'
|
12
|
+
test.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :deploy do
|
16
|
+
|
17
|
+
desc "Commits changes to local git repo and then pushes to remote"
|
18
|
+
task :git do
|
19
|
+
git_actions
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Builds gemspec and deploys gem to RubyGems.org"
|
23
|
+
task :gem do
|
24
|
+
rubygems_actions
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :bump do
|
30
|
+
|
31
|
+
desc "Bumps major version number by 1"
|
32
|
+
task :major do
|
33
|
+
I0nRails3Generators.bump_version_major
|
34
|
+
git_actions
|
35
|
+
rubygems_actions
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Bumps minor version number by 1"
|
39
|
+
task :minor do
|
40
|
+
I0nRails3Generators.bump_version_minor
|
41
|
+
git_actions
|
42
|
+
rubygems_actions
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Bumps patch version number by 1"
|
46
|
+
task :patch do
|
47
|
+
I0nRails3Generators.bump_version_patch
|
48
|
+
git_actions
|
49
|
+
rubygems_actions
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
task :version do
|
55
|
+
puts "\nI0nRails3Generators Version: #{I0nRails3Generators::VERSION}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def git_actions
|
59
|
+
Dir.chdir("#{I0nRails3Generators::ROOT_PATH}")
|
60
|
+
system "git add ."
|
61
|
+
system "git commit -v -a -m 'commit for version: #{I0nRails3Generators.version}'"
|
62
|
+
system "git tag #{I0nRails3Generators.version}"
|
63
|
+
system "git push"
|
64
|
+
system "git push --tags"
|
65
|
+
end
|
66
|
+
|
67
|
+
def rubygems_actions
|
68
|
+
Dir.chdir("#{I0nRails3Generators::ROOT_PATH}")
|
69
|
+
system "gem build i0n_rails3_generators.gemspec"
|
70
|
+
system "gem push i0n_rails3_generators-#{I0nRails3Generators.version}.gem"
|
71
|
+
end
|
data/config/version.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
module Authlogic
|
4
|
+
module Generators
|
5
|
+
class Base < Rails::Generators::NamedBase
|
6
|
+
# def self.source_root
|
7
|
+
# @_authlogic_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'authlogic', generator_name, 'templates'))
|
8
|
+
# end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Authlogic
|
2
|
+
module Generators
|
3
|
+
class CompleteGenerator < Rails::Generators::Base
|
4
|
+
require 'rails/generators'
|
5
|
+
require 'rails/generators/migration'
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
desc "Creates a complete authlogic based authentication system, using user and user_session as defaults"
|
9
|
+
|
10
|
+
source_root File.expand_path('../templates', __FILE__)
|
11
|
+
|
12
|
+
def create_models
|
13
|
+
copy_file "user.rb", "#{Rails.root}/app/models/user.rb"
|
14
|
+
copy_file "user_session.rb", "#{Rails.root}/app/models/user_session.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_controllers
|
18
|
+
copy_file "users_controller.rb", "#{Rails.root}/app/controllers/users_controller.rb"
|
19
|
+
copy_file "user_sessions_controller.rb", "#{Rails.root}/app/controllers/user_sessions_controller.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_application_controller_helper_methods
|
23
|
+
inject_into_file "#{Rails.root}/app/controllers/application_controller.rb", IO.read("#{CompleteGenerator.source_root}/_application_controller.rb"), :after => "protect_from_forgery"
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_views
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_default_users_to_populate_rake_task
|
31
|
+
inject_into_file "#{Rails.root}/lib/tasks/populate.rake", IO.read("#{CompleteGenerator.source_root}/_populate.rake"), :after => "require 'faker'"
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_routes
|
35
|
+
inject_into_file "#{Rails.root}/config/routes.rb", IO.read("#{CompleteGenerator.source_root}/_routes.rb"), :after => "::Application.routes.draw do"
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup_test_helper
|
39
|
+
inject_into_file "#{Rails.root}/test/test_helper.rb", IO.read("#{CompleteGenerator.source_root}/_test_helper_require.rb"), :after => "require 'rails/test_help'"
|
40
|
+
inject_into_class "#{Rails.root}/test/test_helper.rb", ActiveSupport::TestCase do
|
41
|
+
IO.read(File.expand_path('../', __FILE__) + "/templates/_test_helper_fixture_settings.rb")
|
42
|
+
end
|
43
|
+
append_file "#{Rails.root}/test/test_helper.rb" do
|
44
|
+
IO.read("#{CompleteGenerator.source_root}/_test_helper_setup.rb")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def create__unit_tests
|
49
|
+
copy_file "user_test.rb", "#{Rails.root}/test/unit/user_test.rb"
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_functional_tests
|
53
|
+
copy_file "users_controller_test.rb", "#{Rails.root}/test/functional/users_controller_test.rb"
|
54
|
+
copy_file "user_sessions_controller_test.rb", "#{Rails.root}/test/functional/user_sessions_controller_test.rb"
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_user_fixtures
|
58
|
+
copy_file "users.yml", "#{Rails.root}/test/fixtures/users.yml"
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.next_migration_number(dirname)
|
62
|
+
if ActiveRecord::Base.timestamped_migrations
|
63
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
64
|
+
else
|
65
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_database_migration
|
70
|
+
migration_template "migration_create_users.rb", "db/migrate/create_users.rb"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
helper :all
|
3
|
+
helper_method :current_user_session, :current_user
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def current_user_session
|
8
|
+
return @current_user_session if defined?(@current_user_session)
|
9
|
+
@current_user_session = UserSession.find
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_user
|
13
|
+
return @current_user if defined?(@current_user)
|
14
|
+
@current_user = current_user_session && current_user_session.record
|
15
|
+
end
|
16
|
+
|
17
|
+
def require_user
|
18
|
+
unless current_user
|
19
|
+
store_location
|
20
|
+
flash[:notice] = 'You must be logged in to access this page'
|
21
|
+
redirect_to new_user_session_url
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def require_no_user
|
27
|
+
if current_user
|
28
|
+
store_location
|
29
|
+
flash[:notice] = 'You must be logged out to access this page'
|
30
|
+
redirect_to account_url
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def require_admin
|
36
|
+
unless current_admin && ["admin"].include?(current_admin.role)
|
37
|
+
flash[:notice] = "You must be logged in to access this page"
|
38
|
+
redirect_to new_admin_login_url
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def store_location
|
44
|
+
session[:return_to] = request.request_uri
|
45
|
+
end
|
46
|
+
|
47
|
+
def redirect_back_or_default(default)
|
48
|
+
redirect_to(session[:return_to] || default)
|
49
|
+
session[:return_to] = nil
|
50
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
##################### DELETE EXISTING USERS #####################
|
2
|
+
User.delete_all
|
3
|
+
|
4
|
+
##################### CREATE DEFAULT USER #####################
|
5
|
+
User.populate 1 do |x|
|
6
|
+
x.login = "i0n"
|
7
|
+
x.email = "ianalexanderwood@gmail.com"
|
8
|
+
x.crypted_password = "e22d74a99750f4a13960e72782586fc2edd020a2c6215eb1f98ede635c1e5173a25a53b3f461ade87f3a13fa1f3fdb20f1dcdd4e8cdd74c0d29abfd5f8a66c79"
|
9
|
+
x.password_salt = "3kH2EVijgrXNODNyLtLZ"
|
10
|
+
x.single_access_token = "be9e887123d2f1ef7d7370ed26fd823c031ca6c5da1ddf3cade69bb29e285cbca799517a44672fd62fe9354f782e3d5dc641376270d36f59ca9600d95437e630"
|
11
|
+
x.perishable_token = "s7bD7z9B8DqVcX4hwa2P"
|
12
|
+
x.persistence_token = 'be9e887123d2f1ef7d7370ed26fd823c031ca6c5da1ddf3cade69bb29e285cbca799517a44672fd62fe9354f782e3d5dc641376270d36f59ca9600d95437e630'
|
13
|
+
x.role = "admin"
|
14
|
+
x.login_count = 0
|
15
|
+
x.failed_login_count = 0
|
16
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
match '/logout' => 'user_sessions#destroy'
|
3
|
+
match '/signup' => 'users#new'
|
4
|
+
match '/register' => 'users#new'
|
5
|
+
scope(:path_names => { :new => "" }) do
|
6
|
+
resource :login, :controller => 'user_sessions', :only => [:new, :create, :destroy], :as => 'user_session'
|
7
|
+
end
|
8
|
+
resource :account, :controller => 'users'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :users do |t|
|
4
|
+
t.string :login, :null => false # optional, you can use email instead, or both
|
5
|
+
t.string :email, :null => false # optional, you can use login instead, or both
|
6
|
+
t.string :crypted_password, :null => false # optional, see below
|
7
|
+
t.string :password_salt, :null => false # optional, but highly recommended
|
8
|
+
t.string :persistence_token, :null => false # required
|
9
|
+
t.string :single_access_token, :null => false # optional, see Authlogic::Session::Params
|
10
|
+
t.string :perishable_token, :null => false # optional, see Authlogic::Session::Perishability
|
11
|
+
t.string :role, :null => false, :default => 'user'
|
12
|
+
|
13
|
+
# Magic columns, just like ActiveRecord's created_at and updated_at. These are automatically maintained by Authlogic if they are present.
|
14
|
+
t.integer :login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
|
15
|
+
t.integer :failed_login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
|
16
|
+
t.datetime :last_request_at # optional, see Authlogic::Session::MagicColumns
|
17
|
+
t.datetime :current_login_at # optional, see Authlogic::Session::MagicColumns
|
18
|
+
t.datetime :last_login_at # optional, see Authlogic::Session::MagicColumns
|
19
|
+
t.string :current_login_ip # optional, see Authlogic::Session::MagicColumns
|
20
|
+
t.string :last_login_ip # optional, see Authlogic::Session::MagicColumns
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.down
|
26
|
+
drop_table :users
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class UserSessionsController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :require_no_user, :only => [:new, :create]
|
4
|
+
before_filter :require_user, :only => :destroy
|
5
|
+
|
6
|
+
def new
|
7
|
+
@user_session = UserSession.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
@user_session = UserSession.new(params[:user_session])
|
12
|
+
if @user_session.save
|
13
|
+
flash[:notice] = "Login successful!"
|
14
|
+
redirect_back_or_default account_path
|
15
|
+
else
|
16
|
+
render :new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy
|
21
|
+
current_user_session.destroy
|
22
|
+
flash[:notice] = "Logout successful!"
|
23
|
+
redirect_back_or_default new_user_session_path
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UserSessionsControllerTest < ActionController::TestCase
|
4
|
+
test "should get new" do
|
5
|
+
get :new
|
6
|
+
assert_response :success
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should create user session" do
|
10
|
+
post :create, :user_session => { :login => "luke", :password => "the_force" }
|
11
|
+
assert user_session = UserSession.find
|
12
|
+
assert_equal users(:luke), user_session.user
|
13
|
+
assert_redirected_to account_path
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should destroy user session" do
|
17
|
+
delete :destroy
|
18
|
+
assert_nil UserSession.find
|
19
|
+
assert_redirected_to new_user_session_path
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
luke:
|
2
|
+
login: luke
|
3
|
+
email: valid_email@email.co.uk
|
4
|
+
password_salt: <%= salt = Authlogic::Random.hex_token %>
|
5
|
+
crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("the_force" + salt) %>
|
6
|
+
persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317
|
7
|
+
single_access_token: U4b7i7Tt8SSG6FRhqj
|
8
|
+
perishable_token: 232CpZECf5kEgjtI10
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :require_no_user, :only => [:new, :create]
|
4
|
+
before_filter :require_user, :only => [:show, :edit, :update]
|
5
|
+
|
6
|
+
def new
|
7
|
+
@user = User.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
@user = User.new(params[:user])
|
12
|
+
if @user.save
|
13
|
+
flash[:notice] = "Account registered!"
|
14
|
+
redirect_back_or_default account_path
|
15
|
+
else
|
16
|
+
render :action => :new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
@user = current_user
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
@user = current_user
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
@user = @current_user # makes our views "cleaner" and more consistent
|
30
|
+
if @user.update_attributes(params[:user])
|
31
|
+
flash[:notice] = "Account updated!"
|
32
|
+
redirect_to account_path
|
33
|
+
else
|
34
|
+
render :action => :edit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UsersControllerTest < ActionController::TestCase
|
4
|
+
test "should get new" do
|
5
|
+
get :new
|
6
|
+
assert_response :success
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should create user" do
|
10
|
+
assert_difference('User.count') do
|
11
|
+
post :create, :user => { :login => "jabba", :email => "jabba@tatooine.org", :password => "the_hutt", :password_confirmation => "the_hutt" }
|
12
|
+
end
|
13
|
+
|
14
|
+
assert_redirected_to account_path
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should show user" do
|
18
|
+
UserSession.create(users(:luke))
|
19
|
+
get :show
|
20
|
+
assert_response :success
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should get edit" do
|
24
|
+
UserSession.create(users(:luke))
|
25
|
+
get :edit, :id => users(:luke).id
|
26
|
+
assert_response :success
|
27
|
+
end
|
28
|
+
|
29
|
+
test "should update user" do
|
30
|
+
UserSession.create(users(:luke))
|
31
|
+
put :update, :id => users(:luke).id, :user => { }
|
32
|
+
assert_redirected_to account_path
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module I0nRails3Generators
|
6
|
+
|
7
|
+
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
8
|
+
LIB_PATH = File.expand_path(File.dirname(__FILE__))
|
9
|
+
CONFIG_PATH = File.expand_path(File.join(File.dirname(__FILE__), '../config'))
|
10
|
+
IGNORE_DIRS = ['.','..']
|
11
|
+
LAUNCH_PATH = FileUtils.pwd
|
12
|
+
|
13
|
+
@version_yaml = YAML.load_file("#{I0nRails3Generators::CONFIG_PATH}/version.yml")
|
14
|
+
|
15
|
+
@version_major = @version_yaml[:version_major]
|
16
|
+
@version_minor = @version_yaml[:version_minor]
|
17
|
+
@version_patch = @version_yaml[:version_patch]
|
18
|
+
|
19
|
+
class << self
|
20
|
+
|
21
|
+
attr_accessor :version_major, :version_minor, :version_patch
|
22
|
+
|
23
|
+
# Method for writing to config/jumpstart_version.yml
|
24
|
+
def dump_version_yaml
|
25
|
+
File.open( "#{I0nRails3Generators::CONFIG_PATH}/version.yml", 'w' ) do |out|
|
26
|
+
YAML.dump( {:version_major => @version_major, :version_minor => @version_minor, :version_patch => @version_patch}, out )
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Looks up the current version of JumpStart
|
31
|
+
def version
|
32
|
+
"#{version_major}.#{version_minor}.#{version_patch}"
|
33
|
+
end
|
34
|
+
|
35
|
+
# Method for bumping version number types.
|
36
|
+
# Resets @version_minor and @version_patch to 0 if bumping @version_major.
|
37
|
+
# Resets @version_pacth to 0 if bumping @version_minor
|
38
|
+
def bump(version_type)
|
39
|
+
value = instance_variable_get("@#{version_type}")
|
40
|
+
instance_variable_set("@#{version_type}", (value + 1))
|
41
|
+
if version_type == "version_major"
|
42
|
+
@version_minor, @version_patch = 0, 0
|
43
|
+
elsif version_type == "version_minor"
|
44
|
+
@version_patch = 0
|
45
|
+
end
|
46
|
+
dump_version_yaml
|
47
|
+
end
|
48
|
+
|
49
|
+
# Handles calls to JumpStart::Setup.bump_version_major, JumpStart::Setup.bump_version_minor and JumpStart::Setup.bump_version_patch class methods.
|
50
|
+
def method_missing(method, *args)
|
51
|
+
if method.to_s.match(/^bump_version_(major|minor|patch)$/)
|
52
|
+
version_type = method.to_s.sub('bump_', '')
|
53
|
+
self.send(:bump, "#{version_type}")
|
54
|
+
else
|
55
|
+
super
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Handles calls to missing constants in the JumpStart module. Calls JumpStart.version if JumpStart::VERSION is recognised.
|
60
|
+
def const_missing(name)
|
61
|
+
if name.to_s =~ /^VERSION$/
|
62
|
+
version
|
63
|
+
else
|
64
|
+
super
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestJumpstartBase < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Testing I0n_rails3_generators::Base\n" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
teardown do
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
context "Tests for the I0n_rails3_generators::Base#intialize instance method. \n" do
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestI0n_rails3_generators < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should "be able to find version.yml" do
|
6
|
+
assert(File.exists?("#{I0n_rails3_generators::CONFIG_PATH}/version.yml"))
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Test for I0n_rails3_generators.version class instance method" do
|
10
|
+
should "return 1.1.1" do
|
11
|
+
I0n_rails3_generators.version_major = 1
|
12
|
+
I0n_rails3_generators.version_minor = 1
|
13
|
+
I0n_rails3_generators.version_patch = 1
|
14
|
+
assert_equal "1.1.1", I0n_rails3_generators.version
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "Tests for the I0n_rails3_generators#dump_version_yaml class method." do
|
19
|
+
should "call File.open and Yaml.dump for version.yml" do
|
20
|
+
YAML.stubs(:dump)
|
21
|
+
File.stubs(:open)
|
22
|
+
File.expects(:open).once
|
23
|
+
I0n_rails3_generators.dump_version_yaml
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "Tests for the I0n_rails3_generators#bump class method." do
|
28
|
+
|
29
|
+
setup do
|
30
|
+
I0n_rails3_generators.stubs(:dump_version_yaml)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "add 1 to @version_major class instance variable, set @version_minor and @version_patch to 0 and call dump_I0n_rails3_generators_version_yaml" do
|
34
|
+
I0n_rails3_generators.module_eval {@version_major = 1; @version_minor = 1; @version_patch = 1 }
|
35
|
+
I0n_rails3_generators.expects(:dump_I0n_rails3_generators_version_yaml).once
|
36
|
+
I0n_rails3_generators.bump("version_major")
|
37
|
+
assert_equal 2, I0n_rails3_generators.version_major
|
38
|
+
assert_equal 0, I0n_rails3_generators.version_minor
|
39
|
+
assert_equal 0, I0n_rails3_generators.version_patch
|
40
|
+
end
|
41
|
+
|
42
|
+
should "add 1 to @version_minor class instance variable, set @version_patch to 0 and call dump_I0n_rails3_generators_version_yaml" do
|
43
|
+
I0n_rails3_generators.module_eval {@version_major = 1; @version_minor = 1; @version_patch = 1 }
|
44
|
+
I0n_rails3_generators.expects(:dump_I0n_rails3_generators_version_yaml).once
|
45
|
+
I0n_rails3_generators.bump("version_minor")
|
46
|
+
assert_equal 1, I0n_rails3_generators.version_major
|
47
|
+
assert_equal 2, I0n_rails3_generators.version_minor
|
48
|
+
assert_equal 0, I0n_rails3_generators.version_patch
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
should "add 1 to @version_patch class instance variable and call dump_I0n_rails3_generators_version_yaml" do
|
53
|
+
I0n_rails3_generators.module_eval {@version_major = 1; @version_minor = 1; @version_patch = 1 }
|
54
|
+
I0n_rails3_generators.expects(:dump_I0n_rails3_generators_version_yaml).once
|
55
|
+
I0n_rails3_generators.bump("version_patch")
|
56
|
+
assert_equal 1, I0n_rails3_generators.version_major
|
57
|
+
assert_equal 1, I0n_rails3_generators.version_minor
|
58
|
+
assert_equal 2, I0n_rails3_generators.version_patch
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
context "Tests for the I0n_rails3_generators#const_missing class method." do
|
65
|
+
|
66
|
+
setup do
|
67
|
+
I0n_rails3_generators.stubs(:version)
|
68
|
+
end
|
69
|
+
|
70
|
+
should "return the value of I0n_rails3_generators Version if I0n_rails3_generators::VERSION is called" do
|
71
|
+
I0n_rails3_generators.expects(:version).once
|
72
|
+
I0n_rails3_generators::VERSION
|
73
|
+
end
|
74
|
+
|
75
|
+
should "return to super if an unknown constant is called" do
|
76
|
+
assert_raises(NameError) {I0n_rails3_generators::VERSIONS}
|
77
|
+
assert_raises(NameError) {I0n_rails3_generators::AVERSION}
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
context "Tests for the I0n_rails3_generators#method_missing class method." do
|
83
|
+
|
84
|
+
setup do
|
85
|
+
I0n_rails3_generators.stubs(:bump).returns(:result)
|
86
|
+
I0n_rails3_generators.stubs(:dump_version_yaml)
|
87
|
+
end
|
88
|
+
|
89
|
+
should "recognise I0n_rails3_generators#bump_version_major class instance method calls and forward them to I0n_rails3_generators#bump to set @version_major." do
|
90
|
+
I0n_rails3_generators.expects(:bump).with("version_major").once
|
91
|
+
I0n_rails3_generators.bump_version_major
|
92
|
+
end
|
93
|
+
|
94
|
+
should "recognise I0n_rails3_generators#bump_version_minor class instance method calls and forward them to I0n_rails3_generators#bump to set @version_minor." do
|
95
|
+
I0n_rails3_generators.expects(:bump).with("version_minor").once
|
96
|
+
I0n_rails3_generators.bump_version_minor
|
97
|
+
end
|
98
|
+
|
99
|
+
should "recognise I0n_rails3_generators#bump_version_patch class instance method calls and forward them to I0n_rails3_generators#bump to set @version_patch." do
|
100
|
+
I0n_rails3_generators.expects(:bump).with("version_patch").once
|
101
|
+
I0n_rails3_generators.bump_version_patch
|
102
|
+
end
|
103
|
+
|
104
|
+
should "return method_missing to super as normal if method name is not recognised." do
|
105
|
+
assert_raises(NoMethodError) {I0n_rails3_generators.bump_version_blarg}
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i0n_rails3_generators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ian Alexander Wood (i0n)
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-07 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mocha
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
description: ""
|
47
|
+
email:
|
48
|
+
- ianalexanderwood@gmail.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- config/version.yml
|
57
|
+
- lib/generators/authlogic/authlogic.rb
|
58
|
+
- lib/generators/authlogic/complete/complete_generator.rb
|
59
|
+
- lib/generators/authlogic/complete/templates/_application_controller.rb
|
60
|
+
- lib/generators/authlogic/complete/templates/_populate.rake
|
61
|
+
- lib/generators/authlogic/complete/templates/_routes.rb
|
62
|
+
- lib/generators/authlogic/complete/templates/_test_helper_fixture_settings.rb
|
63
|
+
- lib/generators/authlogic/complete/templates/_test_helper_require.rb
|
64
|
+
- lib/generators/authlogic/complete/templates/_test_helper_setup.rb
|
65
|
+
- lib/generators/authlogic/complete/templates/migration_create_users.rb
|
66
|
+
- lib/generators/authlogic/complete/templates/user.rb
|
67
|
+
- lib/generators/authlogic/complete/templates/user_session.rb
|
68
|
+
- lib/generators/authlogic/complete/templates/user_sessions_controller.rb
|
69
|
+
- lib/generators/authlogic/complete/templates/user_sessions_controller_test.rb
|
70
|
+
- lib/generators/authlogic/complete/templates/user_test.rb
|
71
|
+
- lib/generators/authlogic/complete/templates/users.yml
|
72
|
+
- lib/generators/authlogic/complete/templates/users_controller.rb
|
73
|
+
- lib/generators/authlogic/complete/templates/users_controller_test.rb
|
74
|
+
- lib/i0n_rails3_generators.rb
|
75
|
+
- test/i0n_rails3_generators/test_base.rb
|
76
|
+
- test/test_i0n_rails3_generators.rb
|
77
|
+
- LICENSE
|
78
|
+
- Rakefile
|
79
|
+
- README.rdoc
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://github.com/i0n/i0n_rails3_generators
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 1
|
104
|
+
- 3
|
105
|
+
- 7
|
106
|
+
version: 1.3.7
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.3.7
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: ""
|
114
|
+
test_files: []
|
115
|
+
|