Skip to content

Commit

Permalink
fixed specs
Browse files Browse the repository at this point in the history
  • Loading branch information
gacha committed Sep 22, 2011
1 parent 9cb2df5 commit ac1a93d
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 17 deletions.
5 changes: 2 additions & 3 deletions Gemfile
@@ -1,11 +1,9 @@
source "http://rubygems.org"

gem "lolita", '3.2.0.rc.3'
gem "sqlite3"
gem "redis"
gem "yajl-ruby"

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
Expand All @@ -19,4 +17,5 @@ group :test do
gem "mongo", "~> 1.3.0"
gem "mongoid", "~> 2.0.0"
gem "bson_ext", "~> 1.3.0"
gem 'ruby-debug19', :require => 'ruby-debug'
end
19 changes: 17 additions & 2 deletions Gemfile.lock
Expand Up @@ -31,11 +31,13 @@ GEM
activesupport (= 3.1.0)
activesupport (3.1.0)
multi_json (~> 1.0)
archive-tar-minitar (0.5.2)
arel (2.2.1)
bcrypt-ruby (3.0.1)
bson (1.3.1)
bson_ext (1.3.1)
builder (3.0.0)
columnize (0.3.4)
diff-lcs (1.1.3)
digestion (1.2)
actionpack (~> 3.1.0)
Expand All @@ -53,6 +55,8 @@ GEM
thor (~> 0.14)
kaminari (0.12.4)
rails (>= 3.0.0)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
lolita (3.2.0.rc.3)
abstract
builder (~> 3.0)
Expand Down Expand Up @@ -101,6 +105,7 @@ GEM
rake (0.9.2)
rcov (0.9.10)
rdoc (3.9.4)
redis (2.2.2)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
Expand All @@ -114,12 +119,21 @@ GEM
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.5.0)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
shoulda (2.11.3)
sprockets (2.0.0)
hike (~> 1.2)
rack (~> 1.0)
tilt (!= 1.3.0, ~> 1.1)
sqlite3 (1.3.4)
thor (0.14.6)
tilt (1.3.3)
tinymce-rails (3.4.5)
Expand All @@ -142,8 +156,9 @@ DEPENDENCIES
mongo (~> 1.3.0)
mongoid (~> 2.0.0)
rcov
redis
rspec (~> 2.5.0)
rspec-rails (~> 2.5.0)
ruby-debug19
shoulda
sqlite3
yajl-ruby
3 changes: 3 additions & 0 deletions app/assets/stylesheets/lolita/i18n/application.scss
Expand Up @@ -54,4 +54,7 @@ p.hint {
color: #666;
text-align: right;
span { font-weight: bold; }
}
#i18n_edit textarea {
height: 100px;
}
3 changes: 1 addition & 2 deletions app/controllers/lolita/i18n_controller.rb
Expand Up @@ -19,8 +19,7 @@ def next

def update
Lolita::I18n::Backend.set(params[:id],params[:i18n])
next_key=Lolita::I18n::Backend.next(params[:id],Lolita::I18n::Backend.locale(params[:id]))
redirect_to :action=>:edit,:id=>next_key
redirect_to :action=>:edit, :id=>params[:id]
end

end
2 changes: 1 addition & 1 deletion app/views/lolita/i18n/edit.html.erb
@@ -1,7 +1,7 @@
<% content_for :style do %>
<%= stylesheet_link_tag "lolita/i18n/application.css", :media => "screen,projection" %>
<% end %>
<div class="tab box" id="tab_edit">
<div class="tab box" id="i18n_edit">
<div class="tab-title boxtitle black" >
<h1>I18n edit</h1>
<div class="arrow"></div>
Expand Down
15 changes: 13 additions & 2 deletions lib/lolita-i18n.rb
Expand Up @@ -6,14 +6,25 @@ module Lolita
module I18n
autoload :Backend, 'lolita-i18n/backend'
def self.load options={}
@@backend=::I18n::Backend::KeyValue.new(Redis.new({:db => 10}.merge(options)))
# Loads given key/value engine as backend
# place this method in rails initializer lolita.rb
# === Example
#
# I18n.backend = Lolita::I18n.load Redis.new
#
def self.load store
@@store=store
@@backend=::I18n::Backend::KeyValue.new(@@store)
@@yaml_backend=::I18n.backend
::I18n::Backend::Simple.send(:include, ::I18n::Backend::Flatten)
::I18n::Backend::Simple.send(:include, ::I18n::Backend::Memoize)
::I18n::Backend::Chain.new(Lolita::I18n.backend, @@yaml_backend)
end
def self.store
@@store
end
def self.backend
@@backend
end
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/lolita/i18n_controller_spec.rb
Expand Up @@ -16,8 +16,8 @@
response.body.should match(/Page title/)
end

it "should save transaltion" do
put :update, {:id=>"en.Page title"}, {:value=>"New title"}
response.body.should match(/New title/)
it "should save translation" do
put :update, {:id=>"en.Page title",:i18n => {:value=>"New title"}}
response.should redirect_to(:action=>:edit, :id=>"en.Page title")
end
end
2 changes: 1 addition & 1 deletion spec/lolita_i18n_spec.rb
Expand Up @@ -11,6 +11,6 @@
end

it "should have fallback to default I18n store" do
I18n.backend.store["en.Page title"].gsub(/\"/,"").should == "Page title"
I18n.t("Page title").should == "Page title"
end
end
2 changes: 2 additions & 0 deletions spec/rails_app/config/application.rb
Expand Up @@ -10,6 +10,8 @@ class Application < Rails::Application
config.root=File.expand_path("#{File.dirname(__FILE__)}/..")
config.logger=Logger.new(File.join(config.root,"log","development.log"))
config.active_support.deprecation=:log
config.i18n.default_locale = :en

#config.autoload_paths=File.expand_path("../#{File.dirname(__FILE__)}")
end
end
16 changes: 14 additions & 2 deletions spec/rails_app/config/initializers/lolita_i18n.rb
@@ -1,3 +1,15 @@
Rails.application.config.after_initialize do
I18n.backend.load_translations
Lolita.setup do |config|
# ==> User and authentication configuration
# Add one or more of your user classes to Lolita
# config.user_classes << MyUser
# config.authentication = :authenticate_user!

# Define authentication for Lolita controllers.
# Call some of your own methods
# config.authentication=:is_admin?
# Or use some customized logic
# config.authentication={
# current_user.is_a?(Admin) || current_user.has_role?(:admin)
# }
I18n.backend = Lolita::I18n.load Redis.new(:db => 11)
end
21 changes: 20 additions & 1 deletion spec/spec_helper.rb
@@ -1,4 +1,16 @@
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :test)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end

require 'rails'
require 'lolita'

if USE_RAILS
require 'mongoid'

Expand All @@ -9,4 +21,11 @@
require File.expand_path("../rails_app/config/enviroment.rb",__FILE__)
require "rspec/rails"
end
require File.expand_path('lib/lolita-i18n')
require File.expand_path('lib/lolita-i18n')

RSpec.configure do |config|
config.mock_with :rspec
config.before(:each) do
Lolita::I18n.store.flushdb
end
end

0 comments on commit ac1a93d

Please sign in to comment.