pretty_file_input 0.0.1 → 0.0.2

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.
@@ -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 pretty_file_input
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,32 @@
1
+ class UsersController < ActionController::Base
2
+ layout 'application'
3
+
4
+ def new
5
+ @user = User.new
6
+ end
7
+
8
+ def create
9
+ @user = User.create(user_params)
10
+ redirect_to edit_user_path(@user)
11
+ end
12
+
13
+ def edit
14
+ @user = User.find(params[:id])
15
+ end
16
+
17
+ def update
18
+ @user = User.find(params[:id])
19
+ @user.update(user_params)
20
+
21
+ respond_to do |format|
22
+ format.json { render json: { ok: true } }
23
+ format.html { redirect_to edit_user_path }
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def user_params
30
+ params.require(:user).permit!
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ mount_uploader :avatar, CarrierWave::Uploader::Base
3
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
+ <script src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
7
+ <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,4 @@
1
+ <%= simple_form_for @user do |f| %>
2
+ <%= f.input :avatar, as: :pretty_file_input %>
3
+ <%= f.button :submit, 'Submit' %>
4
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require 'pretty_file_input'
7
+ require 'carrierwave'
8
+ require 'simple_form'
9
+
10
+ module Dummy
11
+ class Application < Rails::Application
12
+ # Settings in config/environments/* take precedence over those specified here.
13
+ # Application configuration should go into files in config/initializers
14
+ # -- all .rb files in that directory are automatically loaded.
15
+
16
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
17
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
18
+ # config.time_zone = 'Central Time (US & Canada)'
19
+
20
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
21
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
22
+ # config.i18n.default_locale = :de
23
+ config.secret_key_base = 'xxx'
24
+ end
25
+ end
26
+
@@ -0,0 +1,5 @@
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'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/test.sqlite
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Dummy::Application.initialize!
@@ -0,0 +1,36 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static asset server for tests with Cache-Control for performance.
16
+ config.serve_static_assets = true
17
+ config.static_cache_control = "public, max-age=3600"
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Raise exceptions instead of rendering exception templates.
24
+ config.action_dispatch.show_exceptions = false
25
+
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
28
+
29
+ # Tell Action Mailer not to deliver emails to the real world.
30
+ # The :test delivery method accumulates sent emails in the
31
+ # ActionMailer::Base.deliveries array.
32
+ config.action_mailer.delivery_method = :test
33
+
34
+ # Print deprecation notices to the stderr.
35
+ config.active_support.deprecation = :stderr
36
+ end
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :users
3
+ end
@@ -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,7 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :avatar
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20141123205413) do
15
+
16
+ create_table "users", force: true do |t|
17
+ t.string "avatar"
18
+ end
19
+
20
+ end
File without changes
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Users', js: true, type: :feature do
4
+ let!(:user) do
5
+ User.create(avatar: File.open("#{Rails.root}/spec/fixtures/avatar.jpg"))
6
+ end
7
+
8
+ let(:created_user) { User.last }
9
+
10
+ describe '#new + #create' do
11
+ it 'functions properly' do
12
+ visit new_user_path
13
+ attach_file 'user[avatar]', "#{Rails.root}/spec/fixtures/avatar2.jpg"
14
+
15
+ expect do
16
+ click_button 'Submit'
17
+ sleep 1
18
+ end.to change { User.count }.by(1)
19
+
20
+ expect(created_user.avatar.file.filename).to eq 'avatar2.jpg'
21
+ end
22
+ end
23
+
24
+ describe '#edit + #update' do
25
+ it 'uploads via AJAX' do
26
+ user.update(remove_avatar: true)
27
+ expect(user.avatar).to be_blank
28
+ visit edit_user_path(user)
29
+ find('input[type=file]').set "#{Rails.root}/spec/fixtures/avatar2.jpg"
30
+ sleep 1
31
+ expect(user.reload.avatar).to_not be_blank
32
+ expect(user.avatar.file.filename).to eq 'avatar2.jpg'
33
+ end
34
+
35
+ it 'removes via AJAX' do
36
+ expect(user.avatar).to_not be_blank
37
+ visit edit_user_path(user)
38
+ find('a', text: 'Remove').click
39
+ expect(user.reload.avatar).to be_blank
40
+ end
41
+ end
42
+ end
Binary file
@@ -0,0 +1,15 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require 'pretty_file_input'
5
+
6
+ Rails.backtrace_cleaner.remove_silencers!
7
+
8
+ require 'rspec/rails'
9
+ require 'capybara/rspec'
10
+
11
+ Dir[Rails.root.join("../../spec/support/**/*.rb")].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ config.order = 'random'
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pretty_file_input
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Becker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-script
@@ -52,6 +52,104 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.4.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.4.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: carrierwave
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 4.1.7
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 4.1.7
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: selenium-webdriver
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.43.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 2.43.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: simple_form
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: sqlite3
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.3.9
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.3.9
55
153
  description:
56
154
  email: adam@dobt.co
57
155
  executables: []
@@ -60,6 +158,7 @@ extra_rdoc_files: []
60
158
  files:
61
159
  - ".gitignore"
62
160
  - ".ruby-version"
161
+ - ".travis.yml"
63
162
  - Gemfile
64
163
  - README.md
65
164
  - app/assets/javascripts/pretty_file_input.coffee
@@ -70,6 +169,30 @@ files:
70
169
  - lib/pretty_file_input/version.rb
71
170
  - pretty_file_input.gemspec
72
171
  - script/release
172
+ - spec/dummy/Rakefile
173
+ - spec/dummy/app/assets/javascripts/application.js
174
+ - spec/dummy/app/assets/javascripts/jquery.form.js
175
+ - spec/dummy/app/assets/stylesheets/application.css
176
+ - spec/dummy/app/controllers/users_controller.rb
177
+ - spec/dummy/app/models/user.rb
178
+ - spec/dummy/app/views/layouts/application.html.erb
179
+ - spec/dummy/app/views/users/_form.html.erb
180
+ - spec/dummy/app/views/users/edit.html.erb
181
+ - spec/dummy/app/views/users/new.html.erb
182
+ - spec/dummy/config.ru
183
+ - spec/dummy/config/application.rb
184
+ - spec/dummy/config/boot.rb
185
+ - spec/dummy/config/database.yml
186
+ - spec/dummy/config/environment.rb
187
+ - spec/dummy/config/environments/test.rb
188
+ - spec/dummy/config/routes.rb
189
+ - spec/dummy/db/migrate/20141123205413_create_users.rb
190
+ - spec/dummy/db/schema.rb
191
+ - spec/dummy/public/favicon.ico
192
+ - spec/dummy/spec/features/users_spec.rb
193
+ - spec/dummy/spec/fixtures/avatar.jpg
194
+ - spec/dummy/spec/fixtures/avatar2.jpg
195
+ - spec/spec_helper.rb
73
196
  homepage: http://github.com/dobtco/pretty_file_input
74
197
  licenses:
75
198
  - MIT
@@ -94,5 +217,29 @@ rubygems_version: 2.2.2
94
217
  signing_key:
95
218
  specification_version: 4
96
219
  summary: A more powerful file input.
97
- test_files: []
220
+ test_files:
221
+ - spec/dummy/Rakefile
222
+ - spec/dummy/app/assets/javascripts/application.js
223
+ - spec/dummy/app/assets/javascripts/jquery.form.js
224
+ - spec/dummy/app/assets/stylesheets/application.css
225
+ - spec/dummy/app/controllers/users_controller.rb
226
+ - spec/dummy/app/models/user.rb
227
+ - spec/dummy/app/views/layouts/application.html.erb
228
+ - spec/dummy/app/views/users/_form.html.erb
229
+ - spec/dummy/app/views/users/edit.html.erb
230
+ - spec/dummy/app/views/users/new.html.erb
231
+ - spec/dummy/config.ru
232
+ - spec/dummy/config/application.rb
233
+ - spec/dummy/config/boot.rb
234
+ - spec/dummy/config/database.yml
235
+ - spec/dummy/config/environment.rb
236
+ - spec/dummy/config/environments/test.rb
237
+ - spec/dummy/config/routes.rb
238
+ - spec/dummy/db/migrate/20141123205413_create_users.rb
239
+ - spec/dummy/db/schema.rb
240
+ - spec/dummy/public/favicon.ico
241
+ - spec/dummy/spec/features/users_spec.rb
242
+ - spec/dummy/spec/fixtures/avatar.jpg
243
+ - spec/dummy/spec/fixtures/avatar2.jpg
244
+ - spec/spec_helper.rb
98
245
  has_rdoc: