radiant-shop-extension 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -1
- data/VERSION +1 -1
- data/app/controllers/admin/shop/categories_controller.rb +32 -65
- data/app/controllers/admin/shop/customers_controller.rb +8 -7
- data/app/controllers/admin/shop/orders_controller.rb +37 -159
- data/app/controllers/admin/shop/packages/packings_controller.rb +90 -0
- data/app/controllers/admin/shop/packages_controller.rb +65 -0
- data/app/controllers/admin/shop/products/images_controller.rb +5 -8
- data/app/controllers/admin/shop/products/variant_templates_controller.rb +27 -0
- data/app/controllers/admin/shop/products/variants_controller.rb +60 -0
- data/app/controllers/admin/shop/products_controller.rb +67 -64
- data/app/controllers/admin/shop/variants_controller.rb +49 -0
- data/app/helpers/shop_helper.rb +5 -0
- data/app/models/form_address.rb +144 -0
- data/app/models/form_checkout.rb +200 -307
- data/app/models/form_line_item.rb +60 -0
- data/app/models/shop_address.rb +2 -2
- data/app/models/shop_category.rb +48 -51
- data/app/models/shop_customer.rb +25 -5
- data/app/models/shop_group.rb +15 -0
- data/app/models/shop_grouping.rb +6 -0
- data/app/models/shop_line_item.rb +7 -6
- data/app/models/shop_order.rb +44 -16
- data/app/models/shop_package.rb +74 -0
- data/app/models/shop_packing.rb +22 -0
- data/app/models/shop_page.rb +7 -0
- data/app/models/shop_payment.rb +5 -1
- data/app/models/shop_product.rb +86 -48
- data/app/models/shop_product_attachment.rb +5 -2
- data/app/models/shop_product_variant.rb +31 -0
- data/app/models/shop_variant.rb +25 -0
- data/app/views/admin/shop/categories/edit.html.haml +9 -10
- data/app/views/admin/shop/categories/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/categories/edit/_form.html.haml +14 -0
- data/app/views/admin/shop/categories/edit/_head.html.haml +4 -2
- data/app/views/admin/shop/categories/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/categories/edit/_meta.html.haml +8 -7
- data/app/views/admin/shop/categories/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/categories/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/categories/edit/inputs/_name.html.haml +4 -0
- data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +6 -5
- data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +6 -5
- data/app/views/admin/shop/categories/edit/meta/_page.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/parts/_description.html.haml +4 -1
- data/app/views/admin/shop/categories/index/_category.html.haml +11 -10
- data/app/views/admin/shop/categories/new.html.haml +10 -9
- data/app/views/admin/shop/customers/edit.html.haml +8 -10
- data/app/views/admin/shop/customers/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/customers/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/customers/edit/_head.html.haml +4 -2
- data/app/views/admin/shop/customers/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/customers/edit/_parts.html.haml +9 -4
- data/app/views/admin/shop/customers/edit/inputs/_email.html.haml +3 -0
- data/app/views/admin/shop/customers/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/customers/edit/parts/_orders.html.haml +10 -6
- data/app/views/admin/shop/customers/index.html.haml +4 -1
- data/app/views/admin/shop/customers/index/_customer.html.haml +3 -3
- data/app/views/admin/shop/customers/index/_foot.html.haml +4 -0
- data/app/views/admin/shop/customers/index/_head.html.haml +4 -0
- data/app/views/admin/shop/customers/new.html.haml +9 -9
- data/app/views/admin/shop/orders/edit.html.haml +11 -0
- data/app/views/admin/shop/orders/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/orders/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/orders/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/orders/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/orders/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/orders/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/orders/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/orders/edit/parts/_address.html.haml +7 -0
- data/app/views/admin/shop/orders/edit/parts/_addresses.html.haml +9 -0
- data/app/views/admin/shop/orders/edit/parts/_customer.html.haml +3 -0
- data/app/views/admin/shop/orders/edit/parts/_items.html.haml +8 -0
- data/app/views/admin/shop/orders/index.html.haml +10 -30
- data/app/views/admin/shop/orders/index/_foot.html.haml +3 -0
- data/app/views/admin/shop/orders/index/_head.html.haml +4 -0
- data/app/views/admin/shop/orders/index/_order.html.haml +13 -0
- data/app/views/admin/shop/orders/index/buttons/_all.html.haml +1 -0
- data/app/views/admin/shop/orders/index/buttons/_new.html.haml +1 -0
- data/app/views/admin/shop/orders/index/buttons/_paid.html.haml +1 -0
- data/app/views/admin/shop/orders/index/buttons/_shipped.html.haml +1 -0
- data/app/views/admin/shop/packages/edit.html.haml +11 -0
- data/app/views/admin/shop/packages/edit/_foot.html.haml +17 -0
- data/app/views/admin/shop/packages/edit/_form.html.haml +15 -0
- data/app/views/admin/shop/packages/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/packages/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/packages/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/packages/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/packages/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +1 -0
- data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +5 -0
- data/app/views/admin/shop/packages/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/packages/edit/parts/_products.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +7 -0
- data/app/views/admin/shop/packages/edit/shared/_product.html.haml +8 -0
- data/app/views/admin/shop/packages/index.html.haml +13 -0
- data/app/views/admin/shop/packages/index/_foot.html.haml +7 -0
- data/app/views/admin/shop/packages/index/_head.html.haml +4 -0
- data/app/views/admin/shop/packages/index/_package.html.haml +9 -0
- data/app/views/admin/shop/packages/new.html.haml +11 -0
- data/app/views/admin/shop/packages/remove.html.haml +12 -0
- data/app/views/admin/shop/products/edit.html.haml +9 -12
- data/app/views/admin/shop/products/edit/_foot.html.haml +19 -0
- data/app/views/admin/shop/products/edit/_form.html.haml +15 -0
- data/app/views/admin/shop/products/edit/_head.html.haml +4 -2
- data/app/views/admin/shop/products/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/products/edit/_meta.html.haml +8 -8
- data/app/views/admin/shop/products/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/products/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -1
- data/app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml +1 -0
- data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -1
- data/app/views/admin/shop/products/edit/buttons/_new_variant.html.haml +1 -0
- data/app/views/admin/shop/products/edit/inputs/_name.html.haml +4 -0
- data/app/views/admin/shop/products/edit/inputs/_price.html.haml +3 -0
- data/app/views/admin/shop/products/edit/meta/_category.html.haml +6 -5
- data/app/views/admin/shop/products/edit/meta/_page.html.haml +2 -0
- data/app/views/admin/shop/products/edit/meta/_sku.html.haml +6 -5
- data/app/views/admin/shop/products/edit/parts/_customers.html.haml +5 -0
- data/app/views/admin/shop/products/edit/parts/_description.html.haml +4 -1
- data/app/views/admin/shop/products/edit/parts/_images.html.haml +1 -1
- data/app/views/admin/shop/products/edit/parts/_variants.html.haml +3 -0
- data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +1 -1
- data/app/views/admin/shop/products/edit/popups/_browse_templates.html.haml +6 -0
- data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +4 -4
- data/app/views/admin/shop/products/edit/popups/_new_variant.html.haml +16 -0
- data/app/views/admin/shop/products/edit/{_image.html.haml → shared/_image.html.haml} +0 -0
- data/app/views/admin/shop/products/edit/shared/_template.html.haml +6 -0
- data/app/views/admin/shop/products/edit/shared/_variant.html.haml +10 -0
- data/app/views/admin/shop/products/index.html.haml +6 -3
- data/app/views/admin/shop/products/index/_foot.html.haml +10 -0
- data/app/views/admin/shop/products/index/_head.html.haml +4 -0
- data/app/views/admin/shop/products/index/_product.html.haml +18 -10
- data/app/views/admin/shop/products/index/buttons/_discounts.html.haml +1 -0
- data/app/views/admin/shop/products/index/buttons/_packages.html.haml +1 -0
- data/app/views/admin/shop/products/index/buttons/_variants.html.haml +1 -0
- data/app/views/admin/shop/products/new.html.haml +10 -9
- data/app/views/admin/shop/variants/edit.html.haml +11 -0
- data/app/views/admin/shop/variants/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/variants/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/variants/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/variants/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/variants/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/variants/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/variants/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/variants/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/variants/edit/inputs/_options.html.haml +3 -0
- data/app/views/admin/shop/variants/index.html.haml +13 -0
- data/app/views/admin/shop/variants/index/_foot.html.haml +4 -0
- data/app/views/admin/shop/variants/index/_head.html.haml +4 -0
- data/app/views/admin/shop/variants/index/_variant.html.haml +9 -0
- data/app/views/admin/shop/variants/new.html.haml +11 -0
- data/app/views/admin/shop/variants/remove.html.haml +12 -0
- data/config/locales/en.yml +8 -1
- data/config/routes.rb +11 -22
- data/db/migrate/20100929011106_fix_relationship_foreign_keys.rb +101 -0
- data/db/migrate/20100929011607_drop_shop_addressables.rb +25 -0
- data/db/migrate/20100929030510_create_shop_groups.rb +19 -0
- data/db/migrate/20100929080301_shop_groups_change_add_description.rb +11 -0
- data/db/migrate/20100929081200_create_variants.rb +20 -0
- data/db/migrate/20100929143531_change_variants_add_updated_by.rb +25 -0
- data/db/migrate/20100929145641_change_created_by_to_id.rb +75 -0
- data/db/migrate/20100929235221_change_category_add_variant_id.rb +9 -0
- data/db/migrate/20100930235221_create_packages.rb +31 -0
- data/db/migrate/20101005231713_create_page_ids.rb +11 -0
- data/db/migrate/20101006051214_create_pages_for_products_and_categories.rb +73 -0
- data/db/migrate/20101007111845_add_default_position_to_attachment.rb +9 -0
- data/lib/shop/controllers/application_controller.rb +1 -1
- data/lib/shop/interface/categories.rb +29 -0
- data/lib/shop/interface/customers.rb +15 -15
- data/lib/shop/interface/orders.rb +34 -0
- data/lib/shop/interface/packages.rb +34 -0
- data/lib/shop/interface/products.rb +18 -31
- data/lib/shop/interface/variants.rb +34 -0
- data/lib/shop/models/form_extension.rb +23 -0
- data/lib/shop/models/page.rb +3 -2
- data/lib/shop/tags/address.rb +3 -3
- data/lib/shop/tags/cart.rb +12 -16
- data/lib/shop/tags/category.rb +4 -6
- data/lib/shop/tags/helpers.rb +131 -30
- data/lib/shop/tags/item.rb +16 -33
- data/lib/shop/tags/package.rb +95 -0
- data/lib/shop/tags/product.rb +11 -16
- data/lib/shop/tags/product_variant.rb +52 -0
- data/mockups/discounts/new-edit.bmml +492 -0
- data/public/javascripts/admin/extensions/shop/edit.js +20 -0
- data/public/javascripts/admin/extensions/shop/packages/edit.js +109 -0
- data/public/javascripts/admin/extensions/shop/products/edit.js +64 -65
- data/public/javascripts/admin/extensions/shop/products/index.js +31 -36
- data/public/stylesheets/sass/admin/extensions/shop/edit.sass +58 -11
- data/public/stylesheets/sass/admin/extensions/shop/index.sass +104 -53
- data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +162 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +115 -36
- data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +12 -20
- data/radiant-shop-extension.gemspec +182 -38
- data/shop_extension.rb +29 -25
- data/spec/controllers/admin/shop/categories_controller_spec.rb +76 -191
- data/spec/controllers/admin/shop/customers_controller_spec.rb +67 -0
- data/spec/controllers/admin/shop/orders_controller_spec.rb +85 -0
- data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +188 -0
- data/spec/controllers/admin/shop/packages_controller_spec.rb +32 -0
- data/spec/controllers/admin/shop/products/images_controller_spec.rb +10 -15
- data/spec/controllers/admin/shop/products/variant_templates_controller_spec.rb +53 -0
- data/spec/controllers/admin/shop/products/variants_controller_spec.rb +116 -0
- data/spec/controllers/admin/shop/products_controller_spec.rb +80 -148
- data/spec/controllers/admin/shop/variants_controller_spec.rb +67 -0
- data/spec/datasets/forms.rb +23 -8
- data/spec/datasets/shop_addresses.rb +1 -4
- data/spec/datasets/shop_categories.rb +25 -4
- data/spec/datasets/shop_groups.rb +15 -0
- data/spec/datasets/shop_line_items.rb +4 -3
- data/spec/datasets/shop_orders.rb +6 -15
- data/spec/datasets/shop_packages.rb +25 -0
- data/spec/datasets/shop_payments.rb +12 -0
- data/spec/datasets/{images.rb → shop_product_attachments.rb} +9 -1
- data/spec/datasets/shop_product_variants.rb +22 -0
- data/spec/datasets/shop_products.rb +28 -18
- data/spec/datasets/shop_variants.rb +17 -0
- data/spec/lib/shop/models/image_spec.rb +4 -4
- data/spec/lib/shop/tags/address_spec.rb +3 -3
- data/spec/lib/shop/tags/cart_spec.rb +32 -43
- data/spec/lib/shop/tags/category_spec.rb +58 -93
- data/spec/lib/shop/tags/helpers_spec.rb +162 -69
- data/spec/lib/shop/tags/item_spec.rb +116 -158
- data/spec/lib/shop/tags/package_spec.rb +342 -0
- data/spec/lib/shop/tags/product_spec.rb +29 -26
- data/spec/lib/shop/tags/product_variant_spec.rb +175 -0
- data/spec/models/form_address_spec.rb +166 -0
- data/spec/models/form_checkout_spec.rb +27 -157
- data/spec/models/shop_address_spec.rb +81 -0
- data/spec/models/shop_category_spec.rb +114 -31
- data/spec/models/shop_customer_spec.rb +105 -0
- data/spec/models/shop_group_spec.rb +38 -0
- data/spec/models/shop_line_item_spec.rb +5 -5
- data/spec/models/shop_order_spec.rb +89 -83
- data/spec/models/shop_package_spec.rb +117 -0
- data/spec/models/shop_packing_spec.rb +67 -0
- data/spec/models/shop_payment_spec.rb +19 -0
- data/spec/models/shop_product_attachment_spec.rb +4 -3
- data/spec/models/shop_product_spec.rb +171 -92
- data/spec/models/shop_product_variant_spec.rb +92 -0
- data/spec/models/shop_variant_spec.rb +47 -0
- metadata +183 -39
- data/app/controllers/shop/categories_controller.rb +0 -45
- data/app/controllers/shop/line_items_controller.rb +0 -165
- data/app/controllers/shop/orders_controller.rb +0 -16
- data/app/controllers/shop/products_controller.rb +0 -48
- data/app/models/shop_addressable.rb +0 -11
- data/app/views/admin/shop/categories/edit/_fields.html.haml +0 -28
- data/app/views/admin/shop/categories/edit/_part.html.haml +0 -3
- data/app/views/admin/shop/categories/edit/_popup.html.haml +0 -3
- data/app/views/admin/shop/customers/edit/_fields.html.haml +0 -33
- data/app/views/admin/shop/customers/index/_bottom.html.haml +0 -4
- data/app/views/admin/shop/products/edit/_fields.html.haml +0 -38
- data/app/views/admin/shop/products/edit/_part.html.haml +0 -3
- data/app/views/admin/shop/products/edit/_popup.html.haml +0 -3
- data/app/views/admin/shop/products/index/_bottom.html.haml +0 -5
- data/spec/controllers/shop/categories_controller_spec.rb +0 -42
- data/spec/controllers/shop/line_items_controller_spec.rb +0 -256
- data/spec/controllers/shop/orders_controller_specs.rb +0 -37
- data/spec/controllers/shop/products_controller_spec.rb +0 -51
- data/vendor/plugins/json_fields/.gitignore +0 -3
- data/vendor/plugins/json_fields/MIT-LICENSE +0 -20
- data/vendor/plugins/json_fields/README.rdoc +0 -65
- data/vendor/plugins/json_fields/Rakefile +0 -55
- data/vendor/plugins/json_fields/init.rb +0 -2
- data/vendor/plugins/json_fields/lib/json_fields.rb +0 -99
- data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +0 -124
- data/vendor/plugins/json_fields/spec/spec.opts +0 -6
- data/vendor/plugins/json_fields/spec/spec_helper.rb +0 -29
- data/vendor/plugins/json_fields/spec/test_models.rb +0 -12
@@ -1,99 +0,0 @@
|
|
1
|
-
######
|
2
|
-
# JSON-Stored Fields
|
3
|
-
# (c) 2008-2009 Aurora Software (http://www.aurorasoft.com.au)
|
4
|
-
#
|
5
|
-
# http://www.github.com/aurorasoft/json_fields
|
6
|
-
#
|
7
|
-
######
|
8
|
-
|
9
|
-
require 'json'
|
10
|
-
|
11
|
-
module JsonFields
|
12
|
-
def self.included(base)
|
13
|
-
base.extend(ClassMethods)
|
14
|
-
base.class_eval do
|
15
|
-
include InstanceMethods
|
16
|
-
before_save :store_json_data
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
module ClassMethods
|
21
|
-
def set_json_field(field_name)
|
22
|
-
define_method :json_backed_field_name do
|
23
|
-
field_name.to_sym
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def has_json_field(*fields)
|
28
|
-
if fields.is_a? Symbol then
|
29
|
-
fields=[fields]
|
30
|
-
end
|
31
|
-
fields.each do |field|
|
32
|
-
define_method("#{field.to_s}") do
|
33
|
-
json_field_get(field)
|
34
|
-
end
|
35
|
-
define_method("#{field.to_s}=") do |value|
|
36
|
-
json_field_set(field, value)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module InstanceMethods
|
43
|
-
# Default field name
|
44
|
-
def json_backed_field_name
|
45
|
-
:json_field
|
46
|
-
end
|
47
|
-
|
48
|
-
def json_field_get(field)
|
49
|
-
load_json_data
|
50
|
-
# NOTE: to_json forces symbols to string! So, convert here so as that
|
51
|
-
# we don't get caught out!
|
52
|
-
@json_data[field.to_s]
|
53
|
-
end
|
54
|
-
|
55
|
-
def json_field_set(field, value)
|
56
|
-
load_json_data
|
57
|
-
# NOTE: to_json forces symbols to string! So, convert here so as that
|
58
|
-
# we don't get caught out!
|
59
|
-
@json_data ||= {}
|
60
|
-
@json_data[field.to_s]=value
|
61
|
-
end
|
62
|
-
|
63
|
-
def load_json_data
|
64
|
-
if !respond_to?(:json_backed_field_name) then
|
65
|
-
# We don't know which field to use
|
66
|
-
raise 'Not a JSON-backed field'
|
67
|
-
else
|
68
|
-
if @json_data then
|
69
|
-
# The data is already loaded - use the version in memory
|
70
|
-
else
|
71
|
-
# It's not loaded yet - do we have anything to load?
|
72
|
-
if self.send(json_backed_field_name).blank? then
|
73
|
-
# No data saved as yet - prepare an empty hash
|
74
|
-
@json_data = {}
|
75
|
-
else
|
76
|
-
# We have data - parse it from JSON
|
77
|
-
@json_data=JSON.parse(self.send(json_backed_field_name))
|
78
|
-
end
|
79
|
-
end
|
80
|
-
return @json_data
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# before_save
|
85
|
-
# Takes the current data in @json_data and stores it as test_results
|
86
|
-
def store_json_data
|
87
|
-
if !respond_to?(:json_backed_field_name) then
|
88
|
-
# This model doesn't have the data field, so skip it
|
89
|
-
return true
|
90
|
-
else
|
91
|
-
if !@json_data then
|
92
|
-
# The JSON data hasn't even been loaded - so, leave the field as is
|
93
|
-
else
|
94
|
-
self.send("#{json_backed_field_name}=", @json_data.to_json)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe 'JsonFields' do
|
4
|
-
it "should add class methods to ActiveRecord::Base" do
|
5
|
-
ActiveRecord::Base.should respond_to(:has_json_field)
|
6
|
-
ActiveRecord::Base.should respond_to(:set_json_field)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should add relevant hooks to before_save" do
|
10
|
-
JsonFieldsDefaultTestModel.expects(:before_save).with(:store_json_data)
|
11
|
-
JsonFieldsDefaultTestModel.class_eval do
|
12
|
-
include JsonFields
|
13
|
-
has_json_field :field_1, :field_2, :field_3
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should accept single field to add" do
|
18
|
-
JsonFieldsSimpleTestModel.expects(:before_save).with(:store_json_data)
|
19
|
-
JsonFieldsSimpleTestModel.class_eval do
|
20
|
-
include JsonFields
|
21
|
-
has_json_field :field_1
|
22
|
-
end
|
23
|
-
@i=JsonFieldsSimpleTestModel.new
|
24
|
-
@i.should respond_to(:field_1)
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "instance with default field name" do
|
28
|
-
before do
|
29
|
-
JsonFieldsDefaultTestModel.expects(:before_save).with(:store_json_data)
|
30
|
-
JsonFieldsDefaultTestModel.class_eval do
|
31
|
-
include JsonFields
|
32
|
-
has_json_field :field_1, :field_2, :field_3
|
33
|
-
end
|
34
|
-
@i=JsonFieldsDefaultTestModel.new
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should respond to added methods" do
|
38
|
-
@i.should respond_to(:json_field_get)
|
39
|
-
@i.should respond_to(:json_field_set)
|
40
|
-
%w( field_1 field_2 field_3 ).each do |field|
|
41
|
-
@i.should respond_to(field.to_sym)
|
42
|
-
@i.should respond_to("#{field}=".to_sym)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should get and set fields manually by strings" do
|
47
|
-
@i.json_field_set('foo', 100)
|
48
|
-
@i.json_field_set('bar', 200)
|
49
|
-
@i.instance_variable_get(:@json_data).should == { 'foo' => 100, 'bar' => 200 }
|
50
|
-
@i.json_field_get('foo').should == 100
|
51
|
-
@i.json_field_get('bar').should == 200
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should manually get missing fields OK" do
|
55
|
-
@i.json_field_get('missingfield').should be_nil
|
56
|
-
@i.json_field_get(:missingfield).should be_nil
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should get and set fields manually by symbols" do
|
60
|
-
@i.json_field_set(:foo, 100)
|
61
|
-
@i.json_field_set(:bar, 200)
|
62
|
-
# Internally, we store everything as strings because JSON can't handle symbols correctly
|
63
|
-
@i.instance_variable_get(:@json_data).should == { 'foo' => 100, 'bar' => 200 }
|
64
|
-
@i.json_field_get(:foo).should == 100
|
65
|
-
@i.json_field_get(:bar).should == 200
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should get and set fields by the added methods" do
|
69
|
-
@i.field_1=100
|
70
|
-
@i.field_2=200
|
71
|
-
@i.json_field_set(:field_3, 300)
|
72
|
-
@i.instance_variable_get(:@json_data).should == { 'field_1' => 100, 'field_2' => 200, 'field_3' => 300 }
|
73
|
-
@i.field_1.should == 100
|
74
|
-
@i.field_2.should == 200
|
75
|
-
@i.field_3.should == 300
|
76
|
-
@i.json_field_get(:field_1).should == 100
|
77
|
-
@i.json_field_get(:field_2).should == 200
|
78
|
-
@i.json_field_get(:field_3).should == 300
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should set field data as JSON before_save" do
|
82
|
-
data={ :foo => 100, :bar => 200 }
|
83
|
-
data.each do |key, value|
|
84
|
-
@i.json_field_set(key, value)
|
85
|
-
end
|
86
|
-
@i.store_json_data
|
87
|
-
@i.json_field.should == '{"foo":100,"bar":200}'
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should load the field data from JSON on first read" do
|
91
|
-
@i.stubs(:json_field).returns("{\"a\":50,\"b\":150}")
|
92
|
-
@i.json_field_get(:a).should == 50
|
93
|
-
@i.json_field_get(:b).should == 150
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "instance with custom field name" do
|
98
|
-
before do
|
99
|
-
JsonFieldsCustomTestModel.expects(:before_save).with(:store_json_data)
|
100
|
-
JsonFieldsCustomTestModel.class_eval do
|
101
|
-
include JsonFields
|
102
|
-
has_json_field :field_1, :field_2, :field_3
|
103
|
-
set_json_field :custom_json_field
|
104
|
-
end
|
105
|
-
@i=JsonFieldsCustomTestModel.new
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should set field data as JSON before_save" do
|
109
|
-
@i.stubs(:custom_json_field).with(nil)
|
110
|
-
@i.expects(:custom_json_field=).with('{"foo":100,"bar":200}')
|
111
|
-
data={ :foo => 100, :bar => 200 }
|
112
|
-
data.each do |key, value|
|
113
|
-
@i.json_field_set(key, value)
|
114
|
-
end
|
115
|
-
@i.store_json_data
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should load the field data from JSON on first read" do
|
119
|
-
@i.stubs(:custom_json_field).returns("{\"a\":50,\"b\":150}")
|
120
|
-
@i.json_field_get(:a).should == 50
|
121
|
-
@i.json_field_get(:b).should == 150
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
|
3
|
-
|
4
|
-
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
5
|
-
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
6
|
-
end
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/test_models.rb'
|
9
|
-
require 'mocha'
|
10
|
-
|
11
|
-
Spec::Runner.configure do |config|
|
12
|
-
# config.use_transactional_fixtures = true
|
13
|
-
# config.use_instantiated_fixtures = false
|
14
|
-
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
15
|
-
|
16
|
-
config.mock_with :mocha
|
17
|
-
|
18
|
-
# You can declare fixtures for each behaviour like this:
|
19
|
-
# describe "...." do
|
20
|
-
# fixtures :table_a, :table_b
|
21
|
-
#
|
22
|
-
# Alternatively, if you prefer to declare them only once, you can
|
23
|
-
# do so here, like so ...
|
24
|
-
#
|
25
|
-
# config.global_fixtures = :table_a, :table_b
|
26
|
-
#
|
27
|
-
# If you declare global fixtures, be aware that they will be declared
|
28
|
-
# for all of your examples, even those that don't use them.
|
29
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class JsonFieldsDefaultTestModel
|
2
|
-
def json_field
|
3
|
-
@json_field
|
4
|
-
end
|
5
|
-
def json_field=(new)
|
6
|
-
@json_field=new
|
7
|
-
end
|
8
|
-
end
|
9
|
-
class JsonFieldsSimpleTestModel < JsonFieldsDefaultTestModel
|
10
|
-
end
|
11
|
-
class JsonFieldsCustomTestModel < JsonFieldsDefaultTestModel
|
12
|
-
end
|