fingerrails 0.1.0

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 (54) hide show
  1. data/.gitignore +3 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +28 -0
  4. data/VERSION +1 -0
  5. data/bin/fingerrails +9 -0
  6. data/fingerrails.gemspec +90 -0
  7. data/fingertips.rb +181 -0
  8. data/templates/.kick +22 -0
  9. data/templates/Rakefile +23 -0
  10. data/templates/app/controllers/application_controller.rb +51 -0
  11. data/templates/app/controllers/members_controller.rb +32 -0
  12. data/templates/app/controllers/passwords_controller.rb +46 -0
  13. data/templates/app/controllers/sessions_controller.rb +26 -0
  14. data/templates/app/helpers/application_helper.rb +20 -0
  15. data/templates/app/models/mailer.rb +8 -0
  16. data/templates/app/models/member.rb +10 -0
  17. data/templates/app/models/member/authentication.rb +44 -0
  18. data/templates/app/views/layouts/_application_javascript_includes.html.erb +3 -0
  19. data/templates/app/views/layouts/_head.html.erb +3 -0
  20. data/templates/app/views/layouts/application.html.erb +25 -0
  21. data/templates/app/views/mailer/reset_password_message.erb +8 -0
  22. data/templates/app/views/members/edit.html.erb +21 -0
  23. data/templates/app/views/members/new.html.erb +26 -0
  24. data/templates/app/views/members/show.html.erb +3 -0
  25. data/templates/app/views/passwords/edit.html.erb +22 -0
  26. data/templates/app/views/passwords/new.html.erb +22 -0
  27. data/templates/app/views/passwords/reset.html.erb +9 -0
  28. data/templates/app/views/passwords/sent.html.erb +11 -0
  29. data/templates/app/views/sessions/_form.html.erb +22 -0
  30. data/templates/app/views/sessions/_status.html.erb +9 -0
  31. data/templates/app/views/sessions/new.html.erb +5 -0
  32. data/templates/config/database.yml +18 -0
  33. data/templates/lib/active_record_ext.rb +26 -0
  34. data/templates/lib/token.rb +9 -0
  35. data/templates/public/403.html +29 -0
  36. data/templates/public/javascripts/ready.js +9 -0
  37. data/templates/public/stylesheets/default.css +143 -0
  38. data/templates/public/stylesheets/reset.css +52 -0
  39. data/templates/test/ext/authentication.rb +24 -0
  40. data/templates/test/ext/file_fixtures.rb +8 -0
  41. data/templates/test/ext/time.rb +8 -0
  42. data/templates/test/fixtures/members.yml +8 -0
  43. data/templates/test/functional/application_controller_test.rb +104 -0
  44. data/templates/test/functional/members_controller_test.rb +71 -0
  45. data/templates/test/functional/passwords_controller_test.rb +95 -0
  46. data/templates/test/functional/sessions_controller_test.rb +68 -0
  47. data/templates/test/lib/active_record_ext_test.rb +13 -0
  48. data/templates/test/lib/token_test.rb +17 -0
  49. data/templates/test/test_helper.rb +32 -0
  50. data/templates/test/unit/helpers/application_helper_test.rb +44 -0
  51. data/templates/test/unit/mailer_test.rb +13 -0
  52. data/templates/test/unit/member/authentication_test.rb +73 -0
  53. data/templates/test/unit/member_test.rb +32 -0
  54. metadata +108 -0
@@ -0,0 +1,68 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe "On the", SessionsController, "a visitor" do
4
+ it "should see a login form" do
5
+ get :new
6
+ status.should.be :success
7
+ template.should.be 'sessions/new'
8
+ assert_select 'form'
9
+ end
10
+
11
+ it "should keep the url to return to after authentication" do
12
+ url = member_url(members(:adrian))
13
+ get :new, {}, {}, { :after_authentication => { :redirect_to => url }}
14
+ controller.after_authentication[:redirect_to].should == url
15
+ end
16
+
17
+ it "should be able to create a new session" do
18
+ post :create, :member => valid_credentials
19
+ assigns(:unauthenticated).should == members(:adrian)
20
+ should.be.authenticated
21
+ should.redirect_to root_url
22
+ end
23
+
24
+ it "should redirect the user back to the page he originally requested" do
25
+ url = edit_member_url(members(:adrian))
26
+ post :create, { :member => valid_credentials }, {}, { :after_authentication => { :redirect_to => url }}
27
+ should.redirect_to url
28
+ end
29
+
30
+ it "should see an explanation if the password was wrong" do
31
+ post :create, :member => valid_credentials.merge(:password => 'wrong')
32
+ should.not.be.authenticated
33
+ status.should.be :success
34
+ assert_select 'div.errorExplanation'
35
+ end
36
+
37
+ it "should see an explanation when the email does not exist" do
38
+ post :create, :member => valid_credentials.merge(:email => 'unknown@example.com')
39
+ should.not.be.authenticated
40
+ status.should.be :success
41
+ assert_select 'div.errorExplanation'
42
+ end
43
+
44
+ it "should keep the url to return to if the password or email was wrong" do
45
+ url = member_url(members(:adrian))
46
+ post :create, { :member => valid_credentials.merge(:password => 'wrong') }, {}, { :after_authentication => { :redirect_to => url }}
47
+ should.not.be.authenticated
48
+ controller.after_authentication[:redirect_to].should == url
49
+ end
50
+
51
+ private
52
+
53
+ def valid_credentials
54
+ { :email => members(:adrian).email, :password => 'secret' }
55
+ end
56
+ end
57
+
58
+ describe "On the", SessionsController, "a member" do
59
+ before do
60
+ login members(:adrian)
61
+ end
62
+
63
+ it "should be able to clear the logged in session" do
64
+ get :clear
65
+ should.not.be.authenticated
66
+ should.redirect_to root_url
67
+ end
68
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe "Model that includes ActiveRecord::Ext" do
4
+ it "should have a named scope to order" do
5
+ Member.order('email').should.equal_set Member.all
6
+ Member.order('email').map(&:email).should == Member.all.map(&:email).sort
7
+ Member.order('email', :desc).map(&:email).should == Member.all.map(&:email).sort.reverse
8
+ end
9
+
10
+ it "should have a named scope to limit" do
11
+ Member.limit(3).should.equal_set Member.all(:limit => 3)
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe "Token" do
4
+ it "should generate a token" do
5
+ Token.generate.should.not.be.blank
6
+ end
7
+
8
+ it "should not generate the same token twice in quick succession" do
9
+ Token.generate.should.not == Token.generate
10
+ end
11
+
12
+ it "should generate tokens of specific lengths" do
13
+ Token.generate(3).length.should == 3
14
+ Token.generate(40).length.should == 40
15
+ Token.generate(61).length.should == 61
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
4
+ require 'test_help'
5
+
6
+ require 'mocha'
7
+ require 'test/spec'
8
+ require 'test/spec/rails'
9
+ require 'test/spec/rails/macros'
10
+ require 'test/spec/share'
11
+
12
+ # require 'test/spec/add_allow_switch'
13
+ # Net::HTTP.add_allow_switch :start
14
+
15
+ class ActiveSupport::TestCase
16
+ self.use_transactional_fixtures = true
17
+ self.use_instantiated_fixtures = false
18
+ fixtures :all
19
+
20
+ $:.unshift(File.expand_path('../', __FILE__))
21
+
22
+ require 'ext/authentication'
23
+ include TestHelpers::Authentication
24
+
25
+ require 'ext/time'
26
+ include TestHelpers::Time
27
+
28
+ require 'ext/file_fixtures'
29
+ include TestHelpers::FileFixtures
30
+ end
31
+
32
+ ActionMailer::Base.default_url_options[:host] = 'test.host'
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ describe ApplicationHelper, "concerning navigation" do
4
+ attr_accessor :request
5
+ before do
6
+ @request = stub(:request_uri => '/members')
7
+ @controller = stub(:request => @request)
8
+ end
9
+
10
+ it "should generate a navigation link" do
11
+ assert_dom_equal('<a href="/passwords/new">Reset password</a>', nav_link_to('Reset password', '/passwords/new'))
12
+ assert_dom_equal('<a href="/members" class="current">Members</a>', nav_link_to('Members', '/members'))
13
+ end
14
+
15
+ it "should generate a navigation item" do
16
+ assert_dom_equal('<li><a href="/passwords/new">Reset password</a></li>', nav_item('Reset password', '/passwords/new'))
17
+ end
18
+
19
+ it "should generate a navigation item with extra options" do
20
+ assert_dom_equal('<li class="first"><a href="/passwords/new">Reset password</a></li>', nav_item('Reset password', '/passwords/new', :class => 'first'))
21
+ end
22
+
23
+ it "should generate a navigation item when the current page is equal to the navigation item" do
24
+ assert_dom_equal('<li class="current"><a href="/members">Members</a></li>', nav_item('Members', '/members'))
25
+ end
26
+
27
+ it "should generate a navigation item when the current page is equal to the navigation item with extra options" do
28
+ assert_dom_equal('<li class="first current"><a href="/members">Members</a></li>', nav_item('Members', '/members', :class => 'first'))
29
+ end
30
+
31
+ it "should generate a navigation item when the current page is more specific than the navigation item" do
32
+ @request = stub(:request_uri => '/members/12')
33
+ assert_dom_equal('<li class="current"><a href="/members">Members</a></li>', nav_item('Members', '/members'))
34
+ end
35
+
36
+ it "should generate a shallow navigation item that doesn't become current when a subpage is viewed" do
37
+ assert_dom_equal('<li><a href="/">Home</a></li>', nav_item('Home', '/', :shallow => true))
38
+ end
39
+
40
+ it "should generate a shallow navigation item that becomes current when the page it links to is viewed" do
41
+ @request = stub(:request_uri => '/')
42
+ assert_dom_equal('<li class="current"><a href="/">Home</a></li>', nav_item('Home', '/', :shallow => true))
43
+ end
44
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe "Mailer", ActionMailer::TestCase do
4
+ it "should render a reset password message" do
5
+ member = members(:adrian)
6
+ member.generate_reset_password_token!
7
+ url = "http://test.host/password/#{member.reset_password_token}/edit"
8
+
9
+ email = Mailer.create_reset_password_message(member, url)
10
+ email.to.first.should == member.email
11
+ email.body.should.include url
12
+ end
13
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ describe "Member, concerning authentication" do
4
+ it "should hash passwords" do
5
+ Member.hash_password('secret').should == 'e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4'
6
+ end
7
+
8
+ it "should authenticate users with correct credentials" do
9
+ member = Member.authenticate(:email => 'adrian@example.com', :password => 'secret')
10
+ member.errors.should.be.empty
11
+ end
12
+
13
+ it "should not authenticate users with incorrect credentials" do
14
+ member = Member.authenticate(:email => 'adrian@example.com', :password => 'incorrect')
15
+ member.errors.should.not.be.empty
16
+ member.errors.on(:base).should.not.be.blank
17
+ end
18
+
19
+ it "should not authenticate non-existant users" do
20
+ member = Member.authenticate(:email => 'unknown@example.com', :password => 'incorrect')
21
+ member.errors.should.not.be.empty
22
+ member.errors.on(:base).should.not.be.blank
23
+ end
24
+ end
25
+
26
+ describe "A member, concerning authentication" do
27
+ before do
28
+ @member = members(:adrian)
29
+ end
30
+
31
+ it "should require a password" do
32
+ @member.password = ''
33
+ @member.should.not.be.valid
34
+ @member.errors.on(:password).should.not.be.blank
35
+
36
+ @member.hashed_password = Member.hash_password('')
37
+ @member.should.not.be.valid
38
+ @member.errors.on(:password).should.not.be.blank
39
+ end
40
+
41
+ it "should automatically hash passwords" do
42
+ @member.password = 'secret'
43
+ @member.hashed_password.should == Member.hash_password('secret')
44
+
45
+ @member.password = 'not so secret'
46
+ @member.hashed_password.should == Member.hash_password('not so secret')
47
+ end
48
+
49
+ it "should respond to password" do
50
+ @member.should.respond_to(:password)
51
+ end
52
+
53
+ it "should generate a new reset password token" do
54
+ token = Token.generate
55
+ Token.stubs(:generate).returns(token)
56
+
57
+ @member.generate_reset_password_token!
58
+ @member.reload.reset_password_token.should == token
59
+ end
60
+
61
+ %w{ hashed_password role reset_password_token }.each do |attribute|
62
+ it "should not allow access to `#{attribute}'" do
63
+ before = @member.send(attribute)
64
+ @member.update_attributes(attribute => '[updated]')
65
+ @member.reload.send(attribute).should == before
66
+ end
67
+ end
68
+
69
+ it "should allow access to password and verify password" do
70
+ @member.update_attributes(:password => 'new', :verify_password => 'new')
71
+ @member.reload.hashed_password.should == Member.hash_password('new')
72
+ end
73
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe Member, "concerning validations" do
4
+ before do
5
+ @member = Member.new
6
+ end
7
+
8
+ it "should require an email" do
9
+ @member.email = ''
10
+ @member.should.not.be.valid
11
+ @member.errors.on(:email).should.not.be.blank
12
+ end
13
+
14
+ it "should require a valid email" do
15
+ @member.email = 'invalid'
16
+ @member.should.not.be.valid
17
+ @member.errors.on(:email).should.not.be.blank
18
+ end
19
+
20
+ it "should require a unique email" do
21
+ @member.email = members(:adrian).email
22
+ @member.should.not.be.valid
23
+ @member.errors.on(:email).should.not.be.blank
24
+ end
25
+ end
26
+
27
+ describe 'A', Member do
28
+ it "should allow access to email" do
29
+ members(:adrian).update_attributes(:email => 'new@example.com')
30
+ members(:adrian).reload.email.should == 'new@example.com'
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fingerrails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Manfred Stienstra
8
+ - Eloy Duran
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-10-28 00:00:00 +01:00
14
+ default_executable: fingerrails
15
+ dependencies: []
16
+
17
+ description: A self contained version of the Fingertips Rails template
18
+ email: eloy@fngtps.com
19
+ executables:
20
+ - fingerrails
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README.rdoc
25
+ files:
26
+ - .gitignore
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION
30
+ - bin/fingerrails
31
+ - fingerrails.gemspec
32
+ - fingertips.rb
33
+ - templates/.kick
34
+ - templates/Rakefile
35
+ - templates/app/controllers/application_controller.rb
36
+ - templates/app/controllers/members_controller.rb
37
+ - templates/app/controllers/passwords_controller.rb
38
+ - templates/app/controllers/sessions_controller.rb
39
+ - templates/app/helpers/application_helper.rb
40
+ - templates/app/models/mailer.rb
41
+ - templates/app/models/member.rb
42
+ - templates/app/models/member/authentication.rb
43
+ - templates/app/views/layouts/_application_javascript_includes.html.erb
44
+ - templates/app/views/layouts/_head.html.erb
45
+ - templates/app/views/layouts/application.html.erb
46
+ - templates/app/views/mailer/reset_password_message.erb
47
+ - templates/app/views/members/edit.html.erb
48
+ - templates/app/views/members/new.html.erb
49
+ - templates/app/views/members/show.html.erb
50
+ - templates/app/views/passwords/edit.html.erb
51
+ - templates/app/views/passwords/new.html.erb
52
+ - templates/app/views/passwords/reset.html.erb
53
+ - templates/app/views/passwords/sent.html.erb
54
+ - templates/app/views/sessions/_form.html.erb
55
+ - templates/app/views/sessions/_status.html.erb
56
+ - templates/app/views/sessions/new.html.erb
57
+ - templates/config/database.yml
58
+ - templates/lib/active_record_ext.rb
59
+ - templates/lib/token.rb
60
+ - templates/public/403.html
61
+ - templates/public/javascripts/ready.js
62
+ - templates/public/stylesheets/default.css
63
+ - templates/public/stylesheets/reset.css
64
+ - templates/test/ext/authentication.rb
65
+ - templates/test/ext/file_fixtures.rb
66
+ - templates/test/ext/time.rb
67
+ - templates/test/fixtures/members.yml
68
+ - templates/test/functional/application_controller_test.rb
69
+ - templates/test/functional/members_controller_test.rb
70
+ - templates/test/functional/passwords_controller_test.rb
71
+ - templates/test/functional/sessions_controller_test.rb
72
+ - templates/test/lib/active_record_ext_test.rb
73
+ - templates/test/lib/token_test.rb
74
+ - templates/test/test_helper.rb
75
+ - templates/test/unit/helpers/application_helper_test.rb
76
+ - templates/test/unit/mailer_test.rb
77
+ - templates/test/unit/member/authentication_test.rb
78
+ - templates/test/unit/member_test.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/Fingertips/rails-template
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --charset=UTF-8
86
+ require_paths:
87
+ - bin
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.5
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: A self contained version of the Fingertips Rails template
107
+ test_files: []
108
+