adminpanel 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -2
- data/.ruby-version +1 -0
- data/.travis.yml +8 -8
- data/Gemfile +26 -24
- data/README.md +57 -57
- data/adminpanel.gemspec +41 -39
- data/app/assets/fonts/fontawesome-webfont.svg +254 -254
- data/app/assets/javascripts/adminpanel/bootstrap-datepicker.js +1159 -1159
- data/app/assets/javascripts/adminpanel/bootstrap-timepicker.js +803 -803
- data/app/assets/javascripts/adminpanel/bootstrap.js +2170 -2170
- data/app/assets/javascripts/adminpanel/{products.js → images_form.js} +13 -13
- data/app/assets/javascripts/adminpanel/imagesloaded.js +12 -12
- data/app/assets/javascripts/adminpanel/jquery.dataTables.min.js +155 -155
- data/app/assets/javascripts/adminpanel/jquery.facybox.js +395 -395
- data/app/assets/javascripts/adminpanel/jquery.masonry.min.js +9 -9
- data/app/assets/javascripts/adminpanel/jquery.slimscroll.min.js +13 -13
- data/app/assets/javascripts/adminpanel/medium-editor.js +702 -702
- data/app/assets/javascripts/adminpanel/realm.js +87 -87
- data/app/assets/javascripts/adminpanel/tables.js +126 -126
- data/app/assets/javascripts/application-admin.js +15 -15
- data/app/assets/stylesheets/adminpanel/_clearfix.css.scss +7 -7
- data/app/assets/stylesheets/adminpanel/alertify.css +241 -241
- data/app/assets/stylesheets/adminpanel/bootstrap.css +6103 -6103
- data/app/assets/stylesheets/adminpanel/colorpicker.css +6 -6
- data/app/assets/stylesheets/adminpanel/datepicker.css +9 -9
- data/app/assets/stylesheets/adminpanel/elfinder.min.css +59 -59
- data/app/assets/stylesheets/adminpanel/facybox.css +146 -146
- data/app/assets/stylesheets/adminpanel/font-awesome.min.css +33 -33
- data/app/assets/stylesheets/adminpanel/fullcalendar.css +618 -618
- data/app/assets/stylesheets/adminpanel/fullcalendar.print.css +61 -61
- data/app/assets/stylesheets/adminpanel/select2.css +524 -524
- data/app/assets/stylesheets/adminpanel/theme.css +1571 -1571
- data/app/assets/stylesheets/adminpanel/timepicker.css +82 -82
- data/app/assets/stylesheets/application-admin.css +13 -13
- data/app/controllers/adminpanel/application_controller.rb +32 -17
- data/app/controllers/adminpanel/galleries_controller.rb +80 -80
- data/app/controllers/adminpanel/sections_controller.rb +45 -45
- data/app/controllers/adminpanel/sessions_controller.rb +26 -26
- data/app/controllers/adminpanel/users_controller.rb +84 -84
- data/app/helpers/adminpanel/application_helper.rb +41 -51
- data/app/helpers/adminpanel/breadcrumbs_helper.rb +16 -0
- data/app/helpers/adminpanel/custom_form_builder.rb +248 -0
- data/app/helpers/adminpanel/images_helper.rb +9 -9
- data/app/helpers/adminpanel/rest_actions_helper.rb +47 -0
- data/app/helpers/adminpanel/router_helper.rb +33 -0
- data/app/helpers/adminpanel/sessions_helper.rb +25 -25
- data/app/models/adminpanel/gallery.rb +60 -60
- data/app/models/adminpanel/image.rb +14 -14
- data/app/models/adminpanel/section.rb +22 -22
- data/app/models/adminpanel/user.rb +35 -35
- data/app/uploaders/adminpanel/gallery_uploader.rb +55 -55
- data/app/uploaders/adminpanel/image_uploader.rb +57 -57
- data/app/views/adminpanel/galleries/_galleries_table.html.erb +14 -14
- data/app/views/adminpanel/galleries/create.html.erb +2 -2
- data/app/views/adminpanel/galleries/delete.html.erb +2 -2
- data/app/views/adminpanel/galleries/edit.html.erb +25 -25
- data/app/views/adminpanel/galleries/index.html.erb +51 -51
- data/app/views/adminpanel/galleries/new.html.erb +17 -17
- data/app/views/adminpanel/galleries/show.html.erb +17 -17
- data/app/views/adminpanel/galleries/update.html.erb +2 -2
- data/app/views/adminpanel/sections/_image_fields.html.erb +23 -23
- data/app/views/adminpanel/sections/_sections_table.html.erb +16 -16
- data/app/views/adminpanel/sections/create.html.erb +2 -2
- data/app/views/adminpanel/sections/destroy.html.erb +2 -2
- data/app/views/adminpanel/sections/edit.html.erb +41 -41
- data/app/views/adminpanel/sections/index.html.erb +44 -44
- data/app/views/adminpanel/sections/new.html.erb +26 -26
- data/app/views/adminpanel/sections/show.html.erb +30 -30
- data/app/views/adminpanel/sections/update.html.erb +2 -2
- data/app/views/adminpanel/sessions/new.html.erb +25 -25
- data/app/views/adminpanel/users/_user_form.html.erb +20 -20
- data/app/views/adminpanel/users/edit.html.erb +5 -5
- data/app/views/adminpanel/users/index.html.erb +49 -49
- data/app/views/adminpanel/users/new.html.erb +5 -5
- data/app/views/adminpanel/users/show.html.erb +20 -20
- data/app/views/layouts/_shim.html.erb +3 -3
- data/app/views/layouts/_side_menu.html.erb +49 -43
- data/app/views/layouts/_top_bar.html.erb +43 -43
- data/app/views/layouts/admin-login.html.erb +28 -28
- data/app/views/layouts/admin.html.erb +41 -39
- data/app/views/shared/_breadcrumb.html.erb +6 -6
- data/app/views/shared/_error_messages.html.erb +16 -16
- data/app/views/shared/_form_fields.html.erb +25 -0
- data/app/views/{adminpanel/products → shared}/_image_fields.html.erb +23 -23
- data/app/views/shared/_init_editor.html.erb +24 -0
- data/app/views/shared/edit.html.erb +28 -0
- data/app/views/shared/index.html.erb +94 -0
- data/app/views/shared/new.html.erb +28 -0
- data/app/views/shared/show.html.erb +63 -0
- data/config/locales/en.yml +5 -5
- data/config/locales/es.yml +127 -129
- data/config/routes.rb +24 -16
- data/lib/adminpanel.rb +9 -7
- data/lib/adminpanel/active_record_extension.rb +38 -0
- data/lib/adminpanel/engine.rb +5 -5
- data/lib/adminpanel/version.rb +3 -3
- data/lib/generators/adminpanel/initialize/initialize_generator.rb +17 -0
- data/lib/generators/adminpanel/{install/templates/migrations → initialize/templates}/create_adminpanel_tables.rb +45 -64
- data/lib/generators/adminpanel/resource/resource_generator.rb +105 -0
- data/lib/generators/adminpanel/resource/templates/controller.rb +4 -0
- data/lib/generators/adminpanel/resource/templates/migration.rb +9 -0
- data/lib/generators/adminpanel/resource/templates/resource.rb +19 -0
- data/spec/dummy/.gitignore +17 -17
- data/spec/dummy/README.rdoc +261 -261
- data/spec/dummy/Rakefile +7 -7
- data/{app/views/adminpanel/categories/show.html.erb → spec/dummy/app/adminpanel/products.rb} +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -13
- data/spec/dummy/app/assets/stylesheets/application.css +13 -13
- data/spec/dummy/app/controllers/adminpanel/.gitkeep +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -11
- data/spec/dummy/app/helpers/application_helper.rb +2 -2
- data/spec/dummy/app/views/layouts/application.html.erb +14 -14
- data/spec/dummy/config.ru +4 -4
- data/spec/dummy/config/application.rb +62 -62
- data/spec/dummy/config/boot.rb +9 -9
- data/spec/dummy/config/carrierwve.rb +5 -5
- data/spec/dummy/config/database.yml +24 -24
- data/spec/dummy/config/environment.rb +5 -5
- data/spec/dummy/config/environments/development.rb +41 -41
- data/spec/dummy/config/environments/production.rb +72 -72
- data/spec/dummy/config/environments/test.rb +41 -41
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/dummy/config/initializers/inflections.rb +15 -15
- data/spec/dummy/config/initializers/mime_types.rb +5 -5
- data/spec/dummy/config/initializers/secret_token.rb +8 -8
- data/spec/dummy/config/initializers/session_store.rb +8 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +5 -5
- data/spec/dummy/config/routes.rb +4 -4
- data/spec/dummy/db/schema.rb +15 -15
- data/spec/dummy/public/404.html +26 -26
- data/spec/dummy/public/422.html +26 -26
- data/spec/dummy/public/500.html +25 -25
- data/spec/dummy/public/uploads/gallery/file/1/hipster.jpg +0 -0
- data/spec/dummy/public/uploads/gallery/file/1/thumb_hipster.jpg +0 -0
- data/spec/dummy/script/rails +6 -6
- data/spec/features/authentication_pages_spec.rb +43 -43
- data/spec/features/galleries_pages_spec.rb +124 -124
- data/spec/features/section_pages_spec.rb +37 -37
- data/spec/features/user_pages_spec.rb +48 -48
- data/spec/generators/initialize_spec.rb +9 -0
- data/spec/generators/resource_spec.rb +122 -0
- data/spec/models/gallery_spec.rb +21 -21
- data/spec/models/section_spec.rb +66 -66
- data/spec/models/user_spec.rb +105 -105
- data/spec/spec_helper.rb +32 -31
- data/spec/support/define_factory_models.rb +25 -36
- data/spec/support/helper_methods.rb +26 -26
- data/spec/support/submit_forms_without_button.rb +16 -16
- data/spec/support/test_database.rb +45 -58
- data/spec/uploaders/gallery_uploader_spec.rb +36 -30
- data/spec/uploaders/image_uploader_spec.rb +30 -29
- metadata +208 -64
- checksums.yaml +0 -7
- data/app/assets/javascripts/adminpanel/init_editor.js +0 -28
- data/app/controllers/adminpanel/categories_controller.rb +0 -41
- data/app/controllers/adminpanel/products_controller.rb +0 -88
- data/app/helpers/custom_form_builder.rb +0 -219
- data/app/models/adminpanel/category.rb +0 -7
- data/app/models/adminpanel/product.rb +0 -24
- data/app/views/adminpanel/categories/edit.html.erb +0 -18
- data/app/views/adminpanel/categories/index.html.erb +0 -55
- data/app/views/adminpanel/categories/new.html.erb +0 -18
- data/app/views/adminpanel/products/.DS_Store +0 -0
- data/app/views/adminpanel/products/_product_form.html.erb +0 -31
- data/app/views/adminpanel/products/edit.html.erb +0 -10
- data/app/views/adminpanel/products/index.html.erb +0 -51
- data/app/views/adminpanel/products/new.html.erb +0 -10
- data/app/views/adminpanel/products/show.html.erb +0 -61
- data/config/database.yml +0 -24
- data/lib/generators/adminpanel/install/install_generator.rb +0 -12
- data/spec/features/categories_pages_spec.rb +0 -44
- data/spec/features/product_pages_spec.rb +0 -64
- data/spec/models/category_spec.rb +0 -58
- data/spec/models/product_spec.rb +0 -51
data/spec/models/gallery_spec.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Adminpanel::Gallery do
|
4
|
-
before do
|
5
|
-
@gallery = Adminpanel::Gallery.new(
|
6
|
-
:file => "Test file"
|
7
|
-
)
|
8
|
-
end
|
9
|
-
|
10
|
-
subject { @gallery }
|
11
|
-
|
12
|
-
it { should respond_to(:file) }
|
13
|
-
|
14
|
-
describe "when file is not present" do
|
15
|
-
before {@gallery.file = " "}
|
16
|
-
it {should_not be_valid}
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "default scope" do
|
20
|
-
it { expect(Adminpanel::Gallery.scoped.to_sql).to eq Adminpanel::Gallery.reorder('').order('position ASC').to_sql}
|
21
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Adminpanel::Gallery do
|
4
|
+
before do
|
5
|
+
@gallery = Adminpanel::Gallery.new(
|
6
|
+
:file => "Test file"
|
7
|
+
)
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { @gallery }
|
11
|
+
|
12
|
+
it { should respond_to(:file) }
|
13
|
+
|
14
|
+
describe "when file is not present" do
|
15
|
+
before {@gallery.file = " "}
|
16
|
+
it {should_not be_valid}
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "default scope" do
|
20
|
+
it { expect(Adminpanel::Gallery.scoped.to_sql).to eq Adminpanel::Gallery.reorder('').order('position ASC').to_sql}
|
21
|
+
end
|
22
22
|
end
|
data/spec/models/section_spec.rb
CHANGED
@@ -1,67 +1,67 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Adminpanel::Section do
|
4
|
-
before do
|
5
|
-
@section = Adminpanel::Section.new(
|
6
|
-
:name => "Section name",
|
7
|
-
:description => "Test description for index",
|
8
|
-
:has_image => true,
|
9
|
-
:key => "example_key",
|
10
|
-
:has_description => true,
|
11
|
-
:page => "index"
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
subject { @section }
|
16
|
-
|
17
|
-
it { should respond_to(:description) }
|
18
|
-
it { should respond_to(:has_image) }
|
19
|
-
it { should respond_to(:key) }
|
20
|
-
it { should respond_to(:name) }
|
21
|
-
it { should respond_to(:has_description) }
|
22
|
-
it { should respond_to(:page) }
|
23
|
-
|
24
|
-
describe "when key is telephone and has less than 10 chars" do
|
25
|
-
before do
|
26
|
-
@section.key = "telephone"
|
27
|
-
@section.description = "1" * 9
|
28
|
-
end
|
29
|
-
it { @section.valid? eq false}
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "when key is telephone and has more than 10 chars" do
|
33
|
-
before do
|
34
|
-
@section.key = "telephone"
|
35
|
-
@section.description = "1" * 11
|
36
|
-
end
|
37
|
-
it { @section.valid? eq false}
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "when key is telephone and has 10 chars" do
|
41
|
-
before do
|
42
|
-
@section.key = "telephone"
|
43
|
-
@section.description = "1" * 10
|
44
|
-
end
|
45
|
-
it { @section.valid? eq true}
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "when key is blank" do
|
50
|
-
before {@section.key = " "}
|
51
|
-
it { @section.valid? eq false}
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "when name is blank" do
|
55
|
-
before {@section.name = " "}
|
56
|
-
it { @section.valid? eq false}
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "when description is blank" do
|
60
|
-
before {@section.description = " "}
|
61
|
-
it { @section.valid? eq false}
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "default scope" do
|
65
|
-
it { expect(Adminpanel::Section.scoped.to_sql).to eq Adminpanel::Section.reorder('').order('page ASC').to_sql}
|
66
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Adminpanel::Section do
|
4
|
+
before do
|
5
|
+
@section = Adminpanel::Section.new(
|
6
|
+
:name => "Section name",
|
7
|
+
:description => "Test description for index",
|
8
|
+
:has_image => true,
|
9
|
+
:key => "example_key",
|
10
|
+
:has_description => true,
|
11
|
+
:page => "index"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { @section }
|
16
|
+
|
17
|
+
it { should respond_to(:description) }
|
18
|
+
it { should respond_to(:has_image) }
|
19
|
+
it { should respond_to(:key) }
|
20
|
+
it { should respond_to(:name) }
|
21
|
+
it { should respond_to(:has_description) }
|
22
|
+
it { should respond_to(:page) }
|
23
|
+
|
24
|
+
describe "when key is telephone and has less than 10 chars" do
|
25
|
+
before do
|
26
|
+
@section.key = "telephone"
|
27
|
+
@section.description = "1" * 9
|
28
|
+
end
|
29
|
+
it { @section.valid? eq false}
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when key is telephone and has more than 10 chars" do
|
33
|
+
before do
|
34
|
+
@section.key = "telephone"
|
35
|
+
@section.description = "1" * 11
|
36
|
+
end
|
37
|
+
it { @section.valid? eq false}
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "when key is telephone and has 10 chars" do
|
41
|
+
before do
|
42
|
+
@section.key = "telephone"
|
43
|
+
@section.description = "1" * 10
|
44
|
+
end
|
45
|
+
it { @section.valid? eq true}
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "when key is blank" do
|
50
|
+
before {@section.key = " "}
|
51
|
+
it { @section.valid? eq false}
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "when name is blank" do
|
55
|
+
before {@section.name = " "}
|
56
|
+
it { @section.valid? eq false}
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "when description is blank" do
|
60
|
+
before {@section.description = " "}
|
61
|
+
it { @section.valid? eq false}
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "default scope" do
|
65
|
+
it { expect(Adminpanel::Section.scoped.to_sql).to eq Adminpanel::Section.reorder('').order('page ASC').to_sql}
|
66
|
+
end
|
67
67
|
end
|
data/spec/models/user_spec.rb
CHANGED
@@ -1,106 +1,106 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Adminpanel::User do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@user = Adminpanel::User.new(
|
7
|
-
:name => "Example User",
|
8
|
-
:email => "user@example.com",
|
9
|
-
:password => "foobar",
|
10
|
-
:password_confirmation => "foobar"
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { @user }
|
15
|
-
|
16
|
-
it { should respond_to(:name) }
|
17
|
-
it { should respond_to(:email) }
|
18
|
-
it { should respond_to(:password_digest) }
|
19
|
-
it { should respond_to(:password) }
|
20
|
-
it { should respond_to(:password_confirmation) }
|
21
|
-
|
22
|
-
it { should be_valid }
|
23
|
-
it { should respond_to(:authenticate) }
|
24
|
-
|
25
|
-
describe "when name is not present" do
|
26
|
-
before { @user.name = " " }
|
27
|
-
it { should_not be_valid }
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "when email is not present" do
|
31
|
-
before { @user.email = " " }
|
32
|
-
it { should_not be_valid }
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "when email address is already taken" do
|
36
|
-
before do
|
37
|
-
user_with_same_email = @user.dup
|
38
|
-
user_with_same_email.email = @user.email.upcase
|
39
|
-
user_with_same_email.save
|
40
|
-
end
|
41
|
-
|
42
|
-
it { should_not be_valid }
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "when name is too long" do
|
46
|
-
before { @user.name = "a" * 51 }
|
47
|
-
it { should_not be_valid }
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "when email format is invalid" do
|
51
|
-
it "should be invalid" do
|
52
|
-
addresses = %w[user@foo,com user_at_foo.org example.user@foo.
|
53
|
-
foo@bar_baz.com foo@bar+baz.com]
|
54
|
-
addresses.each do |invalid_address|
|
55
|
-
@user.email = invalid_address
|
56
|
-
@user.should_not be_valid
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "when email format is valid" do
|
62
|
-
it "should be valid" do
|
63
|
-
addresses = %w[user@foo.COM A_US-ER@f.b.org frst.lst@foo.jp a+b@baz.cn]
|
64
|
-
addresses.each do |valid_address|
|
65
|
-
@user.email = valid_address
|
66
|
-
@user.should be_valid
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "when password is not present" do
|
72
|
-
before { @user.password = @user.password_confirmation = " " }
|
73
|
-
it { should_not be_valid }
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "when password doesn't match confirmation" do
|
77
|
-
before { @user.password_confirmation = "mismatch" }
|
78
|
-
it { should_not be_valid }
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "when password confirmation is nil" do
|
82
|
-
before { @user.password_confirmation = nil }
|
83
|
-
it { should_not be_valid }
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "with a password that's too short" do
|
87
|
-
before { @user.password = @user.password_confirmation = "a" * 5 }
|
88
|
-
it { should be_invalid }
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "return value of authenticate method" do
|
92
|
-
before { @user.save }
|
93
|
-
let(:found_user) { Adminpanel::User.find_by_email(@user.email) }
|
94
|
-
|
95
|
-
describe "with valid password" do
|
96
|
-
it { should == found_user.authenticate(@user.password) }
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "with invalid password" do
|
100
|
-
let(:user_for_invalid_password) { found_user.authenticate("invalid") }
|
101
|
-
|
102
|
-
it { should_not == user_for_invalid_password }
|
103
|
-
specify { user_for_invalid_password.should be_false }
|
104
|
-
end
|
105
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Adminpanel::User do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@user = Adminpanel::User.new(
|
7
|
+
:name => "Example User",
|
8
|
+
:email => "user@example.com",
|
9
|
+
:password => "foobar",
|
10
|
+
:password_confirmation => "foobar"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { @user }
|
15
|
+
|
16
|
+
it { should respond_to(:name) }
|
17
|
+
it { should respond_to(:email) }
|
18
|
+
it { should respond_to(:password_digest) }
|
19
|
+
it { should respond_to(:password) }
|
20
|
+
it { should respond_to(:password_confirmation) }
|
21
|
+
|
22
|
+
it { should be_valid }
|
23
|
+
it { should respond_to(:authenticate) }
|
24
|
+
|
25
|
+
describe "when name is not present" do
|
26
|
+
before { @user.name = " " }
|
27
|
+
it { should_not be_valid }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "when email is not present" do
|
31
|
+
before { @user.email = " " }
|
32
|
+
it { should_not be_valid }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when email address is already taken" do
|
36
|
+
before do
|
37
|
+
user_with_same_email = @user.dup
|
38
|
+
user_with_same_email.email = @user.email.upcase
|
39
|
+
user_with_same_email.save
|
40
|
+
end
|
41
|
+
|
42
|
+
it { should_not be_valid }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "when name is too long" do
|
46
|
+
before { @user.name = "a" * 51 }
|
47
|
+
it { should_not be_valid }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "when email format is invalid" do
|
51
|
+
it "should be invalid" do
|
52
|
+
addresses = %w[user@foo,com user_at_foo.org example.user@foo.
|
53
|
+
foo@bar_baz.com foo@bar+baz.com]
|
54
|
+
addresses.each do |invalid_address|
|
55
|
+
@user.email = invalid_address
|
56
|
+
@user.should_not be_valid
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "when email format is valid" do
|
62
|
+
it "should be valid" do
|
63
|
+
addresses = %w[user@foo.COM A_US-ER@f.b.org frst.lst@foo.jp a+b@baz.cn]
|
64
|
+
addresses.each do |valid_address|
|
65
|
+
@user.email = valid_address
|
66
|
+
@user.should be_valid
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "when password is not present" do
|
72
|
+
before { @user.password = @user.password_confirmation = " " }
|
73
|
+
it { should_not be_valid }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "when password doesn't match confirmation" do
|
77
|
+
before { @user.password_confirmation = "mismatch" }
|
78
|
+
it { should_not be_valid }
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "when password confirmation is nil" do
|
82
|
+
before { @user.password_confirmation = nil }
|
83
|
+
it { should_not be_valid }
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "with a password that's too short" do
|
87
|
+
before { @user.password = @user.password_confirmation = "a" * 5 }
|
88
|
+
it { should be_invalid }
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "return value of authenticate method" do
|
92
|
+
before { @user.save }
|
93
|
+
let(:found_user) { Adminpanel::User.find_by_email(@user.email) }
|
94
|
+
|
95
|
+
describe "with valid password" do
|
96
|
+
it { should == found_user.authenticate(@user.password) }
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "with invalid password" do
|
100
|
+
let(:user_for_invalid_password) { found_user.authenticate("invalid") }
|
101
|
+
|
102
|
+
it { should_not == user_for_invalid_password }
|
103
|
+
specify { user_for_invalid_password.should be_false }
|
104
|
+
end
|
105
|
+
end
|
106
106
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
-
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
-
# loaded once.
|
5
|
-
#
|
6
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
-
|
8
|
-
ENV["RAILS_ENV"] ||= 'test'
|
9
|
-
require File.expand_path("../dummy/config/environment", __FILE__)
|
10
|
-
require "rspec/rails"
|
11
|
-
require "factory_girl"
|
12
|
-
require "carrierwave/test/matchers"
|
13
|
-
require "active_record"
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
config.
|
20
|
-
config.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
ENV["RAILS_ENV"] ||= 'test'
|
9
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
10
|
+
require "rspec/rails"
|
11
|
+
require "factory_girl"
|
12
|
+
require "carrierwave/test/matchers"
|
13
|
+
require "active_record"
|
14
|
+
require "genspec"
|
15
|
+
|
16
|
+
Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
config.filter_run :focus
|
22
|
+
|
23
|
+
root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
24
|
+
ActiveRecord::Base.establish_connection(
|
25
|
+
:adapter => 'sqlite3',
|
26
|
+
:database => ':memory:'
|
27
|
+
)
|
28
|
+
|
29
|
+
config.include Rails.application.routes.url_helpers
|
30
|
+
|
31
|
+
config.order = 'random'
|
32
|
+
end
|