carrierwave-validators 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +26 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +3 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +98 -0
  9. data/Rakefile +6 -0
  10. data/carrierwave-validators.gemspec +29 -0
  11. data/lib/carrierwave/validators.rb +17 -0
  12. data/lib/carrierwave/validators/all.rb +9 -0
  13. data/lib/carrierwave/validators/error.rb +8 -0
  14. data/lib/carrierwave/validators/locales/en.yml +13 -0
  15. data/lib/carrierwave/validators/railtie.rb +14 -0
  16. data/lib/carrierwave/validators/size_validator.rb +98 -0
  17. data/lib/carrierwave/validators/version.rb +5 -0
  18. data/spec/dummy/.rspec +2 -0
  19. data/spec/dummy/Gemfile +15 -0
  20. data/spec/dummy/README.md +5 -0
  21. data/spec/dummy/Rakefile +6 -0
  22. data/spec/dummy/app/assets/images/.keep +0 -0
  23. data/spec/dummy/app/assets/javascripts/application.js +17 -0
  24. data/spec/dummy/app/assets/javascripts/profiles.js.coffee +0 -0
  25. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  26. data/spec/dummy/app/assets/stylesheets/profiles.css.scss +0 -0
  27. data/spec/dummy/app/assets/stylesheets/scaffolds.css.scss +69 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  29. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  30. data/spec/dummy/app/controllers/profiles_controller.rb +73 -0
  31. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  32. data/spec/dummy/app/helpers/profiles_helper.rb +2 -0
  33. data/spec/dummy/app/mailers/.keep +0 -0
  34. data/spec/dummy/app/models/.keep +0 -0
  35. data/spec/dummy/app/models/concerns/.keep +0 -0
  36. data/spec/dummy/app/models/profile.rb +9 -0
  37. data/spec/dummy/app/uploaders/avatar_uploader.rb +58 -0
  38. data/spec/dummy/app/views/layouts/application.html.erb +12 -0
  39. data/spec/dummy/app/views/profiles/_form.html.erb +24 -0
  40. data/spec/dummy/app/views/profiles/edit.html.erb +6 -0
  41. data/spec/dummy/app/views/profiles/index.html.erb +29 -0
  42. data/spec/dummy/app/views/profiles/index.json.jbuilder +4 -0
  43. data/spec/dummy/app/views/profiles/new.html.erb +5 -0
  44. data/spec/dummy/app/views/profiles/show.html.erb +14 -0
  45. data/spec/dummy/app/views/profiles/show.json.jbuilder +1 -0
  46. data/spec/dummy/bin/bundle +3 -0
  47. data/spec/dummy/bin/rails +4 -0
  48. data/spec/dummy/bin/rake +4 -0
  49. data/spec/dummy/config.ru +4 -0
  50. data/spec/dummy/config/application.rb +28 -0
  51. data/spec/dummy/config/boot.rb +4 -0
  52. data/spec/dummy/config/database.yml +25 -0
  53. data/spec/dummy/config/environment.rb +5 -0
  54. data/spec/dummy/config/environments/development.rb +29 -0
  55. data/spec/dummy/config/environments/production.rb +80 -0
  56. data/spec/dummy/config/environments/test.rb +36 -0
  57. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  59. data/spec/dummy/config/initializers/inflections.rb +16 -0
  60. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  61. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  62. data/spec/dummy/config/initializers/session_store.rb +3 -0
  63. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/spec/dummy/config/locales/en.yml +23 -0
  65. data/spec/dummy/config/routes.rb +60 -0
  66. data/spec/dummy/db/migrate/20140330144709_create_profiles.rb +10 -0
  67. data/spec/dummy/db/schema.rb +23 -0
  68. data/spec/dummy/db/seeds.rb +7 -0
  69. data/spec/dummy/lib/assets/.keep +0 -0
  70. data/spec/dummy/lib/tasks/.keep +0 -0
  71. data/spec/dummy/log/.keep +0 -0
  72. data/spec/dummy/public/404.html +58 -0
  73. data/spec/dummy/public/422.html +58 -0
  74. data/spec/dummy/public/500.html +57 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/dummy/public/robots.txt +5 -0
  77. data/spec/dummy/spec/support/avatar.jpg +0 -0
  78. data/spec/dummy/spec/support/large.jpg +0 -0
  79. data/spec/dummy/spec/support/small.png +0 -0
  80. data/spec/spec_helper.rb +34 -0
  81. data/spec/validators/size_validators/size_validator_spec.rb +165 -0
  82. metadata +292 -0
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,69 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ p, ol, ul, td {
10
+ font-family: verdana, arial, helvetica, sans-serif;
11
+ font-size: 13px;
12
+ line-height: 18px;
13
+ }
14
+
15
+ pre {
16
+ background-color: #eee;
17
+ padding: 10px;
18
+ font-size: 11px;
19
+ }
20
+
21
+ a {
22
+ color: #000;
23
+ &:visited {
24
+ color: #666;
25
+ }
26
+ &:hover {
27
+ color: #fff;
28
+ background-color: #000;
29
+ }
30
+ }
31
+
32
+ div {
33
+ &.field, &.actions {
34
+ margin-bottom: 10px;
35
+ }
36
+ }
37
+
38
+ #notice {
39
+ color: green;
40
+ }
41
+
42
+ .field_with_errors {
43
+ padding: 2px;
44
+ background-color: red;
45
+ display: table;
46
+ }
47
+
48
+ #error_explanation {
49
+ width: 450px;
50
+ border: 2px solid red;
51
+ padding: 7px;
52
+ padding-bottom: 0;
53
+ margin-bottom: 20px;
54
+ background-color: #f0f0f0;
55
+ h2 {
56
+ text-align: left;
57
+ font-weight: bold;
58
+ padding: 5px 5px 5px 15px;
59
+ font-size: 12px;
60
+ margin: -7px;
61
+ margin-bottom: 0px;
62
+ background-color: #c00;
63
+ color: #fff;
64
+ }
65
+ ul li {
66
+ font-size: 12px;
67
+ list-style: square;
68
+ }
69
+ }
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,73 @@
1
+ class ProfilesController < ApplicationController
2
+ before_action :set_profile, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /profiles
5
+ # GET /profiles.json
6
+ def index
7
+ @profiles = Profile.all
8
+ end
9
+
10
+ # GET /profiles/1
11
+ # GET /profiles/1.json
12
+ def show
13
+ end
14
+
15
+ # GET /profiles/new
16
+ def new
17
+ @profile = Profile.new
18
+ end
19
+
20
+ # GET /profiles/1/edit
21
+ def edit
22
+ end
23
+
24
+ # POST /profiles
25
+ # POST /profiles.json
26
+ def create
27
+ @profile = Profile.new(profile_params)
28
+ respond_to do |format|
29
+ if @profile.save
30
+ format.html { redirect_to @profile, notice: 'Profile was successfully created.' }
31
+ format.json { render action: 'show', status: :created, location: @profile }
32
+ else
33
+ format.html { render action: 'new' }
34
+ format.json { render json: @profile.errors, status: :unprocessable_entity }
35
+ end
36
+ end
37
+ end
38
+
39
+ # PATCH/PUT /profiles/1
40
+ # PATCH/PUT /profiles/1.json
41
+ def update
42
+ respond_to do |format|
43
+ if @profile.update(profile_params)
44
+ format.html { redirect_to @profile, notice: 'Profile was successfully updated.' }
45
+ format.json { head :no_content }
46
+ else
47
+ format.html { render action: 'edit' }
48
+ format.json { render json: @profile.errors, status: :unprocessable_entity }
49
+ end
50
+ end
51
+ end
52
+
53
+ # DELETE /profiles/1
54
+ # DELETE /profiles/1.json
55
+ def destroy
56
+ @profile.destroy
57
+ respond_to do |format|
58
+ format.html { redirect_to profiles_url }
59
+ format.json { head :no_content }
60
+ end
61
+ end
62
+
63
+ private
64
+ # Use callbacks to share common setup or constraints between actions.
65
+ def set_profile
66
+ @profile = Profile.find(params[:id])
67
+ end
68
+
69
+ # Never trust parameters from the scary internet, only allow the white list through.
70
+ def profile_params
71
+ params.require(:profile).permit(:name, :avatar)
72
+ end
73
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ProfilesHelper
2
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,9 @@
1
+
2
+ class Profile < ActiveRecord::Base
3
+ mount_uploader :avatar, AvatarUploader
4
+ # validates :avatar, :size => {:in => 0..20.kilobytes}
5
+ # validates :avatar, :size => {:less_than => 40.kilobytes}
6
+ # validates :avatar, :size => {:less_than_or_equal_to => 40.kilobytes}
7
+ # validates :avatar, :size => {:greater_than => 20.kilobytes}
8
+ # validates :avatar, :size => {:greater_than_or_equal_to => 20.kilobytes}
9
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+ class AvatarUploader < CarrierWave::Uploader::Base
3
+
4
+ # Include RMagick or MiniMagick support:
5
+ # include CarrierWave::RMagick
6
+ # include CarrierWave::MiniMagick
7
+ # include CarrierWave::RMagick
8
+
9
+
10
+ # Choose what kind of storage to use for this uploader:
11
+ storage :file
12
+ # storage :fog
13
+
14
+ # Override the directory where uploaded files will be stored.
15
+ # This is a sensible default for uploaders that are meant to be mounted:
16
+ def store_dir
17
+ "#{Rails.root}/public/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
18
+ end
19
+
20
+ # Provide a default URL as a default if there hasn't been a file uploaded:
21
+ # def default_url
22
+ # # For Rails 3.1+ asset pipeline compatibility:
23
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
24
+ #
25
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
26
+ # end
27
+
28
+ # Process files as they are uploaded:
29
+ # process :scale => [200, 300]
30
+ # process :crop
31
+ #
32
+ # def scale(width, height)
33
+ # # do something
34
+ # end
35
+
36
+ # Create different versions of your uploaded files:
37
+ #version :thumb do
38
+ #process :crop
39
+ #resize_to_fill(100, 100)
40
+ # process :resize_to_fit => [50, 50]
41
+ #end
42
+ #version :large do
43
+ # resize_to_limit(600,600)
44
+ #end
45
+
46
+
47
+ # Add a white list of extensions which are allowed to be uploaded.
48
+ # For images you might use something like this:
49
+ def extension_white_list
50
+ %w(jpg jpeg gif png)
51
+ end
52
+
53
+ # Override the filename of the uploaded files:
54
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
55
+ # def filename
56
+ # "something.jpg" if original_filename
57
+ # end
58
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
+ <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <%= yield %>
11
+ </body>
12
+ </html>
@@ -0,0 +1,24 @@
1
+ <%= form_for(@profile, html: {multipart: true}) do |f| %>
2
+ <% if @profile.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@profile.errors.count, "error") %>
5
+ prohibited this profile from being saved:</h2>
6
+ <ul>
7
+ <% @profile.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+ <div class="field">
14
+ <%= f.label :name %><br>
15
+ <%= f.text_field :name %>
16
+ </div>
17
+ <div class="field">
18
+ <%= f.label :avatar %><br>
19
+ <%= f.file_field :avatar %>
20
+ </div>
21
+ <div class="actions">
22
+ <%= f.submit %>
23
+ </div>
24
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing profile</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @profile %> |
6
+ <%= link_to 'Back', profiles_path %>
@@ -0,0 +1,29 @@
1
+ <h1>Listing profiles</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Name</th>
7
+ <th>Avatar</th>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+ </thead>
13
+
14
+ <tbody>
15
+ <% @profiles.each do |profile| %>
16
+ <tr>
17
+ <td><%= profile.name %></td>
18
+ <td><%= profile.avatar %></td>
19
+ <td><%= link_to 'Show', profile %></td>
20
+ <td><%= link_to 'Edit', edit_profile_path(profile) %></td>
21
+ <td><%= link_to 'Destroy', profile, method: :delete, data: { confirm: 'Are you sure?' } %></td>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+
27
+ <br>
28
+
29
+ <%= link_to 'New Profile', new_profile_path %>
@@ -0,0 +1,4 @@
1
+ json.array!(@profiles) do |profile|
2
+ json.extract! profile, :id, :name, :avatar
3
+ json.url profile_url(profile, format: :json)
4
+ end
@@ -0,0 +1,5 @@
1
+ <h1>New profile</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', profiles_path %>
@@ -0,0 +1,14 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Name:</strong>
5
+ <%= @profile.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Avatar:</strong>
10
+ <%= image_tag @profile.avatar.url %>
11
+ </p>
12
+
13
+ <%= link_to 'Edit', edit_profile_path(@profile) %> |
14
+ <%= link_to 'Back', profiles_path %>
@@ -0,0 +1 @@
1
+ json.extract! @profile, :id, :name, :avatar, :created_at, :updated_at
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,28 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "sprockets/railtie"
8
+ # require "rails/test_unit/railtie"
9
+
10
+ # Require the gems listed in Gemfile, including any gems
11
+ # you've limited to :test, :development, or :production.
12
+ Bundler.require(:default, Rails.env)
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
+ # config.time_zone = 'Central Time (US & Canada)'
23
+ config.autoload_paths << "#{config.root}/helpers/form_builder.rb"
24
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
+ # config.i18n.default_locale = :de
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000