refinerycms-settings 1.0.11 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rspec +3 -0
- data/.travis.yml +16 -0
- data/Gemfile +74 -0
- data/Rakefile +19 -0
- data/app/controllers/refinery/admin/settings_controller.rb +55 -0
- data/app/decorators/controllers/refinery/.gitkeep +0 -0
- data/app/decorators/models/refinery/.gitkeep +0 -0
- data/app/helpers/refinery/admin/settings_helper.rb +29 -0
- data/app/models/refinery/setting.rb +204 -0
- data/app/views/refinery/admin/settings/_actions.html.erb +8 -0
- data/app/views/refinery/admin/settings/_form.html.erb +54 -0
- data/app/views/refinery/admin/settings/_records.html.erb +21 -0
- data/app/views/refinery/admin/settings/_setting.html.erb +23 -0
- data/app/views/refinery/admin/settings/_settings.html.erb +4 -0
- data/app/views/refinery/admin/settings/edit.html.erb +1 -0
- data/app/views/{admin/refinery_settings → refinery/admin/settings}/index.html.erb +2 -2
- data/app/views/refinery/admin/settings/new.html.erb +1 -0
- data/config/locales/bg.yml +22 -40
- data/config/locales/cs.yml +22 -39
- data/config/locales/da.yml +22 -40
- data/config/locales/de.yml +26 -43
- data/config/locales/el.yml +22 -40
- data/config/locales/en.yml +22 -35
- data/config/locales/es.yml +31 -63
- data/config/locales/fi.yml +22 -40
- data/config/locales/fr.yml +22 -38
- data/config/locales/it.yml +20 -36
- data/config/locales/ja.yml +30 -0
- data/config/locales/ko.yml +29 -0
- data/config/locales/lolcat.yml +21 -37
- data/config/locales/lt.yml +23 -40
- data/config/locales/lv.yml +22 -40
- data/config/locales/nb.yml +22 -40
- data/config/locales/nl.yml +22 -40
- data/config/locales/pl.yml +23 -40
- data/config/locales/pt-BR.yml +22 -38
- data/config/locales/rs.yml +22 -40
- data/config/locales/ru.yml +22 -37
- data/config/locales/sk.yml +22 -40
- data/config/locales/sl.yml +21 -20
- data/config/locales/sv.yml +22 -39
- data/config/locales/vi.yml +23 -42
- data/config/locales/zh-CN.yml +22 -40
- data/config/locales/zh-TW.yml +22 -40
- data/config/routes.rb +3 -6
- data/db/migrate/20100913234710_create_refinerycms_settings_schema.rb +11 -19
- data/lib/refinery/generators/refinery/settings/settings_generator.rb +20 -0
- data/lib/refinery/settings/engine.rb +26 -0
- data/lib/refinery/settings.rb +22 -0
- data/lib/refinerycms-settings.rb +1 -32
- data/readme.md +46 -0
- data/refinerycms-settings.gemspec +7 -79
- data/script/rails +6 -0
- data/spec/factories/settings.rb +5 -0
- data/spec/models/refinery/setting_spec.rb +103 -0
- data/spec/requests/refinery/admin/settings_spec.rb +57 -0
- data/spec/spec_helper.rb +56 -0
- data/tasks/rspec.rake +4 -0
- metadata +87 -75
- data/app/controllers/admin/refinery_settings_controller.rb +0 -71
- data/app/helpers/refinery_settings_helper.rb +0 -25
- data/app/models/refinery_setting.rb +0 -206
- data/app/views/admin/refinery_settings/_actions.html.erb +0 -15
- data/app/views/admin/refinery_settings/_form.html.erb +0 -62
- data/app/views/admin/refinery_settings/_records.html.erb +0 -21
- data/app/views/admin/refinery_settings/_refinery_setting.html.erb +0 -23
- data/app/views/admin/refinery_settings/_refinery_settings.html.erb +0 -5
- data/app/views/admin/refinery_settings/edit.html.erb +0 -1
- data/app/views/admin/refinery_settings/new.html.erb +0 -1
- data/config/locales/jp.yml +0 -47
- data/db/migrate/20100926142529_add_value_type_to_refinery_settings.rb +0 -9
- data/features/manage_refinery_settings.feature +0 -5
- data/features/step_definitions/setting_steps.rb +0 -9
- data/features/support/paths.rb +0 -14
- data/lib/gemspec.rb +0 -37
- data/lib/generators/refinerycms_settings_generator.rb +0 -8
- data/spec/models/refinery_setting_spec.rb +0 -101
data/config/locales/zh-TW.yml
CHANGED
@@ -1,47 +1,29 @@
|
|
1
1
|
zh-TW:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
analytics_page_code: 這個代碼可啟動 Google Analytics 來追蹤您的網站. 如果這項設定留白或是設為 UA-xxxxxx-x 表示為關閉這項功能並且不會有任何遠端的 Google Analytics 呼叫發生.
|
23
|
-
frontend_refinery_stylesheets_enabled: "在預設的情況, Refinery 包含了不影響您個人樣式表的預設 CSS 樣式表給前端使用, 可藉由這個設定來開啟或是關閉這個選項."
|
24
|
-
image_dialogue_sizes: 這個設定可以生效插入圖片的對話方框. 您必須完成不同大小的縮圖並且改變它.
|
25
|
-
image_thumbnails: 如果您修改了這個選項, 您必須執行 rake images:regenerate (或是 rake image:update, 如果您只是增加了更多縮圖), 否則這個設定將不會影響任何已存在網站上的圖片.
|
26
|
-
menu_hide_children: 從選單中隱藏任何次頁面, 即使它們是存在的.
|
27
|
-
new_page_parts: 開啟在頁面編輯器可新增新頁面區塊 (內容區) 的功能.
|
28
|
-
page_title: 提供非常複雜的選項讓您設定頁面標題. 在這裡你可以設定自訂的 CSS 類別或是不同的標籤, 或是加上紀錄著頁面層級關係的導覽列.
|
29
|
-
pages_advanced_options_include_seo: 這可控制是否 SEO 選項會顯示在頁面上的進階選項中.
|
30
|
-
preferred_image_view: 這可控制圖片插件如何呈現目前這些已存在網站上的圖片 - grid 表示 '格狀模式' 以及 list 表示 '列表模式'. 圖片插件本身提供一個按鈕可以自動切換這些模式.
|
31
|
-
refinery_enable_backend_reordering: 您可以移除可以重新排列插件顯示順序的功能.
|
32
|
-
refinery_menu_cache_action_suffix: 這可控制用來使用在快取網站選單的金鑰. 如果您正在使用佈景主題, 那最不要改變預設值, 讓佈景主題來為您處裡.
|
33
|
-
show_contact_privacy_link: 您可以隱藏或是顯示在聯絡人表單確認按鈕旁的隱私條款頁面連結.
|
34
|
-
site_name: 這是您的網站名稱, 它將會顯示在網站標題, Refinery 的後台管理系統, 以及部份有頁尾版權宣告的佈景主題中.
|
35
|
-
theme: 輸入您想要開啟的佈景主題名稱. 它將會馬上生效並且確認為是有效的名稱.
|
36
|
-
use_google_ajax_libraries: 如果您想要使用 Google 的 AJAX CDN 請設定為 true.
|
37
|
-
use_marketable_urls: 將網址從 /pages/about 改變為 /about 並且自動處理與其他插件的衝突.
|
38
|
-
use_resource_caching: 建議在 production 模式中開啟這個選項, 它會將 javascript assets 與樣式表 assets 包裹成一個單一檔案來減少您網站被請求的次數並且達到加速的效果.
|
39
|
-
approximate_ascii: 如果您使用帶有口音或是變音符號的拉丁字母請設定為 true. 它會將像是 ā, č, ž 的字母轉為 a, c, z , 在某些網頁瀏覽器中, 這些字母就不會奇怪地出現在網址列上.
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
refinery_settings:
|
5
|
+
title: 設定
|
6
|
+
description: 管理 Refinery 設定值
|
7
|
+
admin:
|
8
|
+
settings:
|
9
|
+
delete: 永遠地移除這項設定值
|
10
|
+
edit: 編輯這項設定值
|
11
|
+
actions:
|
12
|
+
new: 增加新設定值
|
13
|
+
records:
|
14
|
+
empty_set: 目前沒有任何設定值.
|
15
|
+
create_first: "請按這兒 '%{link}' 加入您的第一個設定值."
|
16
|
+
form:
|
17
|
+
enabled: "是的, 啟動這項設定值."
|
18
|
+
restart_may_be_in_order_html: <strong>請注意</strong> 您必須重新啟動這個網站來讓設定值生效.
|
19
|
+
yes_make_this_setting_restricted: "是的, 讓這項設定只能被管理者修改."
|
20
|
+
help:
|
21
|
+
restricted: 這讓這項設定只能給有管理者權限的使用者 (像您一樣) 看見以及編輯.
|
40
22
|
activerecord:
|
41
23
|
models:
|
42
|
-
|
24
|
+
refinery/setting: 設定
|
43
25
|
attributes:
|
44
|
-
|
26
|
+
refinery/setting:
|
45
27
|
name: 名稱
|
46
28
|
value: 設定值
|
47
29
|
restricted: 限制
|
data/config/routes.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
resources :settings,
|
4
|
-
:except => :show,
|
5
|
-
:as => :refinery_settings,
|
6
|
-
:controller => :refinery_settings
|
1
|
+
Refinery::Core::Engine.routes.draw do
|
2
|
+
namespace :admin, :path => 'refinery' do
|
3
|
+
resources :settings, :except => :show
|
7
4
|
end
|
8
5
|
end
|
@@ -1,24 +1,16 @@
|
|
1
1
|
class CreateRefinerycmsSettingsSchema < ActiveRecord::Migration
|
2
|
-
def
|
3
|
-
create_table
|
4
|
-
t.string
|
5
|
-
t.text
|
6
|
-
t.boolean
|
7
|
-
t.
|
8
|
-
t.
|
9
|
-
t.string
|
10
|
-
t.boolean "restricted", :default => false
|
11
|
-
t.string "callback_proc_as_string"
|
12
|
-
end
|
13
|
-
|
14
|
-
add_index ::RefinerySetting.table_name, ["name"], :name => "index_#{::RefinerySetting.table_name}_on_name"
|
15
|
-
end
|
2
|
+
def change
|
3
|
+
create_table :refinery_settings do |t|
|
4
|
+
t.string :name
|
5
|
+
t.text :value
|
6
|
+
t.boolean :destroyable, :default => true
|
7
|
+
t.string :scoping
|
8
|
+
t.boolean :restricted, :default => false
|
9
|
+
t.string :form_value_type
|
16
10
|
|
17
|
-
|
18
|
-
[::RefinerySetting].reject{|m|
|
19
|
-
!(defined?(m) and m.respond_to?(:table_name))
|
20
|
-
}.each do |model|
|
21
|
-
drop_table model.table_name
|
11
|
+
t.timestamps
|
22
12
|
end
|
13
|
+
|
14
|
+
add_index :refinery_settings, :name
|
23
15
|
end
|
24
16
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Refinery
|
2
|
+
class SettingsGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
def rake_db
|
5
|
+
rake("refinery_settings:install:migrations")
|
6
|
+
end
|
7
|
+
|
8
|
+
def append_load_seed_data
|
9
|
+
create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
|
10
|
+
append_file 'db/seeds.rb', :verbose => true do
|
11
|
+
<<-EOH
|
12
|
+
|
13
|
+
# Added by Refinery CMS Settings engine
|
14
|
+
Refinery::Settings::Engine.load_seed
|
15
|
+
EOH
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Settings
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
include Refinery::Engine
|
5
|
+
|
6
|
+
isolate_namespace Refinery
|
7
|
+
engine_name :refinery_settings
|
8
|
+
|
9
|
+
config.autoload_paths += %W( #{config.root}/lib )
|
10
|
+
|
11
|
+
initializer "register refinery_settings plugin" do
|
12
|
+
Refinery::Plugin.register do |plugin|
|
13
|
+
plugin.pathname = root
|
14
|
+
plugin.name = 'refinery_settings'
|
15
|
+
plugin.version = %q{2.0.0}
|
16
|
+
plugin.menu_match = %r{refinery/settings$}
|
17
|
+
plugin.url = { :controller => '/refinery/admin/settings' }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
config.after_initialize do
|
22
|
+
Refinery.register_engine(Refinery::Settings)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'refinerycms-core'
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
autoload :SettingsGenerator, 'generators/refinery/settings/settings_generator'
|
5
|
+
|
6
|
+
module Settings
|
7
|
+
|
8
|
+
require 'refinery/settings/engine'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_writer :root
|
12
|
+
|
13
|
+
def root
|
14
|
+
@root ||= Pathname.new(File.expand_path('../../../', __FILE__))
|
15
|
+
end
|
16
|
+
|
17
|
+
def factory_paths
|
18
|
+
@factory_paths ||= [ root.join('spec/factories').to_s ]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/refinerycms-settings.rb
CHANGED
@@ -1,32 +1 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
module Refinery
|
4
|
-
module Settings
|
5
|
-
|
6
|
-
class << self
|
7
|
-
attr_accessor :root
|
8
|
-
def root
|
9
|
-
@root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Engine < ::Rails::Engine
|
14
|
-
|
15
|
-
initializer 'serve static assets' do |app|
|
16
|
-
app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
|
17
|
-
end
|
18
|
-
|
19
|
-
config.after_initialize do
|
20
|
-
::Refinery::Plugin.register do |plugin|
|
21
|
-
plugin.pathname = root
|
22
|
-
plugin.name = 'refinery_settings'
|
23
|
-
plugin.url = {:controller => '/admin/refinery_settings'}
|
24
|
-
plugin.version = %q{1.0.0}
|
25
|
-
plugin.menu_match = /(refinery|admin)\/(refinery_)?settings$/
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
::Refinery.engines << 'settings'
|
1
|
+
require 'refinery/settings'
|
data/readme.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Settings
|
2
|
+
|
3
|
+
![Refinery Settings](http://refinerycms.com/system/images/0000/0666/settings.png)
|
4
|
+
|
5
|
+
## About
|
6
|
+
|
7
|
+
Refinery Settings was extracted from Refinery CMS just before 2.0.0 was released
|
8
|
+
and can now be used separately.
|
9
|
+
|
10
|
+
## How do I Make my Own Settings?
|
11
|
+
|
12
|
+
### In view
|
13
|
+
|
14
|
+
Settings can be really useful, especially when you have custom display logic or
|
15
|
+
new plugins that need to behave in different ways.
|
16
|
+
|
17
|
+
To best explain how settings work, let's use an example. Say you have a client
|
18
|
+
who has a display in a local trade show every year and 2 months before the trade
|
19
|
+
show, they want to display a little banner in the header of all pages.
|
20
|
+
|
21
|
+
Once the trade show is finished, the client needs to be able to hide it again
|
22
|
+
until next year. This is what your ``application.html.erb`` file might look like:
|
23
|
+
|
24
|
+
...
|
25
|
+
<div id='header'>
|
26
|
+
<h1>My Company</h1>
|
27
|
+
|
28
|
+
<% if ::Refinery::Setting.find_or_set(:show_trade_show_banner, false) %>
|
29
|
+
<%= image_tag ('trade-show-banner.jpg') %>
|
30
|
+
<% end %>
|
31
|
+
</div>
|
32
|
+
...
|
33
|
+
|
34
|
+
The following will automatically create a new Refinery setting called
|
35
|
+
"show_trade_show_banner" and set its default to ``false``.
|
36
|
+
If that setting already exists, it just reads in what the current value is.
|
37
|
+
|
38
|
+
So as you can see, this is quite clever because you can quickly define new settings
|
39
|
+
and their defaults right from the view as you need them.
|
40
|
+
|
41
|
+
This setting would then show up in the backend in the 'Settings' area where the
|
42
|
+
client could change the value as their trade show approaches. Easy as pie!
|
43
|
+
|
44
|
+
### In Controller
|
45
|
+
|
46
|
+
limit = Refinery::Setting.find_or_set(:list_limit, 20)
|
@@ -1,92 +1,20 @@
|
|
1
1
|
# Encoding: UTF-8
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY! Instead, use lib/gemspec.rb to generate it.
|
3
2
|
|
4
3
|
Gem::Specification.new do |s|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
5
|
s.name = %q{refinerycms-settings}
|
6
|
-
s.version = %q{
|
6
|
+
s.version = %q{2.0.0}
|
7
7
|
s.summary = %q{Settings engine for Refinery CMS}
|
8
|
-
s.description = %q{
|
9
|
-
s.date = %q{2012-05-18}
|
8
|
+
s.description = %q{Adds programmer creatable, user editable settings.}
|
10
9
|
s.email = %q{info@refinerycms.com}
|
11
10
|
s.homepage = %q{http://refinerycms.com}
|
12
11
|
s.rubyforge_project = %q{refinerycms}
|
13
|
-
s.authors = ['
|
12
|
+
s.authors = ['Philip Arndt', 'Uģis Ozols']
|
14
13
|
s.license = %q{MIT}
|
15
14
|
s.require_paths = %w(lib)
|
16
|
-
s.executables = %w()
|
17
15
|
|
18
|
-
s.
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
19
18
|
|
20
|
-
s.
|
21
|
-
'app',
|
22
|
-
'app/controllers',
|
23
|
-
'app/controllers/admin',
|
24
|
-
'app/controllers/admin/refinery_settings_controller.rb',
|
25
|
-
'app/helpers',
|
26
|
-
'app/helpers/refinery_settings_helper.rb',
|
27
|
-
'app/models',
|
28
|
-
'app/models/refinery_setting.rb',
|
29
|
-
'app/views',
|
30
|
-
'app/views/admin',
|
31
|
-
'app/views/admin/refinery_settings',
|
32
|
-
'app/views/admin/refinery_settings/_actions.html.erb',
|
33
|
-
'app/views/admin/refinery_settings/_form.html.erb',
|
34
|
-
'app/views/admin/refinery_settings/_records.html.erb',
|
35
|
-
'app/views/admin/refinery_settings/_refinery_setting.html.erb',
|
36
|
-
'app/views/admin/refinery_settings/_refinery_settings.html.erb',
|
37
|
-
'app/views/admin/refinery_settings/edit.html.erb',
|
38
|
-
'app/views/admin/refinery_settings/index.html.erb',
|
39
|
-
'app/views/admin/refinery_settings/new.html.erb',
|
40
|
-
'config',
|
41
|
-
'config/locales',
|
42
|
-
'config/locales/bg.yml',
|
43
|
-
'config/locales/cs.yml',
|
44
|
-
'config/locales/da.yml',
|
45
|
-
'config/locales/de.yml',
|
46
|
-
'config/locales/el.yml',
|
47
|
-
'config/locales/en.yml',
|
48
|
-
'config/locales/es.yml',
|
49
|
-
'config/locales/fi.yml',
|
50
|
-
'config/locales/fr.yml',
|
51
|
-
'config/locales/it.yml',
|
52
|
-
'config/locales/jp.yml',
|
53
|
-
'config/locales/lolcat.yml',
|
54
|
-
'config/locales/lt.yml',
|
55
|
-
'config/locales/lv.yml',
|
56
|
-
'config/locales/nb.yml',
|
57
|
-
'config/locales/nl.yml',
|
58
|
-
'config/locales/pl.yml',
|
59
|
-
'config/locales/pt-BR.yml',
|
60
|
-
'config/locales/rs.yml',
|
61
|
-
'config/locales/ru.yml',
|
62
|
-
'config/locales/sk.yml',
|
63
|
-
'config/locales/sl.yml',
|
64
|
-
'config/locales/sv.yml',
|
65
|
-
'config/locales/vi.yml',
|
66
|
-
'config/locales/zh-CN.yml',
|
67
|
-
'config/locales/zh-TW.yml',
|
68
|
-
'config/routes.rb',
|
69
|
-
'db',
|
70
|
-
'db/migrate',
|
71
|
-
'db/migrate/20100913234710_create_refinerycms_settings_schema.rb',
|
72
|
-
'db/migrate/20100926142529_add_value_type_to_refinery_settings.rb',
|
73
|
-
'features',
|
74
|
-
'features/manage_refinery_settings.feature',
|
75
|
-
'features/step_definitions',
|
76
|
-
'features/step_definitions/setting_steps.rb',
|
77
|
-
'features/support',
|
78
|
-
'features/support/paths.rb',
|
79
|
-
'lib',
|
80
|
-
'lib/gemspec.rb',
|
81
|
-
'lib/generators',
|
82
|
-
'lib/generators/refinerycms_settings_generator.rb',
|
83
|
-
'lib/refinerycms-settings.rb',
|
84
|
-
'license.md',
|
85
|
-
'refinerycms-settings.gemspec',
|
86
|
-
'spec',
|
87
|
-
'spec/models',
|
88
|
-
'spec/models/refinery_setting_spec.rb'
|
89
|
-
]
|
90
|
-
|
91
|
-
s.add_dependency 'refinerycms-base', '= 1.0.11'
|
19
|
+
s.add_dependency 'refinerycms-core', '2.0.0'
|
92
20
|
end
|
data/script/rails
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_PATH = File.expand_path('../..', __FILE__)
|
6
|
+
load File.expand_path('../../spec/dummy/script/rails', __FILE__)
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
describe Setting do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
::Refinery::Setting.set(:creating_from_scratch, nil)
|
8
|
+
::Refinery::Setting.set(:rspec_testing_creating_from_scratch, nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "set" do
|
12
|
+
it "should create a setting that didn't exist" do
|
13
|
+
::Refinery::Setting.get(:creating_from_scratch, :scoping => 'rspec_testing').should eq(nil)
|
14
|
+
::Refinery::Setting.set(:creating_from_scratch, {:value => "Look, a value", :scoping => 'rspec_testing'}).should eq("Look, a value")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should override an existing setting" do
|
18
|
+
@set = ::Refinery::Setting.set(:creating_from_scratch, {:value => "a value", :scoping => 'rspec_testing'})
|
19
|
+
@set.should eq("a value")
|
20
|
+
|
21
|
+
@new_set = ::Refinery::Setting.set(:creating_from_scratch, {:value => "newer replaced value", :scoping => 'rspec_testing'})
|
22
|
+
@new_set.should eq("newer replaced value")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should default to form_value_type text_area" do
|
26
|
+
@set = ::Refinery::Setting.set(:creating_from_scratch, {:value => "a value", :scoping => 'rspec_testing'})
|
27
|
+
::Refinery::Setting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'}).form_value_type.should eq("text_area")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should fix true as a value to 'true' (string)" do
|
31
|
+
@set = ::Refinery::Setting.set(:creating_from_scratch, {:value => true, :scoping => 'rspec_testing'})
|
32
|
+
::Refinery::Setting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'})[:value].should eq('true')
|
33
|
+
@set.should eq(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should fix false as a value to 'false' (string)" do
|
37
|
+
@set = ::Refinery::Setting.set(:creating_from_scratch, {:value => false, :scoping => 'rspec_testing'})
|
38
|
+
::Refinery::Setting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'})[:value].should eq('false')
|
39
|
+
@set.should eq(false)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should fix '1' as a value with a check_box form_value_type to true" do
|
43
|
+
@set = ::Refinery::Setting.set(:creating_from_scratch, {:value => "1", :scoping => 'rspec_testing', :form_value_type => 'check_box'})
|
44
|
+
::Refinery::Setting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'})[:value].should eq('true')
|
45
|
+
@set.should eq(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should fix '0' as a value with a check_box form_value_type to false" do
|
49
|
+
@set = ::Refinery::Setting.set(:creating_from_scratch, {:value => "0", :scoping => 'rspec_testing', :form_value_type => 'check_box'})
|
50
|
+
::Refinery::Setting.find_by_name(:creating_from_scratch.to_s, :conditions => {:scoping => 'rspec_testing'})[:value].should eq('false')
|
51
|
+
@set.should eq(false)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "get" do
|
56
|
+
it "should retrieve a seting that was created" do
|
57
|
+
@set = ::Refinery::Setting.set(:creating_from_scratch, {:value => "some value", :scoping => 'rspec_testing'})
|
58
|
+
@set.should eq('some value')
|
59
|
+
|
60
|
+
@get = ::Refinery::Setting.get(:creating_from_scratch, :scoping => 'rspec_testing')
|
61
|
+
@get.should eq('some value')
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should also work with setting scoping using string and getting via symbol" do
|
65
|
+
@set = ::Refinery::Setting.set(:creating_from_scratch, {:value => "some value", :scoping => 'rspec_testing'})
|
66
|
+
@set.should eq('some value')
|
67
|
+
|
68
|
+
@get = ::Refinery::Setting.get(:creating_from_scratch, :scoping => :rspec_testing)
|
69
|
+
@get.should eq('some value')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should also work with setting scoping using symbol and getting via string" do
|
73
|
+
@set = ::Refinery::Setting.set(:creating_from_scratch, {:value => "some value", :scoping => :rspec_testing})
|
74
|
+
@set.should eq('some value')
|
75
|
+
|
76
|
+
@get = ::Refinery::Setting.get(:creating_from_scratch, :scoping => 'rspec_testing')
|
77
|
+
@get.should eq('some value')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "find_or_set" do
|
82
|
+
it "should create a non existant setting" do
|
83
|
+
@created = ::Refinery::Setting.find_or_set(:creating_from_scratch, 'I am a setting being created', :scoping => 'rspec_testing')
|
84
|
+
|
85
|
+
@created.should eq("I am a setting being created")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should not override an existing setting" do
|
89
|
+
@created = ::Refinery::Setting.set(:creating_from_scratch, {:value => 'I am a setting being created', :scoping => 'rspec_testing'})
|
90
|
+
@created.should eq("I am a setting being created")
|
91
|
+
|
92
|
+
@find_or_set_created = ::Refinery::Setting.find_or_set(:creating_from_scratch, 'Trying to change an existing value', :scoping => 'rspec_testing')
|
93
|
+
|
94
|
+
@created.should eq("I am a setting being created")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should work without scoping" do
|
98
|
+
::Refinery::Setting.find_or_set(:rspec_testing_creating_from_scratch, 'Yes it worked').should eq('Yes it worked')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
module Admin
|
5
|
+
describe "Settings" do
|
6
|
+
login_refinery_user
|
7
|
+
|
8
|
+
context "when no settings" do
|
9
|
+
before(:each) { Refinery::Setting.destroy_all }
|
10
|
+
|
11
|
+
it "invites to create one" do
|
12
|
+
visit refinery.admin_settings_path
|
13
|
+
page.should have_content("There are no settings yet. Click 'Add new setting' to add your first setting.")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "shows add new setting link" do
|
18
|
+
visit refinery.admin_settings_path
|
19
|
+
page.should have_content("Add new setting")
|
20
|
+
page.should have_selector("a[href*='/refinery/settings/new']")
|
21
|
+
end
|
22
|
+
|
23
|
+
context "new/create" do
|
24
|
+
it "adds setting", :js => true do
|
25
|
+
visit refinery.admin_settings_path
|
26
|
+
click_link "Add new setting"
|
27
|
+
|
28
|
+
page.should have_selector('iframe#dialog_iframe')
|
29
|
+
|
30
|
+
page.within_frame('dialog_iframe') do
|
31
|
+
fill_in "Name", :with => "test setting"
|
32
|
+
fill_in "Value", :with => "true"
|
33
|
+
|
34
|
+
click_button "Save"
|
35
|
+
end
|
36
|
+
|
37
|
+
page.should have_content("'Test Setting' was successfully added.")
|
38
|
+
page.should have_content("Test Setting - true")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "pagination" do
|
43
|
+
before(:each) do
|
44
|
+
(Refinery::Setting.per_page + 1).times do
|
45
|
+
FactoryGirl.create(:setting)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
specify "page links" do
|
50
|
+
visit refinery.admin_settings_path
|
51
|
+
|
52
|
+
page.should have_selector("a[href*='settings?page=2']")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
def setup_environment
|
4
|
+
# Configure Rails Environment
|
5
|
+
ENV["RAILS_ENV"] ||= 'test'
|
6
|
+
|
7
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
8
|
+
|
9
|
+
require 'rspec/rails'
|
10
|
+
require 'capybara/rspec'
|
11
|
+
require 'factory_girl_rails'
|
12
|
+
|
13
|
+
Rails.backtrace_cleaner.remove_silencers!
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.mock_with :rspec
|
17
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
18
|
+
config.filter_run :focus => true
|
19
|
+
config.run_all_when_everything_filtered = true
|
20
|
+
end
|
21
|
+
|
22
|
+
# set javascript driver for capybara
|
23
|
+
Capybara.javascript_driver = :selenium
|
24
|
+
end
|
25
|
+
|
26
|
+
def each_run
|
27
|
+
ActiveSupport::Dependencies.clear
|
28
|
+
|
29
|
+
FactoryGirl.reload
|
30
|
+
|
31
|
+
# Requires supporting files with custom matchers and macros, etc,
|
32
|
+
# in ./support/ and its subdirectories including factories.
|
33
|
+
([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p|
|
34
|
+
Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
|
35
|
+
}.flatten.sort.each do |support_file|
|
36
|
+
require support_file
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# If spork is available in the Gemfile it'll be used but we don't force it.
|
41
|
+
unless (begin; require 'spork'; rescue LoadError; nil end).nil?
|
42
|
+
Spork.prefork do
|
43
|
+
# Loading more in this block will cause your tests to run faster. However,
|
44
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
45
|
+
# need to restart spork for it take effect.
|
46
|
+
setup_environment
|
47
|
+
end
|
48
|
+
|
49
|
+
Spork.each_run do
|
50
|
+
# This code will be run each time you run your specs.
|
51
|
+
each_run
|
52
|
+
end
|
53
|
+
else
|
54
|
+
setup_environment
|
55
|
+
each_run
|
56
|
+
end
|
data/tasks/rspec.rake
ADDED