Permalink
Browse files

Removed deprecated #s and #copy_for methods

  • Loading branch information...
1 parent 120c74e commit 4f6e1eae650bbf7d7828a3cfb4e7e24af5ff369c @jferris jferris committed Jan 31, 2011
Showing with 0 additions and 161 deletions.
  1. +0 −26 features/rails.feature
  2. +0 −40 lib/copycopter_client/helper.rb
  3. +0 −9 lib/copycopter_client/rails.rb
  4. +0 −86 spec/copycopter_client/helper_spec.rb
@@ -132,32 +132,6 @@ Feature: Using copycopter in a rails app
| key | draft content |
| en.users.index.unknown-test | Unknown |
- Scenario: backwards compatibility
- Given the "abc123" project has the following blurbs:
- | key | draft content |
- | en.users.index.controller-test | Controller blurb |
- | en.users.index.view-test | View blurb |
- When I write to "app/controllers/users_controller.rb" with:
- """
- class UsersController < ActionController::Base
- def index
- @text = s('.controller-test')
- render
- end
- end
- """
- When I route the "users" resource
- And I write to "app/views/users/index.html.erb" with:
- """
- <%= @text %>
- <%= s(".view-test", "default") %>
- """
- When I start the application
- And I wait for changes to be synchronized
- And I visit /users/
- Then the response should contain "Controller blurb"
- And the response should contain "View blurb"
-
Scenario: configure a bad api key
When I configure the copycopter client with api key "bogus"
And I start the application
@@ -1,40 +0,0 @@
-module CopycopterClient
- # Helper methods for Copycopter
- # @deprecated use +I81n#translate+ instead.
- module Helper
- # Returns copy for the given key in the current locale.
- # @param key [String] the key you want copy for
- # @param default [String, Hash] an optional default value, used if this key is missing
- # @option default [String] :default the default text
- def copy_for(key, default=nil)
- default = if default.respond_to?(:to_hash)
- default[:default]
- else
- default
- end
-
- key = scope_copycopter_key_by_partial(key)
- warn("WARNING: #s is deprecated; use t(#{key.inspect}, :default => #{default.inspect}) instead.")
- I18n.translate(key, { :default => default })
- end
- alias_method :s, :copy_for
-
- private
-
- def scope_copycopter_key_by_partial(key)
- if respond_to?(:scope_key_by_partial, true)
- scope_key_by_partial(key)
- elsif key.to_s[0].chr == "."
- if respond_to?(:template)
- "#{template.path_without_format_and_extension.gsub(%r{/_?}, '.')}#{key}"
- else
- "#{controller_name}.#{action_name}#{key}"
- end
- else
- key
- end
- end
- end
-
- extend Helper
-end
@@ -1,12 +1,3 @@
-require 'copycopter_client/helper'
-
-if defined?(ActionController::Base)
- ActionController::Base.send :include, CopycopterClient::Helper
-end
-if defined?(ActionView::Base)
- ActionView::Base.send :include, CopycopterClient::Helper
-end
-
module CopycopterClient
# Responsible for Rails initialization
module Rails
@@ -1,86 +0,0 @@
-require 'spec_helper'
-require 'copycopter_client/helper'
-
-describe CopycopterClient::Helper do
- subject { Object.new }
-
- before do
- class << subject
- include CopycopterClient::Helper
- def warn(*args); end # these are annoying in test output
- end
- I18n.stubs(:translate)
- end
-
- RSpec::Matchers.define :have_translated do |key, default|
- match do |ignored_subject|
- extend Mocha::API
- I18n.should have_received(:translate).with(key, :default => default)
- end
- end
-
- it "translates keys on CopycopterClient.s" do
- CopycopterClient.s('test.key', 'default')
- should have_translated("test.key", 'default')
- end
-
- it "translates keys on CopycopterClient.copy_for" do
- CopycopterClient.copy_for('test.key', 'default')
- should have_translated("test.key", 'default')
- end
-
- it "uses existing scope by partial key when present" do
- subject.stubs(:scope_key_by_partial => "controller.action.key")
- class << subject
- private :scope_key_by_partial
- end
-
- subject.s(".key")
-
- subject.should have_received(:scope_key_by_partial).with(".key")
- should have_translated("controller.action.key", nil)
- end
-
- it "should prepend current partial when key starts with . and inside a view" do
- template = stub(:path_without_format_and_extension => "controller/action")
- subject.stubs(:template => template)
-
- subject.s(".key")
-
- should have_translated("controller.action.key", nil)
- end
-
- it "should prepend controller and action when key starts with . and inside a controller" do
- subject.stubs(:controller_name => "controller", :action_name => "action")
-
- subject.s(".key")
-
- should have_translated("controller.action.key", nil)
- end
-
- describe "default assignment" do
- before do
- subject.stubs(:scope_copycopter_key_by_partial => '.key')
- end
-
- it "should allow a hash with key default" do
- subject.s(@key, :default => "Default string")
- should have_translated('.key', "Default string")
- end
-
- it "should not allow a hash with stringed key default" do
- subject.s(@key, "default" => "Default string")
- should have_translated('.key', nil)
- end
-
- it "should not allow a hash with key other than default" do
- subject.s(@key, :junk => "Default string")
- should have_translated('.key', nil)
- end
-
- it "should allow a string" do
- subject.s(@key, "Default string")
- should have_translated('.key', "Default string")
- end
- end
-end

0 comments on commit 4f6e1ea

Please sign in to comment.