fetty-generators 1.7.1 → 2.0.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.
- data/Gemfile +2 -0
- data/README.rdoc +42 -36
- data/Rakefile +1 -3
- data/lib/generators/fetty.rb +160 -10
- data/lib/generators/fetty/authentication/USAGE +4 -0
- data/lib/generators/fetty/authentication/authentication_generator.rb +171 -0
- data/lib/generators/fetty/authentication/templates/controllers/reset_passwords_controller.rb +45 -0
- data/lib/generators/fetty/authentication/templates/controllers/sessions_controller.rb +30 -0
- data/lib/generators/fetty/authentication/templates/controllers/users_controller.rb +78 -0
- data/lib/generators/fetty/authentication/templates/helpers/reset_passwords_helper.rb +2 -0
- data/lib/generators/fetty/authentication/templates/helpers/sessions_helper.rb +2 -0
- data/lib/generators/fetty/authentication/templates/helpers/users_helper.rb +2 -0
- data/lib/generators/fetty/authentication/templates/lib/sessions_authentication.rb +53 -0
- data/lib/generators/fetty/authentication/templates/lib/users_authentication.rb +110 -0
- data/lib/generators/fetty/authentication/templates/mailers/setup_mail.rb +11 -0
- data/lib/generators/fetty/authentication/templates/mailers/user_mailer.rb +14 -0
- data/lib/generators/fetty/authentication/templates/models/active_record/create_users.rb +17 -0
- data/lib/generators/fetty/authentication/templates/models/active_record/user.rb +15 -0
- data/lib/generators/fetty/authentication/templates/models/mongoid/user.rb +23 -0
- data/lib/generators/fetty/authentication/templates/spec/controllers/reset_passwords_controller_spec.rb +93 -0
- data/lib/generators/fetty/authentication/templates/spec/controllers/sessions_controller_spec.rb +61 -0
- data/lib/generators/fetty/authentication/templates/spec/controllers/users_controller_spec.rb +158 -0
- data/lib/generators/fetty/authentication/templates/spec/models/user_spec.rb +108 -0
- data/lib/generators/fetty/authentication/templates/spec/routing/reset_passwords_routing_spec.rb +21 -0
- data/lib/generators/fetty/authentication/templates/spec/routing/sessions_routing_spec.rb +17 -0
- data/lib/generators/fetty/authentication/templates/spec/routing/users_routing_spec.rb +37 -0
- data/lib/generators/fetty/authentication/templates/spec/support/user_factories.rb +6 -0
- data/lib/generators/fetty/authentication/templates/views/layouts/application.html.erb +33 -0
- data/lib/generators/fetty/authentication/templates/views/reset_passwords/edit.html.erb +19 -0
- data/lib/generators/fetty/authentication/templates/views/reset_passwords/new.html.erb +14 -0
- data/lib/generators/fetty/authentication/templates/views/sessions/new.html.erb +22 -0
- data/lib/generators/fetty/authentication/templates/views/user_mailer/user_activation.text.erb +4 -0
- data/lib/generators/fetty/authentication/templates/views/user_mailer/user_forgot_password.text.erb +7 -0
- data/lib/generators/fetty/authentication/templates/views/users/_table.html.erb +23 -0
- data/lib/generators/fetty/authentication/templates/views/users/edit.html.erb +21 -0
- data/lib/generators/fetty/authentication/templates/views/users/index.html.erb +7 -0
- data/lib/generators/fetty/authentication/templates/views/users/index.js.erb +1 -0
- data/lib/generators/fetty/authentication/templates/views/users/new.html.erb +23 -0
- data/lib/generators/fetty/authentication/templates/views/users/show.html.erb +19 -0
- data/lib/generators/fetty/messages/USAGE +4 -0
- data/lib/generators/fetty/messages/messages_generator.rb +136 -0
- data/lib/generators/fetty/messages/templates/assets/javascripts/jquery.tokeninput.js +718 -0
- data/lib/generators/fetty/messages/templates/assets/javascripts/messages.js +19 -0
- data/lib/generators/fetty/messages/templates/assets/stylesheets/messages.css +87 -0
- data/lib/generators/fetty/messages/templates/assets/stylesheets/token-input-facebook.css +122 -0
- data/lib/generators/fetty/messages/templates/controllers/messages_controller.rb +109 -0
- data/lib/generators/fetty/messages/templates/helpers/messages_helper.rb +2 -0
- data/lib/generators/fetty/messages/templates/lib/users_messages.rb +67 -0
- data/lib/generators/fetty/messages/templates/models/active_record/create_messages.rb +24 -0
- data/lib/generators/fetty/messages/templates/models/active_record/message.rb +67 -0
- data/lib/generators/fetty/messages/templates/models/mongoid/message.rb +81 -0
- data/lib/generators/fetty/messages/templates/spec/controllers/messages_controller_spec.rb +78 -0
- data/lib/generators/fetty/messages/templates/spec/models/message_spec.rb +53 -0
- data/lib/generators/fetty/messages/templates/spec/routing/messages_routing_spec.rb +61 -0
- data/lib/generators/fetty/messages/templates/spec/support/message_factories.rb +8 -0
- data/lib/generators/fetty/messages/templates/views/_head.html.erb +20 -0
- data/lib/generators/fetty/messages/templates/views/_messages.html.erb +56 -0
- data/lib/generators/fetty/messages/templates/views/_tabs_panel.html.erb +11 -0
- data/lib/generators/fetty/messages/templates/views/index.html.erb +10 -0
- data/lib/generators/fetty/messages/templates/views/index.js.erb +1 -0
- data/lib/generators/fetty/messages/templates/views/new.html.erb +26 -0
- data/lib/generators/fetty/messages/templates/views/show.html.erb +35 -0
- data/lib/generators/fetty/scaffold/USAGE +2 -52
- data/lib/generators/fetty/scaffold/scaffold_generator.rb +96 -329
- data/lib/generators/fetty/scaffold/templates/controllers/active_record/controller.rb +60 -0
- data/lib/generators/fetty/scaffold/templates/controllers/mongoid/controller.rb +60 -0
- data/lib/generators/fetty/scaffold/templates/helpers/helper.rb +2 -0
- data/lib/generators/fetty/scaffold/templates/models/active_record/migration.rb +16 -0
- data/lib/generators/fetty/scaffold/templates/models/active_record/model.rb +10 -0
- data/lib/generators/fetty/scaffold/templates/models/mongoid/model.rb +16 -0
- data/lib/generators/fetty/scaffold/templates/test/rspec/controller.rb +98 -0
- data/lib/generators/fetty/scaffold/templates/test/rspec/factories.rb +26 -0
- data/lib/generators/fetty/scaffold/templates/test/rspec/helper.rb +15 -0
- data/lib/generators/fetty/scaffold/templates/test/rspec/model.rb +9 -0
- data/lib/generators/fetty/scaffold/templates/test/rspec/request.rb +11 -0
- data/lib/generators/fetty/scaffold/templates/test/rspec/routing.rb +41 -0
- data/lib/generators/fetty/scaffold/templates/test/test_unit/controller.rb +62 -0
- data/lib/generators/fetty/scaffold/templates/{fixtures.yml → test/test_unit/fixtures.yml} +2 -0
- data/lib/generators/fetty/scaffold/templates/test/test_unit/helper.rb +4 -0
- data/lib/generators/fetty/scaffold/templates/test/test_unit/model.rb +7 -0
- data/lib/generators/fetty/scaffold/templates/views/_form.html.erb +20 -0
- data/lib/generators/fetty/scaffold/templates/views/_table.html.erb +48 -0
- data/lib/generators/fetty/scaffold/templates/views/edit.html.erb +13 -0
- data/lib/generators/fetty/scaffold/templates/views/index.html.erb +15 -0
- data/lib/generators/fetty/scaffold/templates/views/{erb/index.js.erb → index.js.erb} +0 -0
- data/lib/generators/fetty/scaffold/templates/views/new.html.erb +9 -0
- data/lib/generators/fetty/scaffold/templates/views/show.html.erb +28 -0
- data/lib/generators/fetty/setup/USAGE +3 -20
- data/lib/generators/fetty/setup/setup_generator.rb +122 -61
- data/lib/generators/fetty/setup/templates/ability.rb +0 -0
- data/lib/generators/fetty/setup/templates/ckeditor.rb +54 -0
- data/lib/generators/fetty/setup/templates/ckeditor.tar.gz +0 -0
- data/lib/generators/fetty/setup/templates/escape_utils.rb +7 -0
- data/lib/generators/fetty/setup/templates/file_uploader.rb +15 -0
- data/lib/generators/fetty/setup/templates/image_uploader.rb +48 -0
- data/lib/generators/fetty/setup/templates/spec_helper.rb +44 -0
- data/lib/generators/fetty/views/USAGE +5 -0
- data/lib/generators/fetty/{layout/templates/stylesheet.css → views/templates/application.css} +184 -166
- data/lib/generators/fetty/views/templates/application.html.erb +23 -0
- data/lib/generators/fetty/{layout → views}/templates/application.js +0 -0
- data/lib/generators/fetty/views/templates/application_helper.rb +10 -0
- data/lib/generators/fetty/views/templates/down_arrow.gif +0 -0
- data/lib/generators/fetty/{layout → views}/templates/error_messages_helper.rb +0 -0
- data/lib/generators/fetty/{layout → views}/templates/layout_helper.rb +0 -0
- data/lib/generators/fetty/views/templates/up_arrow.gif +0 -0
- data/lib/generators/fetty/views/views_generator.rb +51 -0
- data/lib/generators/scaffold.rb +204 -0
- metadata +126 -111
- data/LICENSE +0 -20
- data/lib/generators/fetty/layout/USAGE +0 -26
- data/lib/generators/fetty/layout/layout_generator.rb +0 -44
- data/lib/generators/fetty/layout/templates/layout.html.erb +0 -32
- data/lib/generators/fetty/layout/templates/layout.html.haml +0 -34
- data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.erb +0 -23
- data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.haml +0 -23
- data/lib/generators/fetty/layout/templates/stylesheet.sass +0 -163
- data/lib/generators/fetty/scaffold/templates/actions/create.rb +0 -8
- data/lib/generators/fetty/scaffold/templates/actions/destroy.rb +0 -5
- data/lib/generators/fetty/scaffold/templates/actions/edit.rb +0 -3
- data/lib/generators/fetty/scaffold/templates/actions/index.rb +0 -10
- data/lib/generators/fetty/scaffold/templates/actions/new.rb +0 -3
- data/lib/generators/fetty/scaffold/templates/actions/show.rb +0 -3
- data/lib/generators/fetty/scaffold/templates/actions/update.rb +0 -8
- data/lib/generators/fetty/scaffold/templates/controller.rb +0 -7
- data/lib/generators/fetty/scaffold/templates/helper.rb +0 -2
- data/lib/generators/fetty/scaffold/templates/migration.rb +0 -16
- data/lib/generators/fetty/scaffold/templates/model.rb +0 -7
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/create.rb +0 -11
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/destroy.rb +0 -6
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/edit.rb +0 -4
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/index.rb +0 -4
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/new.rb +0 -4
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/show.rb +0 -4
- data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/update.rb +0 -11
- data/lib/generators/fetty/scaffold/templates/tests/rspec/controller.rb +0 -8
- data/lib/generators/fetty/scaffold/templates/tests/rspec/model.rb +0 -7
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/create.rb +0 -13
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/destroy.rb +0 -8
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/edit.rb +0 -6
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/index.rb +0 -6
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/new.rb +0 -6
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/show.rb +0 -6
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/update.rb +0 -13
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/controller.rb +0 -5
- data/lib/generators/fetty/scaffold/templates/tests/shoulda/model.rb +0 -7
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/create.rb +0 -11
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/destroy.rb +0 -6
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/edit.rb +0 -4
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/index.rb +0 -4
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/new.rb +0 -4
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/show.rb +0 -4
- data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/update.rb +0 -11
- data/lib/generators/fetty/scaffold/templates/tests/testunit/controller.rb +0 -5
- data/lib/generators/fetty/scaffold/templates/tests/testunit/model.rb +0 -7
- data/lib/generators/fetty/scaffold/templates/views/erb/_form.html.erb +0 -22
- data/lib/generators/fetty/scaffold/templates/views/erb/_table.html.erb +0 -50
- data/lib/generators/fetty/scaffold/templates/views/erb/edit.html.erb +0 -12
- data/lib/generators/fetty/scaffold/templates/views/erb/index.html.erb +0 -13
- data/lib/generators/fetty/scaffold/templates/views/erb/new.html.erb +0 -9
- data/lib/generators/fetty/scaffold/templates/views/erb/show.html.erb +0 -26
- data/lib/generators/fetty/scaffold/templates/views/haml/_form.html.haml +0 -8
- data/lib/generators/fetty/scaffold/templates/views/haml/_table.html.haml +0 -33
- data/lib/generators/fetty/scaffold/templates/views/haml/edit.html.haml +0 -14
- data/lib/generators/fetty/scaffold/templates/views/haml/index.html.haml +0 -12
- data/lib/generators/fetty/scaffold/templates/views/haml/index.js.haml +0 -1
- data/lib/generators/fetty/scaffold/templates/views/haml/new.html.haml +0 -8
- data/lib/generators/fetty/scaffold/templates/views/haml/show.html.haml +0 -23
data/lib/generators/fetty/authentication/templates/spec/controllers/sessions_controller_spec.rb
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SessionsController do
|
|
4
|
+
|
|
5
|
+
describe "GET new" do
|
|
6
|
+
it "should render sign-in page" do
|
|
7
|
+
get :new
|
|
8
|
+
response.should be_success
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "POST create" do
|
|
13
|
+
describe "with valid params" do
|
|
14
|
+
it "should authenticate user" do
|
|
15
|
+
user = Factory(:user, :email => "some@email.com", :password => "secret", :password_confirmation => "secret")
|
|
16
|
+
User.stub(:authenticate!).with("some@email.com", "secret").and_return(user)
|
|
17
|
+
post :create, :login => "some@email.com", :password => "secret"
|
|
18
|
+
assigns(:user).should be_a(User)
|
|
19
|
+
assigns(:current_user).should eql(user)
|
|
20
|
+
flash[:notice].should_not be_nil
|
|
21
|
+
response.should redirect_to(root_path)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "with invalid params" do
|
|
26
|
+
it "should not authenticate if user not exists" do
|
|
27
|
+
User.stub(:authenticate!).with("some@email.com", "secret").and_return(UsersAuthentication::Status::Unexist)
|
|
28
|
+
post :create, :login => "some@email.com", :password => "secret"
|
|
29
|
+
assigns(:user).should eql(UsersAuthentication::Status::Unexist)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should not authenticate if given password invalid" do
|
|
33
|
+
User.stub(:authenticate!).with("some@email.com", "secret").and_return(UsersAuthentication::Status::InvalidPassword)
|
|
34
|
+
post :create, :login => "some@email.com", :password => "secret"
|
|
35
|
+
assigns(:user).should eql(UsersAuthentication::Status::InvalidPassword)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should not authenticate if user not activated" do
|
|
39
|
+
User.stub(:authenticate!).with("some@email.com", "secret").and_return(UsersAuthentication::Status::Inactivated)
|
|
40
|
+
post :create, :login => "some@email.com", :password => "secret"
|
|
41
|
+
assigns(:user).should eql(UsersAuthentication::Status::Inactivated)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
after(:each) do
|
|
45
|
+
flash[:alert].should_not be_nil
|
|
46
|
+
response.should render_template(:new)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "DELETE destroy" do
|
|
52
|
+
it "should destroy session or cookies" do
|
|
53
|
+
stub_authenticate_user
|
|
54
|
+
delete :destroy
|
|
55
|
+
assigns(:current_user).should be_nil
|
|
56
|
+
flash[:notice].should_not be_nil
|
|
57
|
+
response.should redirect_to(root_path)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe UsersController do
|
|
4
|
+
|
|
5
|
+
def test_assigns_user_object(action)
|
|
6
|
+
user = Factory(:user)
|
|
7
|
+
User.stub(:find).with(user.id.to_s).and_return(user)
|
|
8
|
+
get action, :id => user.id.to_s
|
|
9
|
+
assigns(:user).should eql(user)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_passing_valid_paramaters
|
|
13
|
+
assigns(:user).username.should be_a_kind_of(String)
|
|
14
|
+
assigns(:user).email.should be_a_kind_of(String)
|
|
15
|
+
assigns(:user).password.should be_a_kind_of(String)
|
|
16
|
+
assigns(:user).password_confirmation.should be_a_kind_of(String)
|
|
17
|
+
assigns(:user).password.should eql(assigns(:user).password_confirmation)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "GET index" do
|
|
21
|
+
it "assigns all users as @users" do
|
|
22
|
+
stub_authenticate_user
|
|
23
|
+
get :index
|
|
24
|
+
assigns(:users).should_not be_nil
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "GET new" do
|
|
29
|
+
it "assigns a new user as @user" do
|
|
30
|
+
get :new
|
|
31
|
+
assigns(:user).should be_a_new(User)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "POST create" do
|
|
36
|
+
describe "with valid params" do
|
|
37
|
+
it "should create user and redirect to sign-in page" do
|
|
38
|
+
User.any_instance.stub(:valid?).and_return(true)
|
|
39
|
+
post :create, Factory.attributes_for(:user)
|
|
40
|
+
test_passing_valid_paramaters
|
|
41
|
+
assigns(:user).should_not be_new_record
|
|
42
|
+
flash[:notice].should_not be_nil
|
|
43
|
+
response.should redirect_to(new_session_path)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "with invalid params" do
|
|
48
|
+
it "should not create user and re-render the sign-up page" do
|
|
49
|
+
User.any_instance.stub(:valid?).and_return(false)
|
|
50
|
+
post :create
|
|
51
|
+
assigns(:user).should be_new_record
|
|
52
|
+
flash[:alert].should_not be_nil
|
|
53
|
+
response.should render_template(:new)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "GET show" do
|
|
59
|
+
it "should assigns the requested user as @user" do
|
|
60
|
+
test_assigns_user_object :show
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe "GET edit" do
|
|
65
|
+
it "should assigns the authenticated user as @user" do
|
|
66
|
+
stub_authenticate_user
|
|
67
|
+
test_assigns_user_object :edit
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe "PUT update" do
|
|
72
|
+
|
|
73
|
+
before(:each) do
|
|
74
|
+
stub_authenticate_user
|
|
75
|
+
@user = Factory(:user)
|
|
76
|
+
User.stub(:find).with(@user.id.to_s).and_return(@user)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "with valid params" do
|
|
80
|
+
it "should update user and redirect back to user path" do
|
|
81
|
+
User.any_instance.stub(:valid?).and_return(true)
|
|
82
|
+
put :update, Factory.attributes_for(:user, :id => @user.id.to_s)
|
|
83
|
+
test_passing_valid_paramaters
|
|
84
|
+
assigns(:user).should eql(@user)
|
|
85
|
+
flash[:notice].should_not be_nil
|
|
86
|
+
response.should redirect_to(user_path(@user))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe "with invalid params" do
|
|
91
|
+
it "should not change user and re-render page" do
|
|
92
|
+
User.any_instance.stub(:valid?).and_return(false)
|
|
93
|
+
put :update, :id => @user.id.to_s
|
|
94
|
+
assigns(:user).should eql(@user)
|
|
95
|
+
flash[:alert].should_not be_nil
|
|
96
|
+
response.should render_template(:edit)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe "DELETE destroy" do
|
|
102
|
+
before(:each) do
|
|
103
|
+
stub_authenticate_user
|
|
104
|
+
@user = Factory(:user)
|
|
105
|
+
User.stub(:find).with(@user.id.to_s).and_return(@user)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should delete self user with authenticate user and redirect to sign-in page" do
|
|
109
|
+
controller.stub(:current_user).and_return(@user)
|
|
110
|
+
delete :destroy, :id => @user.id.to_s
|
|
111
|
+
flash[:notice].should_not be_nil
|
|
112
|
+
response.should redirect_to(new_session_path)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should delete other user and redirect to users list" do
|
|
116
|
+
controller.stub(:current_user).and_return(nil)
|
|
117
|
+
delete :destroy, :id => @user.id.to_s
|
|
118
|
+
flash[:notice].should_not be_nil
|
|
119
|
+
response.should redirect_to(users_path)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe "GET activate" do
|
|
124
|
+
before(:each) do
|
|
125
|
+
@user = Factory(:user, :token => "sometoken")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
describe "with valid params" do
|
|
129
|
+
it "should activate user with given id and token" do
|
|
130
|
+
User.stub(:activate!).with(@user.id.to_s, @user.token).and_return(@user)
|
|
131
|
+
get :activate, :id => @user.id.to_s, :token => @user.token
|
|
132
|
+
assigns(:user).should be_a(User)
|
|
133
|
+
flash[:notice].should_not be_nil
|
|
134
|
+
response.should redirect_to(root_path)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
describe "with invalid params" do
|
|
139
|
+
it "should not activate user if user not exists" do
|
|
140
|
+
User.stub(:activate!).with(@user.id.to_s, @user.token).and_return(UsersAuthentication::Status::Unexist)
|
|
141
|
+
get :activate, :id => @user.id.to_s, :token => @user.token
|
|
142
|
+
assigns(:user).should eql(UsersAuthentication::Status::Unexist)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "should not activate user if user already active" do
|
|
146
|
+
User.stub(:activate!).with(@user.id.to_s, @user.token).and_return(UsersAuthentication::Status::Activated)
|
|
147
|
+
get :activate, :id => @user.id.to_s, :token => @user.token
|
|
148
|
+
assigns(:user).should eql(UsersAuthentication::Status::Activated)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
after(:each) do
|
|
152
|
+
flash[:alert].should_not be_nil
|
|
153
|
+
response.should redirect_to(new_session_path)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe User do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@user = User.new
|
|
7
|
+
@user.attributes = Factory.attributes_for(:user)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should be valid" do
|
|
11
|
+
@user.should be_valid
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should have error on username if username is nil" do
|
|
15
|
+
@user.username = nil
|
|
16
|
+
@user.should have(2).error_on(:username)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should have error on email if email is nil" do
|
|
20
|
+
@user.email = nil
|
|
21
|
+
@user.should have(2).error_on(:email)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should have error on email if email is not a valid email address" do
|
|
25
|
+
@user.email = "some_email"
|
|
26
|
+
@user.should have(1).error_on(:email)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should have error on password / password_confirmation if password is nil" do
|
|
30
|
+
@user.password = nil
|
|
31
|
+
@user.password_confirmation = nil
|
|
32
|
+
@user.should have(2).error_on(:password)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should have error on password / password_confirmation if password is less than 6" do
|
|
36
|
+
@user.password = "123"
|
|
37
|
+
@user.password_confirmation = "123"
|
|
38
|
+
@user.should have(1).error_on(:password)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe User, "Authentication Methods" do
|
|
44
|
+
|
|
45
|
+
before(:each) do
|
|
46
|
+
@user = Factory(:user, :username => "fajri", :password => "secret")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# check class method authenticate!
|
|
50
|
+
it "should authenticate with matching username and password" do
|
|
51
|
+
@user.activated_at = Date.today
|
|
52
|
+
@user.save
|
|
53
|
+
User.authenticate!('fajri', 'secret').should eql(@user)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should not authenticate with incorrect password" do
|
|
57
|
+
User.authenticate!('fajri', 'incorrect').should be(UsersAuthentication::Status::InvalidPassword)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should not authenticate if record not activated" do
|
|
61
|
+
User.authenticate!('fajri', 'secret').should be(UsersAuthentication::Status::Inactivated)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# check class method activate!
|
|
65
|
+
it "should activate with matching id and token" do
|
|
66
|
+
User.activate!(@user.id,@user.token).should eql(@user)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should not activate if user record not exists" do
|
|
70
|
+
User.activate!("id","token").should be(UsersAuthentication::Status::Unexist)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should not activate if user already active" do
|
|
74
|
+
user = User.activate!(@user.id,@user.token)
|
|
75
|
+
User.activate!(user.id,user.token).should be(UsersAuthentication::Status::Activated)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe User, "Reset Password Methods" do
|
|
81
|
+
|
|
82
|
+
before(:each) do
|
|
83
|
+
@user = Factory(:user, :username => "fajri", :password => "secret")
|
|
84
|
+
@user = User.activate!(@user.id,@user.token)
|
|
85
|
+
@user.make_token!
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should be able to reset password with given id and token" do
|
|
89
|
+
user = User.first(:conditions => { :id => @user.id, :token => @user.token })
|
|
90
|
+
user.should_not be_nil
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "should not be able to reset password if id and token are not exists" do
|
|
94
|
+
user = User.first(:conditions => { :id => "id", :token => "token" })
|
|
95
|
+
user.should be_nil
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "should change password if given new password are correct" do
|
|
99
|
+
user = User.first(:conditions => { :id => @user.id, :token => @user.token })
|
|
100
|
+
user.reset_password("123456","123456").should be(UsersAuthentication::Status::Valid)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should not change password if given new password less than 6" do
|
|
104
|
+
user = User.first(:conditions => { :id => @user.id, :token => @user.token })
|
|
105
|
+
user.reset_password("123","123").should_not be(UsersAuthentication::Status::Valid)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
data/lib/generators/fetty/authentication/templates/spec/routing/reset_passwords_routing_spec.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ResetPasswordsController do
|
|
4
|
+
describe "routing" do
|
|
5
|
+
it "routes to #new" do
|
|
6
|
+
get("/users/reset_password/new").should route_to("reset_passwords#new")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "routes to #create" do
|
|
10
|
+
post("/users/reset_password").should route_to("reset_passwords#create")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "routes to #edit" do
|
|
14
|
+
get("/users/reset_password/1/434343").should route_to("reset_passwords#edit", :id => "1", :token => "434343")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "routes to #update" do
|
|
18
|
+
put("/users/reset_password").should route_to("reset_passwords#update")
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SessionsController do
|
|
4
|
+
describe "routing" do
|
|
5
|
+
it "routes to #new" do
|
|
6
|
+
get("/users/session/new").should route_to("sessions#new")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "routes to #create" do
|
|
10
|
+
post("/users/session").should route_to("sessions#create")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "routes to #destroy" do
|
|
14
|
+
delete("/users/session").should route_to("sessions#destroy")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe UsersController do
|
|
4
|
+
describe "routing" do
|
|
5
|
+
it "routes to #index" do
|
|
6
|
+
get("/users").should route_to("users#index")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "routes to #show" do
|
|
10
|
+
get("/users/1").should route_to("users#show", :id => "1")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "routes to #new" do
|
|
14
|
+
get("/users/new").should route_to("users#new")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "routes to #create" do
|
|
18
|
+
post("/users").should route_to("users#create")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "routes to #edit" do
|
|
22
|
+
get("/users/1/edit").should route_to("users#edit", :id => "1")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "routes to #update" do
|
|
26
|
+
put("/users/1").should route_to("users#update", :id => "1")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "routes to #destroy" do
|
|
30
|
+
delete("/users/1").should route_to("users#destroy", :id => "1")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "routes to #activate" do
|
|
34
|
+
get("/users/activate/1/434343").should route_to("users#activate", :id => "1", :token => "434343")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
|
|
5
|
+
<%= stylesheet_link_tag 'application' %>
|
|
6
|
+
<%= javascript_include_tag :defaults %>
|
|
7
|
+
<%= csrf_meta_tag %>
|
|
8
|
+
<%= yield(:head) %>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="container">
|
|
12
|
+
<% flash.each do |name, msg| %>
|
|
13
|
+
<%= content_tag(:div, :id => "flash_#{name}", :class => "flash closable") do %>
|
|
14
|
+
<%=h msg %>
|
|
15
|
+
<%= content_tag(:span, "[close]", :title => "close", :class => "closelink") %>
|
|
16
|
+
<% end %>
|
|
17
|
+
<% end %>
|
|
18
|
+
|
|
19
|
+
<div id='loginbox'>
|
|
20
|
+
<% if user_signed_in? %>
|
|
21
|
+
Signed in as <%= link_to current_user.username, user_path(current_user) %> Not You?
|
|
22
|
+
<%= link_to 'Sign out', session_path, :method => :delete %>
|
|
23
|
+
<% else %>
|
|
24
|
+
<%= link_to 'Sign up', new_user_path %> or <%= link_to 'Sign in', new_session_path %>
|
|
25
|
+
<% end %>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
<%= content_tag :h1, yield(:title) if show_title? %>
|
|
30
|
+
<%= yield %>
|
|
31
|
+
</div>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|