refinerycms 0.9.8.5 → 0.9.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +15 -21
- data/bin/refinerycms +9 -12
- data/changelog.md +164 -154
- data/db/migrate/20100913234704_create_refinery_schema.rb +151 -0
- data/db/migrate/20100926142529_add_value_type_to_refinery_settings.rb +9 -0
- data/db/migrate/20100929035252_add_missing_indexes_to_roles_users.rb +11 -0
- data/db/schema.rb +5 -1
- data/db/seeds/pages.rb +0 -39
- data/db/seeds/pages_for_inquiries.rb +40 -0
- data/vendor/refinerycms/authentication/app/models/roles_users.rb +6 -0
- data/vendor/refinerycms/authentication/features/lost_password.feature +1 -0
- data/vendor/refinerycms/authentication/features/manage_users.feature +1 -1
- data/vendor/refinerycms/authentication/features/step_definitions/lost_password.rb +2 -2
- data/vendor/refinerycms/authentication/features/support/factories.rb +1 -0
- data/vendor/refinerycms/authentication/spec/models/user_spec.rb +52 -0
- data/vendor/refinerycms/core/app/views/admin/_head.html.erb +1 -4
- data/vendor/refinerycms/core/app/views/shared/_menu.html.erb +11 -5
- data/vendor/refinerycms/core/app/views/shared/_menu_branch.html.erb +8 -8
- data/vendor/refinerycms/core/app/views/shared/admin/_make_sortable.html.erb +3 -2
- data/vendor/refinerycms/core/app/views/shared/admin/_sortable_list.html.erb +2 -3
- data/vendor/refinerycms/core/lib/core.rb +5 -5
- data/vendor/refinerycms/core/lib/generators/refinery_engine/refinery_engine_generator.rb +2 -2
- data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/app/views/admin/plural_name/index.html.erb +11 -9
- data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/db/seeds/plural_name.rb +1 -1
- data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/lib/generators/refinerycms_plural_name_generator.rb +3 -3
- data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/lib/plural_name.rb +1 -1
- data/vendor/refinerycms/core/lib/refinery/crud.rb +48 -28
- data/vendor/refinerycms/core/lib/refinery/helpers/menu_helper.rb +34 -4
- data/vendor/refinerycms/core/lib/refinery/plugin.rb +5 -5
- data/vendor/refinerycms/core/public/javascripts/rails.js +152 -0
- data/vendor/refinerycms/core/public/javascripts/refinery/admin.js +33 -13
- data/vendor/refinerycms/core/public/javascripts/wymeditor/jquery.refinery.wymeditor.js +191 -175
- data/vendor/refinerycms/core/public/stylesheets/refinery/refinery.css +80 -12
- data/vendor/refinerycms/dashboard/features/dashboard.feature +3 -1
- data/vendor/refinerycms/images/features/support/factories.rb +5 -0
- data/vendor/refinerycms/images/lib/images.rb +7 -35
- data/vendor/refinerycms/images/spec/models/image_spec.rb +50 -0
- data/vendor/refinerycms/images/spec/uploads/beach.jpeg +0 -0
- data/vendor/refinerycms/pages/features/manage_pages.feature +1 -1
- data/vendor/refinerycms/pages/features/step_definitions/page_steps.rb +19 -3
- data/vendor/refinerycms/pages/features/support/paths.rb +9 -1
- data/vendor/refinerycms/pages/features/visit_pages.feature +45 -0
- data/vendor/refinerycms/pages/spec/models/page_spec.rb +134 -4
- data/vendor/refinerycms/refinery.rb +1 -1
- data/vendor/refinerycms/resources/features/manage_files.feature +5 -1
- data/vendor/refinerycms/resources/features/step_definitions/file_steps.rb +2 -2
- data/vendor/refinerycms/resources/lib/resources.rb +8 -37
- data/vendor/refinerycms/resources/spec/models/resource_spec.rb +45 -0
- data/vendor/refinerycms/resources/spec/uploads/refinery_is_awesome.txt +1 -0
- data/vendor/refinerycms/settings/app/models/refinery_setting.rb +26 -12
- data/vendor/refinerycms/settings/features/manage_refinery_settings.feature +1 -1
- data/vendor/refinerycms/settings/spec/models/refinery_setting_spec.rb +101 -0
- metadata +37 -56
- data/db/migrate/20091109012126_add_missing_indexes.rb +0 -25
- data/db/migrate/20091130040711_add_down_for_maintenance_page.rb +0 -15
- data/db/migrate/20091207033335_add_superuser_to_users.rb +0 -12
- data/db/migrate/20100114092849_add_themes_table.rb +0 -19
- data/db/migrate/20100125003944_rename_title_to_name_on_user_plugins.rb +0 -9
- data/db/migrate/20100125033146_migrate_old_plugin_titles_to_plugin_names_for_users.rb +0 -61
- data/db/migrate/20100127004649_add_reset_code_to_users.rb +0 -9
- data/db/migrate/20100202034802_remove_custom_title_image_id_and_image_id_from_pages.rb +0 -13
- data/db/migrate/20100204011654_change_part_titles_to_titleized_version_for_new_format.rb +0 -13
- data/db/migrate/20100223211536_remove_themes_table.rb +0 -17
- data/db/migrate/20100305023036_change_users_columns_for_authlogic.rb +0 -54
- data/db/migrate/20100305023037_remove_unused_users_columns.rb +0 -15
- data/db/migrate/20100312155331_make_user_perishable_token_nullable.rb +0 -13
- data/db/migrate/20100312160327_make_user_persistence_token_nullable.rb +0 -13
- data/db/migrate/20100315203301_remove_state_from_users.rb +0 -9
- data/db/migrate/20100419001048_change_image_grid_thumbnail_size_and_regenerate.rb +0 -13
- data/db/migrate/20100522020225_rename_permissions_for_resources_plugin_to_files.rb +0 -15
- data/db/migrate/20100525084518_remove_take_down_for_maintenance_page.rb +0 -19
- data/db/migrate/20100525110237_add_small_and_large_thumbnail_sizes.rb +0 -14
- data/db/migrate/20100530205942_update_link_url_on_pages_from_inquiries_new_to_contact.rb +0 -31
- data/db/migrate/20100605132138_convert_resource_to_dragonfly.rb +0 -41
- data/db/migrate/20100605132208_convert_image_to_dragonfly.rb +0 -51
- data/db/migrate/20100606135207_change_thumbnail_sizes_for_dragonfly.rb +0 -17
- data/db/migrate/20100608062447_add_scoping_to_refinery_settings.rb +0 -9
- data/db/migrate/20100623220402_add_restricted_to_refinery_settings.rb +0 -9
- data/db/migrate/20100624024501_add_roles.rb +0 -24
- data/db/migrate/20100629081543_add_callback_proc_as_string_to_refinery_settings.rb +0 -9
- data/db/migrate/20100701053151_remove_superuser_from_users.rb +0 -20
- data/db/migrate/20100702022630_add_spam_to_inquiries.rb +0 -11
- data/db/migrate/20100708014636_ensure_user_plugins_use_name_and_not_title.rb +0 -9
- data/db/migrate/20100729221735_remove_page_translations_if_present.rb +0 -12
- data/db/migrate/20100826232810_move_inquiry_settings_to_refinery_settings.rb +0 -23
- data/db/migrate/20100831122919_move_page_to_nested_set.rb +0 -28
- data/db/migrate/20100913234704_add_cached_slug_to_pages.rb +0 -12
- data/db/seeds/inquiry_settings.rb +0 -2
@@ -1,13 +1,143 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Page do
|
4
|
-
|
4
|
+
|
5
|
+
def reset_page(options = {})
|
5
6
|
@valid_attributes = {
|
6
|
-
:
|
7
|
+
:id => 1,
|
8
|
+
:title => "RSpec is great for testing too",
|
9
|
+
:deletable => true
|
7
10
|
}
|
11
|
+
|
12
|
+
@page.destroy! if @page
|
13
|
+
@page = Page.create!(@valid_attributes)
|
14
|
+
@page.update_attributes(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def page_cannot_be_destroyed
|
18
|
+
@page.destroy.should == false
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_child
|
22
|
+
@child = @page.children.create(:title => 'The child page')
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_page_parts
|
26
|
+
@page.parts.create(:title => 'body', :content => "I'm the first page part for this page.")
|
27
|
+
@page.parts.create(:title => 'side body', :content => "Closely followed by the second page part.")
|
28
|
+
end
|
29
|
+
|
30
|
+
def turn_off_marketable_urls
|
31
|
+
RefinerySetting.set(:use_marketable_urls, {:value => false, :scoping => 'pages'})
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
before(:each) do
|
36
|
+
reset_page
|
37
|
+
end
|
38
|
+
|
39
|
+
context "cannot be deleted under certain rules" do
|
40
|
+
it "if link_url is present" do
|
41
|
+
reset_page({:link_url => '/plugin-name'})
|
42
|
+
page_cannot_be_destroyed
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
it "if refinery team deems it so" do
|
47
|
+
reset_page({:deletable => false})
|
48
|
+
page_cannot_be_destroyed
|
49
|
+
end
|
50
|
+
|
51
|
+
it "if menu_match is present" do
|
52
|
+
reset_page({:menu_match => '^/RSpec is great for testing too.*$'})
|
53
|
+
page_cannot_be_destroyed
|
54
|
+
end
|
55
|
+
|
56
|
+
it "unless you really want it to! >:]" do
|
57
|
+
reset_page
|
58
|
+
@page.destroy!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "page urls" do
|
63
|
+
it "should return a full path" do
|
64
|
+
@page.path.should == 'RSpec is great for testing too'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "and all of its parent page titles, reversed" do
|
68
|
+
create_child
|
69
|
+
@child.path.should == 'RSpec is great for testing too - The child page'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "or normally ;-)" do
|
73
|
+
create_child
|
74
|
+
@child.path(false).should == 'The child page - RSpec is great for testing too'
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return its url" do
|
78
|
+
@page.link_url = '/contact'
|
79
|
+
@page.url.should == '/contact'
|
80
|
+
|
81
|
+
reset_page
|
82
|
+
@page.url[:path].should == ["rspec-is-great-for-testing-too"]
|
83
|
+
@page.url[:id].should be_nil
|
84
|
+
|
85
|
+
turn_off_marketable_urls
|
86
|
+
@page.url[:id].should == "rspec-is-great-for-testing-too"
|
87
|
+
@page.url[:path].should be_nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "home page" do
|
92
|
+
it "should respond as the home page" do
|
93
|
+
@page.link_url = '/'
|
94
|
+
@page.home?.should == true
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should not respond as the home page" do
|
98
|
+
@page.home?.should == false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "content sections (page parts)" do
|
103
|
+
it "should return the content when using []" do
|
104
|
+
create_page_parts
|
105
|
+
|
106
|
+
@page[:body].should == "<p>I'm the first page part for this page.</p>"
|
107
|
+
@page["BoDY"].should == "<p>I'm the first page part for this page.</p>"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return all page part content" do
|
111
|
+
create_page_parts
|
112
|
+
|
113
|
+
@page.all_page_part_content.should == "<p>I'm the first page part for this page.</p> <p>Closely followed by the second page part.</p>"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should reposition correctly" do
|
117
|
+
create_page_parts
|
118
|
+
@page.parts.first.position = 6
|
119
|
+
@page.parts.last.position = 4
|
120
|
+
|
121
|
+
@page.parts.first.position.should == 6
|
122
|
+
@page.parts.last.position.should == 4
|
123
|
+
|
124
|
+
@page.reposition_parts!
|
125
|
+
|
126
|
+
@page.parts.first.position.should == 0
|
127
|
+
@page.parts.last.position.should == 1
|
128
|
+
end
|
8
129
|
end
|
9
130
|
|
10
|
-
|
11
|
-
|
131
|
+
context "draft pages" do
|
132
|
+
it "should not be a live page when set to draft" do
|
133
|
+
@page.draft = true
|
134
|
+
@page.live?.should == false
|
135
|
+
|
136
|
+
@page.draft = false
|
137
|
+
@page.live?.should == true
|
138
|
+
end
|
12
139
|
end
|
140
|
+
|
141
|
+
|
13
142
|
end
|
143
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
@files @files-manage
|
1
|
+
@refinerycms @files @files-manage @resources @resources-manage @manage
|
2
2
|
Feature: Manage Files
|
3
3
|
In order to control the content on my website
|
4
4
|
As an administrator
|
@@ -8,6 +8,7 @@ Feature: Manage Files
|
|
8
8
|
Given I am a logged in refinery user
|
9
9
|
And I have no files
|
10
10
|
|
11
|
+
@files-valid @valid
|
11
12
|
Scenario: Create Valid File
|
12
13
|
When I go to the list of files
|
13
14
|
And I follow "Upload New File"
|
@@ -16,6 +17,7 @@ Feature: Manage Files
|
|
16
17
|
Then the file "refinery_is_awesome.txt" should have uploaded successfully
|
17
18
|
And I should have 1 file
|
18
19
|
|
20
|
+
@files-edit @edit
|
19
21
|
Scenario: Edit Existing File
|
20
22
|
When I upload the file at "refinery_is_awesome.txt"
|
21
23
|
And I go to the list of files
|
@@ -25,12 +27,14 @@ Feature: Manage Files
|
|
25
27
|
Then the file "beach.jpeg" should have uploaded successfully
|
26
28
|
And I should have 1 file
|
27
29
|
|
30
|
+
@files-show @show
|
28
31
|
Scenario: Download Existing File
|
29
32
|
When I upload the file at "refinery_is_awesome.txt"
|
30
33
|
And I go to the list of files
|
31
34
|
And I follow "Download this file"
|
32
35
|
Then I should see "http://www.refineryhq.com/"
|
33
36
|
|
37
|
+
@files-delete @delete
|
34
38
|
Scenario: Files Delete
|
35
39
|
When I upload the file at "refinery_is_awesome.txt"
|
36
40
|
And I go to the list of files
|
@@ -3,7 +3,7 @@ Given /^I have no files$/ do
|
|
3
3
|
end
|
4
4
|
|
5
5
|
When /^I attach the file at "([^"]*)"$/ do |file_path|
|
6
|
-
attach_file('
|
6
|
+
attach_file('resource_file', File.join(File.expand_path('../../uploads/', __FILE__), file_path))
|
7
7
|
end
|
8
8
|
|
9
9
|
Then /^the file "([^"]*)" should have uploaded successfully$/ do |file_name|
|
@@ -16,6 +16,6 @@ end
|
|
16
16
|
|
17
17
|
When /^I upload the file at "([^"]*)"$/ do |file_path|
|
18
18
|
visit new_admin_resource_path
|
19
|
-
attach_file('
|
19
|
+
attach_file('resource_file', File.join(File.expand_path('../../uploads/', __FILE__), file_path))
|
20
20
|
click_button 'Save'
|
21
21
|
end
|
@@ -5,32 +5,8 @@ require 'refinery'
|
|
5
5
|
module Refinery
|
6
6
|
module Resources
|
7
7
|
class Engine < Rails::Engine
|
8
|
-
initializer 'fix-tempfile-not-closing-with-dragonfly-resources' do |app|
|
9
|
-
# see http://github.com/markevans/dragonfly/issues#issue/18/comment/415807
|
10
|
-
require 'tempfile'
|
11
|
-
class Tempfile
|
12
|
-
|
13
|
-
def unlink
|
14
|
-
# keep this order for thread safeness
|
15
|
-
begin
|
16
|
-
if File.exist?(@tmpname)
|
17
|
-
closed? or close
|
18
|
-
File.unlink(@tmpname)
|
19
|
-
end
|
20
|
-
@@cleanlist.delete(@tmpname)
|
21
|
-
@data = @tmpname = nil
|
22
|
-
ObjectSpace.undefine_finalizer(self)
|
23
|
-
rescue Errno::EACCES
|
24
|
-
# may not be able to unlink on Windows; just ignore
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
8
|
initializer 'resources-with-dragonfly' do |app|
|
32
9
|
app_resources = Dragonfly[:resources]
|
33
|
-
app_resources.configure_with(:rmagick)
|
34
10
|
app_resources.configure_with(:rails) do |c|
|
35
11
|
c.datastore.root_path = Rails.root.join('public', 'system', 'resources').to_s
|
36
12
|
c.url_path_prefix = '/system/resources'
|
@@ -44,20 +20,15 @@ module Refinery
|
|
44
20
|
app_resources.define_macro(ActiveRecord::Base, :resource_accessor)
|
45
21
|
app_resources.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)
|
46
22
|
|
47
|
-
# This
|
23
|
+
# This url_suffix makes it so that dragonfly urls work in traditional
|
48
24
|
# situations where the filename and extension are required, e.g. lightbox.
|
49
25
|
# What this does is takes the url that is about to be produced e.g.
|
50
|
-
# /system/
|
51
|
-
# and adds the filename onto the end (say the file was 'refinery_is_awesome.
|
52
|
-
# /system/
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if (fetcher = job.steps.detect{|s| s.class.step_name == :fetch}).present?
|
57
|
-
resource_url = ['', fetcher.uid.to_s.split('/').last].join('/')
|
58
|
-
end
|
59
|
-
"\#{super}\#{resource_url}"
|
60
|
-
end
|
26
|
+
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
|
27
|
+
# and adds the filename onto the end (say the file was 'refinery_is_awesome.pdf')
|
28
|
+
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.pdf
|
29
|
+
# Officially the way to do it, from: http://markevans.github.com/dragonfly/file.URLs.html
|
30
|
+
app_resources.url_suffix = proc{|job|
|
31
|
+
"/#{job.uid_basename}#{job.encoded_extname || job.uid_extname}"
|
61
32
|
}
|
62
33
|
|
63
34
|
### Extend active record ###
|
@@ -65,7 +36,7 @@ module Refinery
|
|
65
36
|
app.config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :resources, '/system/resources'
|
66
37
|
|
67
38
|
app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
|
68
|
-
:verbose =>
|
39
|
+
:verbose => Rails.env.development?,
|
69
40
|
:metastore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'meta')}",
|
70
41
|
:entitystore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'body')}"
|
71
42
|
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Resource do
|
4
|
+
|
5
|
+
def reset_resource(options = {})
|
6
|
+
@valid_attributes = {
|
7
|
+
:id => 1,
|
8
|
+
:file => File.new(File.expand_path('../../uploads/refinery_is_awesome.txt', __FILE__))
|
9
|
+
}.merge(options)
|
10
|
+
|
11
|
+
@resource.destroy if @resource
|
12
|
+
@resource = Resource.create!(@valid_attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
def resource_can_be_destroyed
|
16
|
+
@resource.destroy.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
reset_resource
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with valid attributes" do
|
24
|
+
it "should create successfully" do
|
25
|
+
@resource.errors.empty?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "resource url" do
|
30
|
+
it "should respond to .url" do
|
31
|
+
@resource.respond_to?(:url).should == true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not support thumbnailing like images do" do
|
35
|
+
@resource.respond_to?(:thumbnail).should == false
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should contain its filename at the end" do
|
39
|
+
@resource.url.should =~ %r{#{@resource.file_uid.split('/').last}$}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
http://www.refineryhq.com/
|
@@ -1,5 +1,10 @@
|
|
1
1
|
class RefinerySetting < ActiveRecord::Base
|
2
2
|
|
3
|
+
FORM_VALUE_TYPES = [
|
4
|
+
['Multi-line', 'text_area'],
|
5
|
+
['Checkbox', 'check_box']
|
6
|
+
]
|
7
|
+
|
3
8
|
validates :name, :presence => true
|
4
9
|
|
5
10
|
serialize :value # stores into YAML format
|
@@ -35,6 +40,7 @@ class RefinerySetting < ActiveRecord::Base
|
|
35
40
|
result = ensure_cache_exists!
|
36
41
|
|
37
42
|
if name.present?
|
43
|
+
scoping = scoping.to_s if scoping.is_a?(Symbol)
|
38
44
|
result = result.detect do |rs|
|
39
45
|
rs[:name] == name.to_s.downcase.to_sym and rs[:scoping] == scoping
|
40
46
|
end
|
@@ -70,19 +76,19 @@ class RefinerySetting < ActiveRecord::Base
|
|
70
76
|
end
|
71
77
|
|
72
78
|
def cache_key
|
73
|
-
|
79
|
+
[Refinery.base_cache_key, 'refinery_settings_cache'].join('_')
|
74
80
|
end
|
75
81
|
|
76
82
|
# find_or_set offers a convenient way to
|
77
83
|
def find_or_set(name, the_value, options={})
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
84
|
+
# Merge default options with supplied options.
|
85
|
+
options = {
|
86
|
+
:scoping => nil, :restricted => false,
|
87
|
+
:callback_proc_as_string => nil, :form_value_type => 'text_area'
|
88
|
+
}.merge(options)
|
83
89
|
|
84
90
|
# try to find the setting first
|
85
|
-
value =
|
91
|
+
value = get(name, :scoping => options[:scoping])
|
86
92
|
|
87
93
|
# if the setting's value is nil, store a new one using the existing functionality.
|
88
94
|
value = set(name, options.merge({:value => the_value})) if value.nil?
|
@@ -94,24 +100,27 @@ class RefinerySetting < ActiveRecord::Base
|
|
94
100
|
alias :get_or_set :find_or_set
|
95
101
|
|
96
102
|
# Retrieve the current value for the setting whose name is supplied.
|
97
|
-
def get(name)
|
98
|
-
|
103
|
+
def get(name, options = {})
|
104
|
+
options = {:scoping => nil}.update(options)
|
105
|
+
cache_read(name, options[:scoping])
|
99
106
|
end
|
100
107
|
|
101
108
|
alias :[] :get
|
102
109
|
|
103
110
|
def set(name, value)
|
104
|
-
scoping = (value.is_a?(Hash) and value.has_key?(:scoping))
|
111
|
+
scoping = (value[:scoping] if value.is_a?(Hash) and value.has_key?(:scoping))
|
105
112
|
setting = find_or_initialize_by_name_and_scoping(:name => name.to_s, :scoping => scoping)
|
106
113
|
|
107
114
|
# you could also pass in {:value => 'something', :scoping => 'somewhere'}
|
108
115
|
unless value.is_a?(Hash) and value.has_key?(:value)
|
109
116
|
setting.value = value
|
110
117
|
else
|
111
|
-
|
118
|
+
# set the value last, so that the other attributes can transform it if required.
|
119
|
+
setting.form_value_type = value[:form_value_type] || 'text_area' if setting.respond_to?(:form_value_type)
|
112
120
|
setting.scoping = value[:scoping] if value.has_key?(:scoping)
|
113
121
|
setting.callback_proc_as_string = value[:callback_proc_as_string] if value.has_key?(:callback_proc_as_string)
|
114
122
|
setting.destroyable = value[:destroyable] if value.has_key?(:destroyable)
|
123
|
+
setting.value = value[:value]
|
115
124
|
end
|
116
125
|
|
117
126
|
# Save because we're in a setter method.
|
@@ -154,8 +163,13 @@ class RefinerySetting < ActiveRecord::Base
|
|
154
163
|
end
|
155
164
|
|
156
165
|
def value=(new_value)
|
166
|
+
# must convert "1" to true and "0" to false when supplied using 'check_box', unfortunately.
|
167
|
+
if ["1", "0"].include?(new_value) and self.form_value_type == 'check_box'
|
168
|
+
new_value = new_value == "1" ? true : false
|
169
|
+
end
|
170
|
+
|
157
171
|
# must convert to string if true or false supplied otherwise it becomes 0 or 1, unfortunately.
|
158
|
-
if
|
172
|
+
if [true, false].include?(new_value)
|
159
173
|
new_value = new_value.to_s
|
160
174
|
end
|
161
175
|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RefinerySetting do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
RefinerySetting.set(:creating_from_scratch, nil)
|
7
|
+
RefinerySetting.set(:rspec_testing_creating_from_scratch, nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "set" do
|
11
|
+
it "should create a setting that didn't exist" do
|
12
|
+
RefinerySetting.get(:creating_from_scratch, :scoping => 'rspec_testing').should == nil
|
13
|
+
RefinerySetting.set(:creating_from_scratch, {:value => "Look, a value", :scoping => 'rspec_testing'}).should == "Look, a value"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should override an existing setting" do
|
17
|
+
@set = RefinerySetting.set(:creating_from_scratch, {:value => "a value", :scoping => 'rspec_testing'})
|
18
|
+
@set.should == "a value"
|
19
|
+
|
20
|
+
@new_set = RefinerySetting.set(:creating_from_scratch, {:value => "newer replaced value", :scoping => 'rspec_testing'})
|
21
|
+
@new_set.should == "newer replaced value"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should default to form_value_type text_area" do
|
25
|
+
@set = RefinerySetting.set(:creating_from_scratch, {:value => "a value", :scoping => 'rspec_testing'})
|
26
|
+
RefinerySetting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'}).form_value_type.should == "text_area"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should fix true as a value to 'true' (string)" do
|
30
|
+
@set = RefinerySetting.set(:creating_from_scratch, {:value => true, :scoping => 'rspec_testing'})
|
31
|
+
RefinerySetting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'})[:value].should == 'true'
|
32
|
+
@set.should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should fix false as a value to 'false' (string)" do
|
36
|
+
@set = RefinerySetting.set(:creating_from_scratch, {:value => false, :scoping => 'rspec_testing'})
|
37
|
+
RefinerySetting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'})[:value].should == 'false'
|
38
|
+
@set.should == false
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should fix '1' as a value with a check_box form_value_type to true" do
|
42
|
+
@set = RefinerySetting.set(:creating_from_scratch, {:value => "1", :scoping => 'rspec_testing', :form_value_type => 'check_box'})
|
43
|
+
RefinerySetting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'})[:value].should == 'true'
|
44
|
+
@set.should == true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should fix '0' as a value with a check_box form_value_type to false" do
|
48
|
+
@set = RefinerySetting.set(:creating_from_scratch, {:value => "0", :scoping => 'rspec_testing', :form_value_type => 'check_box'})
|
49
|
+
RefinerySetting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'})[:value].should == 'false'
|
50
|
+
@set.should == false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "get" do
|
55
|
+
it "should retrieve a seting that was created" do
|
56
|
+
@set = RefinerySetting.set(:creating_from_scratch, {:value => "some value", :scoping => 'rspec_testing'})
|
57
|
+
@set.should == 'some value'
|
58
|
+
|
59
|
+
@get = RefinerySetting.get(:creating_from_scratch, :scoping => 'rspec_testing')
|
60
|
+
@get.should == 'some value'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should also work with setting scoping using string and getting via symbol" do
|
64
|
+
@set = RefinerySetting.set(:creating_from_scratch, {:value => "some value", :scoping => 'rspec_testing'})
|
65
|
+
@set.should == 'some value'
|
66
|
+
|
67
|
+
@get = RefinerySetting.get(:creating_from_scratch, :scoping => :rspec_testing)
|
68
|
+
@get.should == 'some value'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should also work with setting scoping using symbol and getting via string" do
|
72
|
+
@set = RefinerySetting.set(:creating_from_scratch, {:value => "some value", :scoping => :rspec_testing})
|
73
|
+
@set.should == 'some value'
|
74
|
+
|
75
|
+
@get = RefinerySetting.get(:creating_from_scratch, :scoping => 'rspec_testing')
|
76
|
+
@get.should == 'some value'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "find_or_set" do
|
81
|
+
it "should create a non existant setting" do
|
82
|
+
@created = RefinerySetting.find_or_set(:creating_from_scratch, 'I am a setting being created', :scoping => 'rspec_testing')
|
83
|
+
|
84
|
+
@created.should == "I am a setting being created"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not override an existing setting" do
|
88
|
+
@created = RefinerySetting.set(:creating_from_scratch, {:value => 'I am a setting being created', :scoping => 'rspec_testing'})
|
89
|
+
@created.should == "I am a setting being created"
|
90
|
+
|
91
|
+
@find_or_set_created = RefinerySetting.find_or_set(:creating_from_scratch, 'Trying to change an existing value', :scoping => 'rspec_testing')
|
92
|
+
|
93
|
+
@created.should == "I am a setting being created"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should work without scoping" do
|
97
|
+
RefinerySetting.find_or_set(:rspec_testing_creating_from_scratch, 'Yes it worked').should == 'Yes it worked'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|