Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Configuration specs

  • Loading branch information...
commit 4a6ac89c5e251a571efe91fe90e3a616222e4b4e 1 parent 8e0a696
Sam Pohlenz authored
1  Gemfile
View
@@ -9,6 +9,7 @@ gem 'json', :platforms => [:ruby_18]
group :test do
gem "rspec-rails"
+ gem "guard-rspec"
end
gemspec
5 Guardfile
View
@@ -0,0 +1,5 @@
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/tinymce/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
1  lib/tinymce/rails.rb
View
@@ -2,6 +2,7 @@ module TinyMCE
module Rails
require 'tinymce/rails/engine'
require 'tinymce/rails/version'
+ require "tinymce/rails/configuration"
def self.base
Engine.config.tinymce.base ||
38 lib/tinymce/rails/configuration.rb
View
@@ -0,0 +1,38 @@
+module TinyMCE::Rails
+ class Configuration
+ def self.defaults
+ {
+ "mode" => "textareas",
+ "theme" => "advanced",
+ "language" => default_language,
+ "editor_selector" => "tinymce"
+ }
+ end
+
+ attr_reader :options
+
+ def initialize
+ @options = self.class.defaults
+ end
+
+ # Default language falls back to English if current locale is not available.
+ def self.default_language
+ available_languages.include?(I18n.locale.to_s) ? I18n.locale.to_s : "en"
+ end
+
+ # Searches asset paths for TinyMCE language files.
+ def self.available_languages
+ assets.paths.map { |path|
+ files = assets.entries(File.join(path, "tinymce/langs"))
+ files.map { |file|
+ asset = assets.attributes_for(File.join(path, file))
+ asset.logical_path.sub(/\.js$/, "")
+ }
+ }.flatten.uniq
+ end
+
+ def self.assets
+ Rails.application.assets
+ end
+ end
+end
8 lib/tinymce/rails/engine.rb
View
@@ -1,7 +1,5 @@
-module TinyMCE
- module Rails
- class Engine < ::Rails::Engine
- config.tinymce = ActiveSupport::OrderedOptions.new
- end
+module TinyMCE::Rails
+ class Engine < ::Rails::Engine
+ config.tinymce = ActiveSupport::OrderedOptions.new
end
end
3  spec/assets/tinymce/langs/erb.js.erb
View
@@ -0,0 +1,3 @@
+tinyMCE.addI18n({
+ erb: <%= {}.to_json %>
+});
3  spec/assets/tinymce/langs/pirate.js
View
@@ -0,0 +1,3 @@
+tinyMCE.addI18n({
+ pirate: {}
+});
41 spec/lib/configuration_spec.rb
View
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+module TinyMCE::Rails
+ describe Configuration do
+ it "has default options" do
+ Configuration.defaults.should eq(
+ "mode" => "textareas",
+ "theme" => "advanced",
+ "language" => "en",
+ "editor_selector" => "tinymce"
+ )
+ end
+
+ it "uses the current locale if available" do
+ I18n.locale = "pirate"
+ Configuration.defaults["language"].should eq("pirate")
+ end
+
+ it "falls back to English if the current locale is not available" do
+ I18n.locale = "missing"
+ Configuration.defaults["language"].should eq("en")
+ end
+
+ it "uses default options when instantiated without a filename" do
+ config = Configuration.new
+ config.options.should eq(Configuration.defaults)
+ end
+
+ it "loads configuration from YAML file when instantiated with a filename"
+
+ it "detects available languages" do
+ langs = Configuration.available_languages
+
+ langs.should include("en")
+ langs.should include("pirate")
+ langs.should include("erb")
+
+ langs.should_not include("missing")
+ end
+ end
+end
40 spec/lib/tinymce_rails_spec.rb
View
@@ -1,22 +1,26 @@
require 'spec_helper'
-describe TinyMCE::Rails do
- before(:each) do
- ::Rails.application.config.action_controller.asset_host = nil
- ActionController::Base.config.relative_url_root = nil
- end
-
- it "has a base path" do
- TinyMCE::Rails.base.should eq("/assets/tinymce")
- end
-
- it "uses the asset host in the base path when set" do
- ::Rails.application.config.action_controller.asset_host = "http://assets.example.com"
- TinyMCE::Rails.base.should eq("http://assets.example.com/assets/tinymce")
- end
-
- it "uses the relative url root in the base path when set" do
- ActionController::Base.config.relative_url_root = "/subfolder"
- TinyMCE::Rails.base.should eq("/subfolder/assets/tinymce")
+module TinyMCE
+ describe Rails do
+ describe ".base" do
+ before(:each) do
+ ::Rails.application.config.action_controller.asset_host = nil
+ ActionController::Base.config.relative_url_root = nil
+ end
+
+ it "has a base path" do
+ TinyMCE::Rails.base.should eq("/assets/tinymce")
+ end
+
+ it "uses the asset host in the base path when set" do
+ ::Rails.application.config.action_controller.asset_host = "http://assets.example.com"
+ TinyMCE::Rails.base.should eq("http://assets.example.com/assets/tinymce")
+ end
+
+ it "uses the relative url root in the base path when set" do
+ ActionController::Base.config.relative_url_root = "/subfolder"
+ TinyMCE::Rails.base.should eq("/subfolder/assets/tinymce")
+ end
+ end
end
end
4 spec/spec_helper.rb
View
@@ -5,7 +5,9 @@
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
-Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
+
+Rails.application.assets.append_path File.expand_path("../assets", __FILE__)
RSpec.configure do |config|
end
Please sign in to comment.
Something went wrong with that request. Please try again.