railscart 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/Manifest.txt +103 -33
- data/bin/railscart +4 -1
- data/lib/railscart/version.rb +1 -1
- data/starter_app/app/controllers/application.rb +1 -1
- data/starter_app/config/database.yml +21 -7
- data/starter_app/config/environment.rb +9 -2
- data/starter_app/db/migrate/{005_create_users.rb → 001_create_users.rb} +0 -0
- data/starter_app/db/migrate/{006_create_roles.rb → 002_create_roles.rb} +0 -0
- data/starter_app/db/migrate/{002_create_tags_and_taggings.rb → 003_create_tags_and_taggings.rb} +0 -0
- data/starter_app/db/migrate/{003_railscart_to_version_19.rb → 004_railscart_to_version_19.rb} +2 -2
- data/starter_app/db/sample/images.yml +252 -0
- data/starter_app/lib/tasks/rc_sample_data.rake +12 -10
- data/starter_app/lib/tasks/sample/products/0000/0001/ror_tote.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0001/ror_tote_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0001/ror_tote_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0001/ror_tote_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0002/ror_tote_back.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0002/ror_tote_back_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0002/ror_tote_back_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0002/ror_tote_back_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0003/ror_bag.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0003/ror_bag_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0003/ror_bag_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0003/ror_bag_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0004/ror_baseball.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0004/ror_baseball_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0004/ror_baseball_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0004/ror_baseball_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0005/ror_baseball_back.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0005/ror_baseball_back_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0005/ror_baseball_back_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0005/ror_baseball_back_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0006/ror_jr_spaghetti.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0006/ror_jr_spaghetti_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0006/ror_jr_spaghetti_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0006/ror_jr_spaghetti_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0007/ror_mug.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0007/ror_mug_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0007/ror_mug_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0007/ror_mug_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0008/ror_mug_back.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0008/ror_mug_back_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0008/ror_mug_back_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0008/ror_mug_back_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0009/ror_ringer.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0009/ror_ringer_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0009/ror_ringer_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0009/ror_ringer_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0010/ror_ringer_back.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0010/ror_ringer_back_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0010/ror_ringer_back_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0010/ror_ringer_back_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0011/ror_stein.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0011/ror_stein_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0011/ror_stein_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0011/ror_stein_small.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0012/ror_stein_back.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0012/ror_stein_back_mini.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0012/ror_stein_back_product.jpeg +0 -0
- data/starter_app/lib/tasks/sample/products/0000/0012/ror_stein_back_small.jpeg +0 -0
- data/starter_app/vendor/plugins/attachment_fu/CHANGELOG +24 -0
- data/starter_app/vendor/plugins/attachment_fu/README +162 -0
- data/starter_app/vendor/plugins/attachment_fu/Rakefile +22 -0
- data/starter_app/vendor/plugins/attachment_fu/amazon_s3.yml.tpl +14 -0
- data/starter_app/vendor/plugins/attachment_fu/init.rb +14 -0
- data/starter_app/vendor/plugins/attachment_fu/install.rb +5 -0
- data/starter_app/vendor/plugins/attachment_fu/lib/geometry.rb +93 -0
- data/starter_app/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb +410 -0
- data/starter_app/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb +39 -0
- data/starter_app/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb +97 -0
- data/starter_app/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb +309 -0
- data/starter_app/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/image_science_processor.rb +61 -0
- data/starter_app/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb +56 -0
- data/starter_app/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb +53 -0
- data/starter_app/vendor/plugins/attachment_fu/test/amazon_s3.yml +6 -0
- data/starter_app/vendor/plugins/attachment_fu/test/backends/db_file_test.rb +16 -0
- data/starter_app/vendor/plugins/attachment_fu/test/backends/file_system_test.rb +80 -0
- data/starter_app/vendor/plugins/attachment_fu/test/backends/remote/s3_test.rb +103 -0
- data/starter_app/vendor/plugins/attachment_fu/test/base_attachment_tests.rb +57 -0
- data/starter_app/vendor/plugins/attachment_fu/test/basic_test.rb +64 -0
- data/starter_app/vendor/plugins/attachment_fu/test/database.yml +18 -0
- data/starter_app/vendor/plugins/attachment_fu/test/extra_attachment_test.rb +57 -0
- data/starter_app/vendor/plugins/attachment_fu/test/fixtures/attachment.rb +127 -0
- data/starter_app/vendor/plugins/attachment_fu/test/fixtures/files/fake/rails.png +0 -0
- data/starter_app/vendor/plugins/attachment_fu/test/fixtures/files/foo.txt +1 -0
- data/starter_app/vendor/plugins/attachment_fu/test/fixtures/files/rails.png +0 -0
- data/starter_app/vendor/plugins/attachment_fu/test/geometry_test.rb +101 -0
- data/starter_app/vendor/plugins/attachment_fu/test/processors/image_science_test.rb +31 -0
- data/starter_app/vendor/plugins/attachment_fu/test/processors/mini_magick_test.rb +31 -0
- data/starter_app/vendor/plugins/attachment_fu/test/processors/rmagick_test.rb +241 -0
- data/starter_app/vendor/plugins/attachment_fu/test/schema.rb +86 -0
- data/starter_app/vendor/plugins/attachment_fu/test/test_helper.rb +142 -0
- data/starter_app/vendor/plugins/attachment_fu/test/validation_test.rb +55 -0
- data/starter_app/vendor/plugins/paginating_find/CHANGELOG +3 -0
- data/starter_app/vendor/plugins/paginating_find/lib/paginating_find.rb +5 -2
- data/starter_app/vendor/plugins/railscart/app/controllers/admin/categories_controller.rb +8 -8
- data/starter_app/vendor/plugins/railscart/app/controllers/admin/images_controller.rb +44 -0
- data/starter_app/vendor/plugins/railscart/app/controllers/admin/products_controller.rb +4 -0
- data/starter_app/vendor/plugins/railscart/app/helpers/rails_cart/base_helper.rb +25 -0
- data/starter_app/vendor/plugins/railscart/app/models/image.rb +12 -0
- data/starter_app/vendor/plugins/railscart/app/models/product.rb +15 -16
- data/starter_app/vendor/plugins/railscart/app/views/admin/categories/_form.rhtml +0 -3
- data/starter_app/vendor/plugins/railscart/app/views/admin/images/new.html.erb +10 -0
- data/starter_app/vendor/plugins/railscart/app/views/admin/products/_form.rhtml +3 -3
- data/starter_app/vendor/plugins/railscart/app/views/admin/products/_option_types.rhtml +0 -1
- data/starter_app/vendor/plugins/railscart/app/views/admin/products/_variations.rhtml +1 -2
- data/starter_app/vendor/plugins/railscart/app/views/admin/products/index.rhtml +1 -1
- data/starter_app/vendor/plugins/railscart/app/views/admin/products/new.rhtml +1 -3
- data/starter_app/vendor/plugins/railscart/app/views/cart/index.rhtml +1 -1
- data/starter_app/vendor/plugins/railscart/app/views/shared/_images.html.erb +43 -0
- data/starter_app/vendor/plugins/railscart/app/views/store/list.rhtml +1 -1
- data/starter_app/vendor/plugins/railscart/app/views/store/show.rhtml +1 -1
- data/starter_app/vendor/plugins/railscart/db/migrate/{008_create_option_values.rb → 007_create_option_values.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{010_create_orders.rb → 008_create_orders.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{011_create_products.rb → 009_create_products.rb} +2 -2
- data/starter_app/vendor/plugins/railscart/db/migrate/{013_create_txns.rb → 010_create_txns.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{015_create_variations.rb → 011_create_variations.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{016_create_tax_treatments.rb → 012_create_tax_treatments.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{017_create_skus.rb → 013_create_skus.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{018_create_countries.rb → 014_create_countries.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{019_create_states.rb → 015_create_states.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{021_create_option_types.rb → 016_create_option_types.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{022_create_product_option_types.rb → 017_create_product_option_types.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/{023_create_option_values_variations.rb → 018_create_option_values_variations.rb} +0 -0
- data/starter_app/vendor/plugins/railscart/db/migrate/019_create_images.rb +19 -0
- metadata +106 -35
- data/starter_app/config/database.master.yml +0 -23
- data/starter_app/db/migrate/001_add_sessions.rb +0 -16
- data/starter_app/db/migrate/004_railscart_to_version_20.rb +0 -9
- data/starter_app/db/migrate/007_railscart_to_version_23.rb +0 -9
- data/starter_app/lib/tasks/sample/images/ror_bag.jpg +0 -0
- data/starter_app/lib/tasks/sample/images/ror_baseball_jersey.jpg +0 -0
- data/starter_app/lib/tasks/sample/images/ror_jr_spaghetti.jpg +0 -0
- data/starter_app/lib/tasks/sample/images/ror_mug.jpg +0 -0
- data/starter_app/lib/tasks/sample/images/ror_ringer_tshirt.jpg +0 -0
- data/starter_app/lib/tasks/sample/images/ror_stein.jpg +0 -0
- data/starter_app/lib/tasks/sample/images/ror_tote.jpg +0 -0
- data/starter_app/vendor/plugins/railscart/app/models/good.rb +0 -4
- data/starter_app/vendor/plugins/railscart/db/migrate/007_create_option_groups.rb +0 -12
- data/starter_app/vendor/plugins/railscart/db/migrate/009_create_options.rb +0 -11
- data/starter_app/vendor/plugins/railscart/db/migrate/012_ignore_users.rb +0 -9
- data/starter_app/vendor/plugins/railscart/db/migrate/014_ignore_roles.rb +0 -9
- data/starter_app/vendor/plugins/railscart/db/migrate/020_modify_users.rb +0 -9
@@ -0,0 +1,142 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
ENV['RAILS_ENV'] = 'test'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
|
7
|
+
require 'breakpoint'
|
8
|
+
require 'active_record/fixtures'
|
9
|
+
require 'action_controller/test_process'
|
10
|
+
|
11
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
12
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
13
|
+
|
14
|
+
db_adapter = ENV['DB']
|
15
|
+
|
16
|
+
# no db passed, try one of these fine config-free DBs before bombing.
|
17
|
+
db_adapter ||=
|
18
|
+
begin
|
19
|
+
require 'rubygems'
|
20
|
+
require 'sqlite'
|
21
|
+
'sqlite'
|
22
|
+
rescue MissingSourceFile
|
23
|
+
begin
|
24
|
+
require 'sqlite3'
|
25
|
+
'sqlite3'
|
26
|
+
rescue MissingSourceFile
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if db_adapter.nil?
|
31
|
+
raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
|
32
|
+
end
|
33
|
+
|
34
|
+
ActiveRecord::Base.establish_connection(config[db_adapter])
|
35
|
+
|
36
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
37
|
+
|
38
|
+
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures"
|
39
|
+
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
40
|
+
|
41
|
+
class Test::Unit::TestCase #:nodoc:
|
42
|
+
include ActionController::TestProcess
|
43
|
+
def create_fixtures(*table_names)
|
44
|
+
if block_given?
|
45
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
|
46
|
+
else
|
47
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def setup
|
52
|
+
Attachment.saves = 0
|
53
|
+
DbFile.transaction { [Attachment, FileAttachment, OrphanAttachment, MinimalAttachment, DbFile].each { |klass| klass.delete_all } }
|
54
|
+
attachment_model self.class.attachment_model
|
55
|
+
end
|
56
|
+
|
57
|
+
def teardown
|
58
|
+
FileUtils.rm_rf File.join(File.dirname(__FILE__), 'files')
|
59
|
+
end
|
60
|
+
|
61
|
+
self.use_transactional_fixtures = true
|
62
|
+
self.use_instantiated_fixtures = false
|
63
|
+
|
64
|
+
def self.attachment_model(klass = nil)
|
65
|
+
@attachment_model = klass if klass
|
66
|
+
@attachment_model
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.test_against_class(test_method, klass, subclass = false)
|
70
|
+
define_method("#{test_method}_on_#{:sub if subclass}class") do
|
71
|
+
klass = Class.new(klass) if subclass
|
72
|
+
attachment_model klass
|
73
|
+
send test_method, klass
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.test_against_subclass(test_method, klass)
|
78
|
+
test_against_class test_method, klass, true
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
def upload_file(options = {})
|
83
|
+
use_temp_file options[:filename] do |file|
|
84
|
+
att = attachment_model.create :uploaded_data => fixture_file_upload(file, options[:content_type] || 'image/png')
|
85
|
+
att.reload unless att.new_record?
|
86
|
+
return att
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def use_temp_file(fixture_filename)
|
91
|
+
temp_path = File.join('/tmp', File.basename(fixture_filename))
|
92
|
+
FileUtils.mkdir_p File.join(fixture_path, 'tmp')
|
93
|
+
FileUtils.cp File.join(fixture_path, fixture_filename), File.join(fixture_path, temp_path)
|
94
|
+
yield temp_path
|
95
|
+
ensure
|
96
|
+
FileUtils.rm_rf File.join(fixture_path, 'tmp')
|
97
|
+
end
|
98
|
+
|
99
|
+
def assert_created(num = 1)
|
100
|
+
assert_difference attachment_model.base_class, :count, num do
|
101
|
+
if attachment_model.included_modules.include? DbFile
|
102
|
+
assert_difference DbFile, :count, num do
|
103
|
+
yield
|
104
|
+
end
|
105
|
+
else
|
106
|
+
yield
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def assert_not_created
|
112
|
+
assert_created(0) { yield }
|
113
|
+
end
|
114
|
+
|
115
|
+
def should_reject_by_size_with(klass)
|
116
|
+
attachment_model klass
|
117
|
+
assert_not_created do
|
118
|
+
attachment = upload_file :filename => '/files/rails.png'
|
119
|
+
assert attachment.new_record?
|
120
|
+
assert attachment.errors.on(:size)
|
121
|
+
assert_nil attachment.db_file if attachment.respond_to?(:db_file)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def assert_difference(object, method = nil, difference = 1)
|
126
|
+
initial_value = object.send(method)
|
127
|
+
yield
|
128
|
+
assert_equal initial_value + difference, object.send(method)
|
129
|
+
end
|
130
|
+
|
131
|
+
def assert_no_difference(object, method, &block)
|
132
|
+
assert_difference object, method, 0, &block
|
133
|
+
end
|
134
|
+
|
135
|
+
def attachment_model(klass = nil)
|
136
|
+
@attachment_model = klass if klass
|
137
|
+
@attachment_model
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
require File.join(File.dirname(__FILE__), 'fixtures/attachment')
|
142
|
+
require File.join(File.dirname(__FILE__), 'base_attachment_tests')
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
class ValidationTest < Test::Unit::TestCase
|
4
|
+
def test_should_invalidate_big_files
|
5
|
+
@attachment = SmallAttachment.new
|
6
|
+
assert !@attachment.valid?
|
7
|
+
assert @attachment.errors.on(:size)
|
8
|
+
|
9
|
+
@attachment.size = 2000
|
10
|
+
assert !@attachment.valid?
|
11
|
+
assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
|
12
|
+
|
13
|
+
@attachment.size = 1000
|
14
|
+
assert !@attachment.valid?
|
15
|
+
assert_nil @attachment.errors.on(:size)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_invalidate_small_files
|
19
|
+
@attachment = BigAttachment.new
|
20
|
+
assert !@attachment.valid?
|
21
|
+
assert @attachment.errors.on(:size)
|
22
|
+
|
23
|
+
@attachment.size = 2000
|
24
|
+
assert !@attachment.valid?
|
25
|
+
assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
|
26
|
+
|
27
|
+
@attachment.size = 1.megabyte
|
28
|
+
assert !@attachment.valid?
|
29
|
+
assert_nil @attachment.errors.on(:size)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_validate_content_type
|
33
|
+
@attachment = PdfAttachment.new
|
34
|
+
assert !@attachment.valid?
|
35
|
+
assert @attachment.errors.on(:content_type)
|
36
|
+
|
37
|
+
@attachment.content_type = 'foo'
|
38
|
+
assert !@attachment.valid?
|
39
|
+
assert @attachment.errors.on(:content_type)
|
40
|
+
|
41
|
+
@attachment.content_type = 'pdf'
|
42
|
+
assert !@attachment.valid?
|
43
|
+
assert_nil @attachment.errors.on(:content_type)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_require_filename
|
47
|
+
@attachment = Attachment.new
|
48
|
+
assert !@attachment.valid?
|
49
|
+
assert @attachment.errors.on(:filename)
|
50
|
+
|
51
|
+
@attachment.filename = 'foo'
|
52
|
+
assert !@attachment.valid?
|
53
|
+
assert_nil @attachment.errors.on(:filename)
|
54
|
+
end
|
55
|
+
end
|
@@ -63,6 +63,7 @@ module PaginatingFind
|
|
63
63
|
|
64
64
|
# Specify :count to prevent a count query.
|
65
65
|
unless (count = page_options.delete(:count))
|
66
|
+
original_table_name = self.table_name
|
66
67
|
count = count(collect_count_options(options))
|
67
68
|
count = count.length if options[:group]
|
68
69
|
end
|
@@ -106,12 +107,14 @@ module PaginatingFind
|
|
106
107
|
def collect_count_options(options)
|
107
108
|
rtn = {}.merge(options)
|
108
109
|
|
110
|
+
table = options[:from] || table_name
|
111
|
+
|
109
112
|
# If original :select includes the distinct keyword, then
|
110
113
|
# also include it in the count query
|
111
114
|
if rtn[:select].to_s.index(/\s*DISTINCT\s+/i) != nil
|
112
|
-
rtn[:select] = "DISTINCT #{
|
115
|
+
rtn[:select] = "DISTINCT #{table}.#{primary_key}"
|
113
116
|
else
|
114
|
-
rtn[:select] = "#{
|
117
|
+
rtn[:select] = "#{table}.#{primary_key}"
|
115
118
|
end
|
116
119
|
|
117
120
|
# AR::Base#find does not support :having, but some folks tack it on to the :group option,
|
@@ -40,15 +40,15 @@ class Admin::CategoriesController < Admin::BaseController
|
|
40
40
|
@category.tax_treatments.clear
|
41
41
|
@category.tax_treatments = TaxTreatment.find(params[:tax_treatments]) if params[:tax_treatments]
|
42
42
|
|
43
|
-
if params[:variation]
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
#if params[:variation]
|
44
|
+
# @variation = Variation.new(params[:variation])
|
45
|
+
# unless @variation.valid?
|
46
|
+
# flash[:error] = "Problem saving variation"
|
47
|
+
# redirect_to :action => "edit", :id => @category and return
|
48
|
+
# end
|
49
49
|
|
50
|
-
|
51
|
-
end
|
50
|
+
# @category.variations << @variation if @variation
|
51
|
+
#end
|
52
52
|
@category.save
|
53
53
|
|
54
54
|
if @category.update_attributes(params[:category])
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Admin::ImagesController < Admin::BaseController
|
2
|
+
|
3
|
+
def new
|
4
|
+
@image = Image.new
|
5
|
+
render :layout => false
|
6
|
+
end
|
7
|
+
|
8
|
+
# delete the variation (ajax call from either product or category edit screen)
|
9
|
+
def delete
|
10
|
+
image = Image.find(params[:id])
|
11
|
+
viewable = image.viewable
|
12
|
+
image.destroy
|
13
|
+
render :partial => 'shared/images', :locals => {:viewable => viewable}
|
14
|
+
end
|
15
|
+
|
16
|
+
# AJAX method to show variations based on change in parent category (during category edit)
|
17
|
+
def category_variations
|
18
|
+
category = Category.find_or_create_by_id(params[:category_id])
|
19
|
+
if (params[:parent_id].blank?)
|
20
|
+
category.parent = Category.find(:first)
|
21
|
+
else
|
22
|
+
category.parent = Category.find(params[:parent_id])
|
23
|
+
end
|
24
|
+
|
25
|
+
render :partial => 'shared/images',
|
26
|
+
:locals => {:variations => category.variations, :category => category},
|
27
|
+
:layout => false
|
28
|
+
end
|
29
|
+
|
30
|
+
# AJAX method to show variations based on change in category (during product edit)
|
31
|
+
def product_variations
|
32
|
+
product = Product.find_or_create_by_id(params[:product_id])
|
33
|
+
if (params[:category_id].blank?)
|
34
|
+
product.category = Category.find(:first)
|
35
|
+
else
|
36
|
+
product.category = Category.find(params[:category_id])
|
37
|
+
end
|
38
|
+
|
39
|
+
render :partial => 'shared/variations',
|
40
|
+
:locals => {:variations => product.variations, :product => product},
|
41
|
+
:layout => false
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -93,6 +93,10 @@ class Admin::ProductsController < Admin::BaseController
|
|
93
93
|
@product.save
|
94
94
|
end
|
95
95
|
|
96
|
+
if params[:image]
|
97
|
+
@product.images << Image.new(params[:image])
|
98
|
+
end
|
99
|
+
|
96
100
|
@product.tax_treatments = TaxTreatment.find(params[:tax_treatments]) if params[:tax_treatments]
|
97
101
|
@product.save
|
98
102
|
|
@@ -74,4 +74,29 @@ module RailsCart::BaseHelper
|
|
74
74
|
end
|
75
75
|
list.to_sentence({:connector => ","})
|
76
76
|
end
|
77
|
+
|
78
|
+
def mini_image(product)
|
79
|
+
if product.images.empty?
|
80
|
+
# TODO - show image not available
|
81
|
+
else
|
82
|
+
image_tag product.images.first.public_filename(:mini)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def small_image(product)
|
87
|
+
if product.images.empty?
|
88
|
+
# TODO - show image not available
|
89
|
+
else
|
90
|
+
image_tag product.images.first.public_filename(:small)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def product_image(product)
|
95
|
+
if product.images.empty?
|
96
|
+
# TODO - show image not available
|
97
|
+
else
|
98
|
+
image_tag product.images.first.public_filename(:product)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
77
102
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Image < ActiveRecord::Base
|
2
|
+
belongs_to :viewable, :polymorphic => true
|
3
|
+
has_attachment :content_type => :image,
|
4
|
+
:max_size => 500.kilobyte,
|
5
|
+
:resize_to => [360,360],
|
6
|
+
:thumbnails => {:product => [240,240], :small => [100,100], :mini => [48,48]},
|
7
|
+
:path_prefix => 'public/images/products',
|
8
|
+
:storage => :file_system,
|
9
|
+
:processor => :MiniMagick
|
10
|
+
|
11
|
+
validates_as_attachment
|
12
|
+
end
|
@@ -4,7 +4,7 @@ class Product < ActiveRecord::Base
|
|
4
4
|
has_many :variations, :dependent => :destroy
|
5
5
|
belongs_to :category
|
6
6
|
has_and_belongs_to_many :tax_treatments
|
7
|
-
|
7
|
+
has_many :images, :as => :viewable, :dependent => :destroy
|
8
8
|
has_one :sku, :as => :stockable, :dependent => :destroy
|
9
9
|
validates_presence_of :name
|
10
10
|
validates_presence_of :description
|
@@ -12,23 +12,22 @@ class Product < ActiveRecord::Base
|
|
12
12
|
|
13
13
|
alias :selected_options :product_option_types
|
14
14
|
|
15
|
-
def file=(incoming_file)
|
16
|
-
|
15
|
+
#def file=(incoming_file)
|
16
|
+
#@temp_file = incoming_file
|
17
17
|
#manually set the ActiveRecord field since its the file that is posted (and not filename)
|
18
|
-
self.filename = incoming_file.original_filename
|
19
|
-
|
20
|
-
end
|
18
|
+
#self.filename = incoming_file.original_filename
|
19
|
+
#end
|
21
20
|
|
22
|
-
def after_save
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
21
|
+
#def after_save
|
22
|
+
# if @temp_file
|
23
|
+
# save_file = "#{RAILS_ROOT}/public/images/products/#{self.filename}"
|
24
|
+
# logger.debug("saving " + save_file)
|
25
|
+
# @temp_file.rewind
|
26
|
+
# File.open(save_file, "wb") do |f|
|
27
|
+
# f.write(@temp_file.read)
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#end
|
32
31
|
|
33
32
|
# if product has a new category then we may need to delete variations associated with the
|
34
33
|
# previous category
|
@@ -17,9 +17,6 @@
|
|
17
17
|
:url => {:controller => :variations, :action => :category_variations},
|
18
18
|
:with => "'category_id=#{@category.id}&parent_id=' + encodeURIComponent(value)",
|
19
19
|
:on => 'changed' -%>
|
20
|
-
<div id="variationsWrapper">
|
21
|
-
<%= render :partial => 'shared/variations', :locals => {:variations => @category.variations, :category => @category, :product => nil} -%>
|
22
|
-
</div>
|
23
20
|
<div id="treatmentWrapper">
|
24
21
|
<%= render :partial => 'shared/tax_treatments', :locals => {:tax_treatments => @all_tax_treatments, :selected_treatments => @category.tax_treatments} -%>
|
25
22
|
</div>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h4>New Image</h4>
|
2
|
+
<% form_for(:image, :url => { :controller => 'images', :action => "new" }, :html => { :multipart => true }) do |form| %>
|
3
|
+
<table class="basic-table">
|
4
|
+
<tr>
|
5
|
+
<td>Filename:</td>
|
6
|
+
<td><%= form.file_field :uploaded_data %></td>
|
7
|
+
</tr>
|
8
|
+
</table>
|
9
|
+
<% end %>
|
10
|
+
|
@@ -34,18 +34,18 @@
|
|
34
34
|
:with => "'id=#{@product.id}&category_id=' + encodeURIComponent(value)",
|
35
35
|
:on => 'changed' -%>
|
36
36
|
</p>
|
37
|
-
|
38
37
|
<br/>
|
39
38
|
<div id="variation-listing">
|
40
39
|
<%= render :partial => 'variations', :locals => {:product => @product} -%>
|
41
40
|
</div>
|
42
|
-
<br/>
|
43
|
-
|
44
41
|
<br/>
|
45
42
|
<div id="option-type-listing">
|
46
43
|
<%= render :partial => 'option_types', :locals => {:product => @product} -%>
|
47
44
|
</div>
|
48
45
|
<br/>
|
46
|
+
<div id="image-listing">
|
47
|
+
<%= render :partial => 'shared/images', :locals => {:viewable => @product} -%>
|
48
|
+
</div>
|
49
49
|
|
50
50
|
<p>
|
51
51
|
<label for="tags">Tags:</label><br/>
|