alchemy_cms 2.6.1 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/app/controllers/alchemy/admin/pictures_controller.rb +1 -1
- data/app/helpers/alchemy/pages_helper.rb +1 -1
- data/app/mailers/alchemy/notifications.rb +9 -6
- data/app/sweepers/alchemy/pictures_sweeper.rb +1 -1
- data/app/views/alchemy/essences/_essence_text_view.html.erb +5 -3
- data/app/views/alchemy/notifications/registered_user_created.de.text.erb +1 -1
- data/app/views/alchemy/notifications/registered_user_created.en.text.erb +1 -1
- data/config/locales/alchemy.de.yml +2 -6
- data/config/locales/alchemy.en.yml +0 -6
- data/config/routes.rb +1 -1
- data/lib/alchemy/mount_point.rb +36 -11
- data/lib/alchemy/seeder.rb +8 -36
- data/lib/alchemy/shell.rb +80 -0
- data/lib/alchemy/upgrader.rb +36 -36
- data/lib/alchemy/upgrader/two_point_five.rb +79 -0
- data/lib/alchemy/upgrader/two_point_four.rb +25 -0
- data/lib/alchemy/upgrader/two_point_one.rb +95 -0
- data/lib/alchemy/upgrader/two_point_six.rb +32 -0
- data/lib/alchemy/upgrader/two_point_three.rb +25 -0
- data/lib/alchemy/upgrader/two_point_two.rb +69 -0
- data/lib/alchemy/upgrader/two_point_zero.rb +13 -0
- data/lib/alchemy/version.rb +1 -1
- data/lib/tasks/alchemy/upgrade.rake +1 -1
- data/spec/libraries/mount_point_spec.rb +62 -0
- data/spec/libraries/shell_spec.rb +123 -0
- data/spec/mailers/notifications_spec.rb +67 -0
- metadata +41 -79
@@ -0,0 +1,79 @@
|
|
1
|
+
module Alchemy
|
2
|
+
module Upgrader::TwoPointFive
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def convert_picture_storage
|
7
|
+
desc "Convert the picture storage"
|
8
|
+
converted_images = []
|
9
|
+
images = Dir.glob Rails.root.join 'uploads/pictures/**/*.*'
|
10
|
+
if images.blank?
|
11
|
+
log "No pictures found", :skip
|
12
|
+
else
|
13
|
+
images.each do |image|
|
14
|
+
image_uid = image.gsub(/#{Rails.root.to_s}\/uploads\/pictures\//, '')
|
15
|
+
image_id = image_uid.split('/').last.split('.').first
|
16
|
+
picture = Alchemy::Picture.find_by_id(image_id)
|
17
|
+
if picture && picture.image_file_uid.blank?
|
18
|
+
picture.image_file_uid = image_uid
|
19
|
+
picture.image_file_size = File.new(image).size
|
20
|
+
if picture.save!
|
21
|
+
log "Converted #{image_uid}"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
log "Picture with id #{image_id} not found or already converted.", :skip
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def removed_standard_set_notice
|
31
|
+
warn = <<-WARN
|
32
|
+
We removed the standard set from Alchemy core!
|
33
|
+
In order to get the standard set back, install the `alchemy-demo_kit` gem.
|
34
|
+
WARN
|
35
|
+
todo warn
|
36
|
+
end
|
37
|
+
|
38
|
+
def renamed_t_method
|
39
|
+
warn = <<-WARN
|
40
|
+
We renamed alchemy's `t` method override into `_t` to avoid conflicts with Rails own t method!
|
41
|
+
If you use the `t` method to translate alchemy scoped keys, then you have to use the `_t` method from now on.
|
42
|
+
WARN
|
43
|
+
todo warn
|
44
|
+
end
|
45
|
+
|
46
|
+
def migrated_to_devise
|
47
|
+
warn = <<-WARN
|
48
|
+
We changed the authentication provider from Authlogic to Devise.
|
49
|
+
|
50
|
+
If you are upgrading from an old Alchemy version < 2.5.0, then you have to make changes to your Devise configuration.
|
51
|
+
|
52
|
+
1. Run:
|
53
|
+
|
54
|
+
$ rails g alchemy:devise
|
55
|
+
|
56
|
+
And alter the encryptor to authlogic_sha512
|
57
|
+
and the stretches value from 10 to 20
|
58
|
+
|
59
|
+
# config/initializers/devise.rb
|
60
|
+
config.stretches = Rails.env.test? ? 1 : 20
|
61
|
+
config.encryptor = :authlogic_sha512
|
62
|
+
|
63
|
+
2. Add the encryptable module to your Alchemy config.yml:
|
64
|
+
|
65
|
+
# config/alchemy/config.yml
|
66
|
+
devise_modules:
|
67
|
+
- :database_authenticatable
|
68
|
+
- :trackable
|
69
|
+
- :validatable
|
70
|
+
- :timeoutable
|
71
|
+
- :recoverable
|
72
|
+
- :encryptable
|
73
|
+
|
74
|
+
WARN
|
75
|
+
todo warn
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Alchemy
|
2
|
+
module Upgrader::TwoPointFour
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def removed_richmedia_essences_notice
|
7
|
+
warn = <<-WARN
|
8
|
+
We removed the EssenceAudio, EssenceFlash and EssenceVideo essences from Alchemy core!
|
9
|
+
|
10
|
+
In order to get the essences back, install the `alchemy-richmedia-essences` gem.
|
11
|
+
|
12
|
+
gem 'alchemy-richmedia-essences'
|
13
|
+
|
14
|
+
We left the tables in your database, you can simply drop them if you don't use these essences in your project.
|
15
|
+
|
16
|
+
drop_table :alchemy_essence_audios
|
17
|
+
drop_table :alchemy_essence_flashes
|
18
|
+
drop_table :alchemy_essence_videos
|
19
|
+
|
20
|
+
WARN
|
21
|
+
todo warn
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Alchemy
|
2
|
+
module Upgrader::TwoPointOne
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
# Creates Language model if it does not exist (Alchemy CMS prior v1.5)
|
7
|
+
# Also creates missing associations between pages and languages
|
8
|
+
def upgrade_to_language
|
9
|
+
desc "Creating languages for pages"
|
10
|
+
Alchemy::Page.all.each do |page|
|
11
|
+
if !page.language_code.blank? && page.language.nil?
|
12
|
+
root = page.get_language_root
|
13
|
+
lang = Alchemy::Language.find_or_create_by_language_code(
|
14
|
+
:name => page.language_code.capitalize,
|
15
|
+
:language_code => page.language_code,
|
16
|
+
:frontpage_name => root.name,
|
17
|
+
:page_layout => root.page_layout,
|
18
|
+
:public => true
|
19
|
+
)
|
20
|
+
page.language = lang
|
21
|
+
if page.save(:validate => false)
|
22
|
+
log "Set language for page #{page.name} to #{lang.name}."
|
23
|
+
end
|
24
|
+
else
|
25
|
+
log("Language for page #{page.name} already set.", :skip)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def upgrade_layoutpages
|
31
|
+
desc "Setting language of layoutpages"
|
32
|
+
default_language = Alchemy::Language.get_default
|
33
|
+
raise "No default language found." if default_language.nil?
|
34
|
+
layoutpages = Alchemy::Page.layoutpages
|
35
|
+
if layoutpages.any?
|
36
|
+
layoutpages.each do |page|
|
37
|
+
if page.language.class == String || page.language.nil?
|
38
|
+
page.language = default_language
|
39
|
+
if page.save(:validate => false)
|
40
|
+
log "Set language for page #{page.name} to #{default_language.name}."
|
41
|
+
end
|
42
|
+
else
|
43
|
+
log "Language for page #{page.name} already set.", :skip
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
log "No layoutpages found.", :skip
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def upgrade_essence_link_target_default
|
52
|
+
desc "Setting new link_target default"
|
53
|
+
essences = (Alchemy::EssencePicture.all + Alchemy::EssenceText.all)
|
54
|
+
if essences.any?
|
55
|
+
essences.each do |essence|
|
56
|
+
case essence.link_target
|
57
|
+
when '1'
|
58
|
+
if essence.update_attribute(:link_target, 'blank')
|
59
|
+
log("Updated #{essence.preview_text} link target to #{essence.link_target}.")
|
60
|
+
end
|
61
|
+
when '0'
|
62
|
+
essence.update_attribute(:link_target, nil)
|
63
|
+
log("Updated #{essence.preview_text} link target to #{essence.link_target.inspect}.")
|
64
|
+
else
|
65
|
+
log("#{essence.preview_text} already upgraded.", :skip)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
else
|
69
|
+
log("No essences to upgrade found.", :skip)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Updates all essence_type of Content if not already namespaced.
|
74
|
+
def upgrade_to_namespaced_essence_type
|
75
|
+
desc "Namespacing essence_type columns"
|
76
|
+
depricated_contents = Alchemy::Content.where("essence_type LIKE ?", "Essence%")
|
77
|
+
if depricated_contents.any?
|
78
|
+
success = 0
|
79
|
+
errors = []
|
80
|
+
depricated_contents.each do |c|
|
81
|
+
if c.update_attribute(:essence_type, c.essence_type.gsub(/^Essence/, 'Alchemy::Essence'))
|
82
|
+
success += 1
|
83
|
+
else
|
84
|
+
errors << c.errors.full_messages
|
85
|
+
end
|
86
|
+
end
|
87
|
+
log("Namespaced #{success} essence_type columns.") if success > 0
|
88
|
+
log("#{errors.count} errors while namespacing essence_type columns.\n#{errors.join('\n')}", :error) if errors.count > 0
|
89
|
+
else
|
90
|
+
log "No essence_type columns to be namespaced found.", :skip
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Alchemy
|
2
|
+
module Upgrader::TwoPointSix
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def convert_attachment_storage
|
7
|
+
desc "Convert the attachment storage"
|
8
|
+
converted_files = []
|
9
|
+
files = Dir.glob Rails.root.join 'uploads/attachments/**/*.*'
|
10
|
+
if files.blank?
|
11
|
+
log "No attachments found", :skip
|
12
|
+
else
|
13
|
+
files.each do |file|
|
14
|
+
file_uid = file.gsub(/#{Rails.root.to_s}\/uploads\/attachments\//, '')
|
15
|
+
file_id = file_uid.split('/')[1].to_i
|
16
|
+
attachment = Alchemy::Attachment.find_by_id(file_id)
|
17
|
+
if attachment && attachment.file_uid.blank?
|
18
|
+
attachment.file_uid = file_uid
|
19
|
+
attachment.file_size = File.new(file).size
|
20
|
+
attachment.file_name = attachment.sanitized_filename
|
21
|
+
if attachment.save!
|
22
|
+
log "Converted #{file_uid}"
|
23
|
+
end
|
24
|
+
else
|
25
|
+
log "Attachment with id #{file_id} not found or already converted.", :skip
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Alchemy
|
2
|
+
module Upgrader::TwoPointThree
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def gallery_pictures_change_notice
|
7
|
+
note =<<NOTE
|
8
|
+
We have changed the way Alchemy handles EssencePictures in elements.
|
9
|
+
|
10
|
+
It is now possible to have single EssencePictures and galleries side by side in the same element.
|
11
|
+
All element editor views containing render_picture_editor with option `maximum_amount_of_images => 1` must be changed into render_essence_editor_by_name.
|
12
|
+
In the yml description of these elements add a new content for this picture.
|
13
|
+
|
14
|
+
In order to upgrade your elements in the database run:
|
15
|
+
|
16
|
+
rails g alchemy:gallery_pictures_migration
|
17
|
+
|
18
|
+
and alter `db/seeds.rb`, so that it contains all elements that have essence pictures.
|
19
|
+
|
20
|
+
NOTE
|
21
|
+
todo note
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Alchemy
|
2
|
+
module Upgrader::TwoPointTwo
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def convert_essence_texts_displayed_as_select_into_essence_selects
|
7
|
+
desc "Converting EssenceTexts displayed as select into EssenceSelects"
|
8
|
+
contents_found = 0
|
9
|
+
elements = Alchemy::Element.descriptions.select { |e| e['contents'].present? && !e['contents'].detect { |c| c['settings'].present? && c['settings']['display_as'] == 'select' }.nil? }
|
10
|
+
contents = elements.collect { |el| el['contents'] }.flatten.select { |c| c['settings'] && c['settings']['display_as'] == 'select' }.flatten
|
11
|
+
content_names = contents.collect { |c| c['name'] }
|
12
|
+
Alchemy::Content.essence_texts.where(
|
13
|
+
:name => content_names,
|
14
|
+
:alchemy_elements => {:name => elements.collect { |e| e['name'] }}
|
15
|
+
).joins(:element).each do |content|
|
16
|
+
new_content = Alchemy::Content.new(:name => content.name, :element_id => content.element.id)
|
17
|
+
if new_content.create_essence!('name' => content.name, 'type' => 'EssenceSelect')
|
18
|
+
new_content.essence.value = content.ingredient
|
19
|
+
if new_content.essence.save
|
20
|
+
contents_found += 1
|
21
|
+
log "Converted #{content.name}'s essence_type into EssenceSelect"
|
22
|
+
content.destroy
|
23
|
+
else
|
24
|
+
log "Could not save essence: #{new_content.essence.errors.full_messages.join(', ')}", :error
|
25
|
+
end
|
26
|
+
else
|
27
|
+
log "Could not create content: #{new_content.errors.full_messages.join(', ')}", :error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
if contents_found > 0
|
31
|
+
todo "Please open your elements.yml file and change all type values from these contents:\n\n#{content_names.join(', ')}\n\ninto EssenceSelect."
|
32
|
+
else
|
33
|
+
log "No EssenceTexts with display_as select setting found.", :skip
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def convert_essence_texts_displayed_as_checkbox_into_essence_booleans
|
38
|
+
desc "Converting EssenceTexts displayed as checkbox into EssenceBooleans"
|
39
|
+
contents_found = 0
|
40
|
+
elements = Alchemy::Element.descriptions.select { |e| e['contents'].present? && !e['contents'].detect { |c| c['settings'].present? && c['settings']['display_as'] == 'checkbox' }.nil? }
|
41
|
+
contents = elements.collect { |el| el['contents'] }.flatten.select { |c| c['settings'] && c['settings']['display_as'] == 'checkbox' }.flatten
|
42
|
+
content_names = contents.collect { |c| c['name'] }
|
43
|
+
Alchemy::Content.essence_texts.where(
|
44
|
+
:name => content_names,
|
45
|
+
:alchemy_elements => {:name => elements.collect { |e| e['name'] }}
|
46
|
+
).joins(:element).each do |content|
|
47
|
+
new_content = Alchemy::Content.new(:name => content.name, :element_id => content.element.id)
|
48
|
+
if new_content.create_essence!('name' => content.name, 'type' => 'EssenceBoolean')
|
49
|
+
new_content.essence.value = content.ingredient
|
50
|
+
if new_content.essence.save
|
51
|
+
contents_found += 1
|
52
|
+
log "Converted #{content.name}'s essence_type into EssenceBoolean"
|
53
|
+
content.destroy
|
54
|
+
else
|
55
|
+
log "Could not save essence: #{new_content.essence.errors.full_messages.join(', ')}", :error
|
56
|
+
end
|
57
|
+
else
|
58
|
+
log "Could not create content: #{new_content.errors.full_messages.join(', ')}", :error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
if contents_found > 0
|
62
|
+
todo "Please open your elements.yml file and change all type values from these contents:\n\n#{content_names.join(', ')}\n\ninto EssenceBoolean."
|
63
|
+
else
|
64
|
+
log "No EssenceTexts with display_as checkbox setting found.", :skip
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
data/lib/alchemy/version.rb
CHANGED
@@ -12,7 +12,7 @@ namespace :alchemy do
|
|
12
12
|
task :list => [:environment] do
|
13
13
|
puts "\nAvailable upgrade tasks"
|
14
14
|
puts "-----------------------\n"
|
15
|
-
methods =
|
15
|
+
methods = Alchemy::Upgrader.all_upgrade_tasks
|
16
16
|
if methods.any?
|
17
17
|
methods.each { |method| puts method }
|
18
18
|
puts "\nUsage:"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
describe Alchemy::MountPoint do
|
5
|
+
|
6
|
+
describe '.get' do
|
7
|
+
|
8
|
+
it "returns the path of alchemy's mount point" do
|
9
|
+
Alchemy::MountPoint.stub!(:mount_point).and_return('/cms')
|
10
|
+
Alchemy::MountPoint.get.should == '/cms'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "removes the leading slash if root mount point" do
|
14
|
+
Alchemy::MountPoint.stub!(:mount_point).and_return('/')
|
15
|
+
Alchemy::MountPoint.get.should == ''
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with remove_leading_slash_if_blank set to false" do
|
19
|
+
before {
|
20
|
+
Alchemy::MountPoint.stub!(:mount_point).and_return('/')
|
21
|
+
}
|
22
|
+
|
23
|
+
it "does not remove the leading white slash of path" do
|
24
|
+
Alchemy::MountPoint.get(false).should == '/'
|
25
|
+
end
|
26
|
+
|
27
|
+
context "and with mount point not root" do
|
28
|
+
before {
|
29
|
+
Alchemy::MountPoint.stub!(:mount_point).and_return('/cms')
|
30
|
+
}
|
31
|
+
|
32
|
+
it "does not remove the leading white slash of path" do
|
33
|
+
Alchemy::MountPoint.get(false).should == '/cms'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.routes' do
|
40
|
+
it "returns the routes object from alchemy engine" do
|
41
|
+
Alchemy::MountPoint.routes.should be_instance_of(Journey::Route)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.mount_point' do
|
46
|
+
it 'returns the raw mount point path from routes' do
|
47
|
+
Alchemy::MountPoint.stub!(:routes).and_return(OpenStruct.new(path: OpenStruct.new(spec: '/cms')))
|
48
|
+
Alchemy::MountPoint.mount_point.should == '/cms'
|
49
|
+
end
|
50
|
+
|
51
|
+
context "Alchemy routes could not be found" do
|
52
|
+
before {
|
53
|
+
Alchemy::MountPoint.stub!(:routes).and_return(nil)
|
54
|
+
}
|
55
|
+
|
56
|
+
it "falls back to root path" do
|
57
|
+
Alchemy::MountPoint.mount_point.should == '/'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Alchemy
|
4
|
+
|
5
|
+
# Class fixture
|
6
|
+
class MyToDoList
|
7
|
+
extend Shell
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Shell do
|
11
|
+
|
12
|
+
before { MyToDoList.stub!(:puts) }
|
13
|
+
|
14
|
+
describe '.todo' do
|
15
|
+
it "should add given string as a todo by delegating to .add_todo" do
|
16
|
+
MyToDoList.should_receive(:add_todo).with("new todo")
|
17
|
+
MyToDoList.todo("new todo")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.todos' do
|
22
|
+
it "should be an Array" do
|
23
|
+
expect(MyToDoList.todos).to be_a(Array)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.add_todo' do
|
28
|
+
it "should add the given string to the .todos array" do
|
29
|
+
MyToDoList.add_todo('1')
|
30
|
+
MyToDoList.add_todo('2')
|
31
|
+
expect(MyToDoList.todos).to eq(['1', '2'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.display_todos' do
|
36
|
+
context 'if there are todos in the list' do
|
37
|
+
before do
|
38
|
+
MyToDoList.stub!(:todos).and_return(['My first todo', 'My second todo'])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should log them" do
|
42
|
+
MyToDoList.should_receive(:log).any_number_of_times
|
43
|
+
MyToDoList.display_todos
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should iterate through the todos with an index" do
|
47
|
+
MyToDoList.todos.should_receive(:each_with_index)
|
48
|
+
MyToDoList.display_todos
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'if there are todos in the list' do
|
53
|
+
before do
|
54
|
+
MyToDoList.stub!(:todos).and_return([])
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not log anything" do
|
58
|
+
MyToDoList.should_not_receive(:log)
|
59
|
+
MyToDoList.display_todos
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '.log' do
|
65
|
+
|
66
|
+
context 'if the message type is "skip"' do
|
67
|
+
it "the output color should be yellow and cleared again" do
|
68
|
+
MyToDoList.should_receive(:color).with(:yellow)
|
69
|
+
MyToDoList.should_receive(:color).with(:clear)
|
70
|
+
MyToDoList.log('in yellow, please', :skip)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'if the message type is "error"' do
|
75
|
+
it "the output color should be yellow and cleared again" do
|
76
|
+
MyToDoList.should_receive(:color).with(:red)
|
77
|
+
MyToDoList.should_receive(:color).with(:clear)
|
78
|
+
MyToDoList.log('in red, please', :error)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'if the message type is "message"' do
|
83
|
+
it "the output color should just be cleared" do
|
84
|
+
MyToDoList.should_receive(:color).with(:clear)
|
85
|
+
MyToDoList.log('cleared, please', :message)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'if no message type is given' do
|
90
|
+
it "the output color should be green" do
|
91
|
+
MyToDoList.should_receive(:color).with(:green)
|
92
|
+
MyToDoList.should_receive(:color).with(:clear)
|
93
|
+
MyToDoList.log('in green, please')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '.color' do
|
99
|
+
|
100
|
+
context 'if given name is a constant of Thor::Shell::Color' do
|
101
|
+
before do
|
102
|
+
Thor::Shell::Color.stub!(:const_defined?).and_return(true)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should call the constant" do
|
106
|
+
String.any_instance.should_receive(:constantize).and_return('')
|
107
|
+
MyToDoList.send(:color, :red)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'if given name is not a defined constant of Thor::Shell::Color' do
|
112
|
+
before do
|
113
|
+
Thor::Shell::Color.stub!(:const_defined?).and_return(false)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should return en empty string" do
|
117
|
+
expect(MyToDoList.send(:color, :not_existing)).to eq('')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|