simple_images 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +146 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/simple_images.js.coffee +10 -0
- data/app/assets/stylesheets/simple_images.css.scss +23 -0
- data/app/controllers/.keep +0 -0
- data/app/controllers/simple_images_controller.rb +59 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/simple_images_helper.rb +20 -0
- data/app/models/.keep +0 -0
- data/app/views/.keep +0 -0
- data/app/views/simple_images/_destroy.html.erb +7 -0
- data/app/views/simple_images/_edit.html.erb +6 -0
- data/app/views/simple_images/_form.html.erb +6 -0
- data/config/initializers/dragonfly.rb +2 -0
- data/lib/generators/simple_images_generator.rb +17 -0
- data/lib/generators/templates/create_simple_images.rb +17 -0
- data/lib/generators/templates/initializer.rb +7 -0
- data/lib/generators/templates/simple_image.rb +3 -0
- data/lib/simple_images.rb +8 -0
- data/lib/simple_images/config.rb +13 -0
- data/lib/simple_images/engine.rb +9 -0
- data/lib/simple_images/imageable_additions.rb +21 -0
- data/lib/simple_images/simple_image_additions.rb +16 -0
- data/lib/simple_images/version.rb +3 -0
- data/simple_images.gemspec +34 -0
- data/spec/assets/images/test.png +0 -0
- data/spec/assets/images/test2.png +0 -0
- data/spec/controllers/simple_images_controller_spec.rb +134 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/dragonfly.rb +1 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/system/dragonfly/test/test.png +0 -0
- data/spec/extra/models.rb +7 -0
- data/spec/extra/schema.rb +19 -0
- data/spec/factories/articles.rb +6 -0
- data/spec/factories/simple_images.rb +5 -0
- data/spec/helpers/simple_images_helper_spec.rb +46 -0
- data/spec/models/imageable_spec.rb +5 -0
- data/spec/models/simple_image_spec.rb +12 -0
- data/spec/spec_helper.rb +30 -0
- metadata +340 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
module SimpleImages
|
2
|
+
# Set the maximum size allowed of uploaded images.
|
3
|
+
mattr_accessor :image_max_size
|
4
|
+
@@image_max_size = 5.megabytes
|
5
|
+
|
6
|
+
# Set list of availible formats allowed for image uploads.
|
7
|
+
mattr_accessor :image_formats_allowed
|
8
|
+
@@image_formats_allowed = [:jpg, :jpeg, :png, :gif]
|
9
|
+
|
10
|
+
def self.setup
|
11
|
+
yield self
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SimpleImages
|
2
|
+
module ImageableAdditions
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def has_simple_images
|
9
|
+
include SimpleImages::ImageableAdditions::InstanceMethods
|
10
|
+
|
11
|
+
has_many :simple_images, as: :imageable
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module InstanceMethods
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
ActiveRecord::Base.send(:include, SimpleImages::ImageableAdditions)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SimpleImages
|
2
|
+
module SimpleImageAdditions
|
3
|
+
def self.included(image_model)
|
4
|
+
image_model.belongs_to :imageable, polymorphic: true
|
5
|
+
|
6
|
+
image_model.image_accessor :image
|
7
|
+
image_model.validates_presence_of :image
|
8
|
+
image_model.validates_size_of :image,
|
9
|
+
maximum: SimpleImages.image_max_size
|
10
|
+
image_model.send :validates_property, :format, {
|
11
|
+
of: :image,
|
12
|
+
in: SimpleImages.image_formats_allowed
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_images/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_images"
|
8
|
+
spec.version = SimpleImages::VERSION
|
9
|
+
spec.authors = ["Kainage"]
|
10
|
+
spec.email = ["kainage@gmail.com"]
|
11
|
+
spec.description = %q{Add a simple image attaching functionality to an Active Record model}
|
12
|
+
spec.summary = %q{Add a simple image attaching functionality to an Active Record model}
|
13
|
+
spec.homepage = "https://github.com/kainage/simple_images"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", "~> 4.0.0"
|
22
|
+
spec.add_dependency "sass-rails", "~> 4.0.0"
|
23
|
+
spec.add_dependency "coffee-rails", "~> 4.0.0"
|
24
|
+
spec.add_dependency 'rack-cache', '~> 1.2'
|
25
|
+
spec.add_dependency 'dragonfly', '~> 0.9.15'
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "rspec-rails"
|
31
|
+
spec.add_development_dependency "factory_girl_rails"
|
32
|
+
spec.add_development_dependency "sqlite3"
|
33
|
+
spec.add_development_dependency "shoulda-matchers"
|
34
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleImagesController do
|
4
|
+
let(:article) { FactoryGirl.create(:article) }
|
5
|
+
def attachment
|
6
|
+
Rack::Test::UploadedFile.new("spec/assets/images/test.png", "image/png")
|
7
|
+
end
|
8
|
+
let(:valid_attributes) { { image: attachment } }
|
9
|
+
|
10
|
+
describe "POST create" do
|
11
|
+
describe "with valid params" do
|
12
|
+
it "creates a new SimpleImage" do
|
13
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
14
|
+
expect {
|
15
|
+
post :create, {article_id: article, simple_image: valid_attributes}
|
16
|
+
}.to change(SimpleImage, :count).by(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "assigns a newly created simple_image as @simple_image" do
|
20
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
21
|
+
post :create, {article_id: article, simple_image: valid_attributes}
|
22
|
+
assigns(:simple_image).should be_a(SimpleImage)
|
23
|
+
assigns(:simple_image).should be_persisted
|
24
|
+
end
|
25
|
+
|
26
|
+
it "redirects to the imageable" do
|
27
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
28
|
+
post :create, {article_id: article, simple_image: valid_attributes}
|
29
|
+
response.should redirect_to(article)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "with invalid params" do
|
34
|
+
it "assigns a newly created but unsaved simple_image as @simple_image" do
|
35
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
36
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
37
|
+
SimpleImage.any_instance.stub(:save).and_return(false)
|
38
|
+
post :create, {article_id: article, simple_image: { "image" => nil }}
|
39
|
+
assigns(:simple_image).should be_a_new(SimpleImage)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "redirects to imageable" do
|
43
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
44
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
45
|
+
SimpleImage.any_instance.stub(:save).and_return(false)
|
46
|
+
post :create, {article_id: article, simple_image: { "image" => nil }}
|
47
|
+
response.should redirect_to article
|
48
|
+
end
|
49
|
+
|
50
|
+
it "error message exists" do
|
51
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
52
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
53
|
+
SimpleImage.any_instance.stub(:save).and_return(false)
|
54
|
+
post :create, {article_id: article, simple_image: { "image" => nil }}
|
55
|
+
expect(flash[:alert]).to_not be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "PUT update" do
|
61
|
+
describe "with valid params" do
|
62
|
+
it "updates the requested simple_image" do
|
63
|
+
simple_image = FactoryGirl.create(:simple_image, imageable: article)
|
64
|
+
# Assuming there are no other simple_images in the database, this
|
65
|
+
# specifies that the SimpleImage created on the previous line
|
66
|
+
# receives the :update message with whatever params are submitted in the request.
|
67
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
68
|
+
SimpleImage.any_instance.should_receive(:update).with({ "image" => 'test2' })
|
69
|
+
put :update, {id: simple_image.to_param, simple_image: { "image" => 'test2'}}
|
70
|
+
end
|
71
|
+
|
72
|
+
it "assigns the requested simple_image as @simple_image" do
|
73
|
+
simple_image = FactoryGirl.create(:simple_image, imageable: article)
|
74
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
75
|
+
put :update, {id: simple_image.to_param, simple_image: valid_attributes}
|
76
|
+
assigns(:simple_image).should eq(simple_image)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "redirects to the imageable" do
|
80
|
+
simple_image = FactoryGirl.create(:simple_image, imageable: article)
|
81
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
82
|
+
put :update, {id: simple_image.to_param, simple_image: valid_attributes}
|
83
|
+
response.should redirect_to(simple_image.imageable)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "with invalid params" do
|
88
|
+
it "assigns the simple_image as @simple_image" do
|
89
|
+
simple_image = FactoryGirl.create(:simple_image, imageable: article)
|
90
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
91
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
92
|
+
SimpleImage.any_instance.stub(:update).and_return(false)
|
93
|
+
put :update, {id: simple_image.to_param, simple_image: { "image" => nil }}
|
94
|
+
assigns(:simple_image).should eq(simple_image)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "redirects to the imageable" do
|
98
|
+
simple_image = FactoryGirl.create(:simple_image, imageable: article)
|
99
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
100
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
101
|
+
SimpleImage.any_instance.stub(:update).and_return(false)
|
102
|
+
put :update, {id: simple_image.to_param, simple_image: { "image" => nil }}
|
103
|
+
response.should redirect_to simple_image.imageable
|
104
|
+
end
|
105
|
+
|
106
|
+
it "error message exists" do
|
107
|
+
simple_image = FactoryGirl.create(:simple_image, imageable: article)
|
108
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
109
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
110
|
+
SimpleImage.any_instance.stub(:update).and_return(false)
|
111
|
+
post :update, {id: simple_image.to_param, simple_image: { "image" => nil }}
|
112
|
+
expect(flash[:alert]).to_not be_nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "DELETE destroy" do
|
118
|
+
it "destroys the requested simple_image" do
|
119
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
120
|
+
simple_image = FactoryGirl.create(:simple_image, imageable: article)
|
121
|
+
expect {
|
122
|
+
delete :destroy, {id: simple_image.to_param}
|
123
|
+
}.to change(SimpleImage, :count).by(-1)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "redirects to the imageable" do
|
127
|
+
controller.request.should_receive(:referrer).and_return(article_url(article))
|
128
|
+
simple_image = FactoryGirl.create(:simple_image, imageable: article)
|
129
|
+
delete :destroy, {id: simple_image.to_param}
|
130
|
+
response.should redirect_to simple_image.imageable
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -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
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
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
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "simple_images"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
+
|
18
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
+
# config.i18n.default_locale = :de
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports and disable caching.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send.
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger.
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Raise an error on page load if there are pending migrations
|
23
|
+
config.active_record.migration_error = :page_load
|
24
|
+
|
25
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
26
|
+
# This option may cause significant delays in view rendering with a large
|
27
|
+
# number of complex assets.
|
28
|
+
config.assets.debug = true
|
29
|
+
end
|