From ac1a93d2e4b438c20082555c1b7405e3ffff8ff7 Mon Sep 17 00:00:00 2001 From: Gatis Tomsons Date: Thu, 22 Sep 2011 16:11:44 +0100 Subject: [PATCH] fixed specs --- Gemfile | 5 ++--- Gemfile.lock | 19 +++++++++++++++-- .../stylesheets/lolita/i18n/application.scss | 3 +++ app/controllers/lolita/i18n_controller.rb | 3 +-- app/views/lolita/i18n/edit.html.erb | 2 +- lib/lolita-i18n.rb | 15 +++++++++++-- .../lolita/i18n_controller_spec.rb | 6 +++--- spec/lolita_i18n_spec.rb | 2 +- spec/rails_app/config/application.rb | 2 ++ .../config/initializers/lolita_i18n.rb | 16 ++++++++++++-- spec/spec_helper.rb | 21 ++++++++++++++++++- 11 files changed, 77 insertions(+), 17 deletions(-) diff --git a/Gemfile b/Gemfile index b32f03f..377bcfa 100644 --- a/Gemfile +++ b/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" @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 14ad101..f465323 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/app/assets/stylesheets/lolita/i18n/application.scss b/app/assets/stylesheets/lolita/i18n/application.scss index d784b82..86fad7f 100644 --- a/app/assets/stylesheets/lolita/i18n/application.scss +++ b/app/assets/stylesheets/lolita/i18n/application.scss @@ -54,4 +54,7 @@ p.hint { color: #666; text-align: right; span { font-weight: bold; } +} +#i18n_edit textarea { + height: 100px; } \ No newline at end of file diff --git a/app/controllers/lolita/i18n_controller.rb b/app/controllers/lolita/i18n_controller.rb index 99eca0f..460da0e 100644 --- a/app/controllers/lolita/i18n_controller.rb +++ b/app/controllers/lolita/i18n_controller.rb @@ -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 \ No newline at end of file diff --git a/app/views/lolita/i18n/edit.html.erb b/app/views/lolita/i18n/edit.html.erb index 3bbef9b..da1f5f2 100644 --- a/app/views/lolita/i18n/edit.html.erb +++ b/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 %> -
+

I18n edit

diff --git a/lib/lolita-i18n.rb b/lib/lolita-i18n.rb index be29030..ea81f07 100644 --- a/lib/lolita-i18n.rb +++ b/lib/lolita-i18n.rb @@ -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 diff --git a/spec/controllers/lolita/i18n_controller_spec.rb b/spec/controllers/lolita/i18n_controller_spec.rb index 857cd3a..b558eac 100644 --- a/spec/controllers/lolita/i18n_controller_spec.rb +++ b/spec/controllers/lolita/i18n_controller_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/lolita_i18n_spec.rb b/spec/lolita_i18n_spec.rb index 765b6ed..14a0a5a 100644 --- a/spec/lolita_i18n_spec.rb +++ b/spec/lolita_i18n_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/rails_app/config/application.rb b/spec/rails_app/config/application.rb index be44ade..7448ba2 100644 --- a/spec/rails_app/config/application.rb +++ b/spec/rails_app/config/application.rb @@ -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 diff --git a/spec/rails_app/config/initializers/lolita_i18n.rb b/spec/rails_app/config/initializers/lolita_i18n.rb index ceb46ae..19c866b 100644 --- a/spec/rails_app/config/initializers/lolita_i18n.rb +++ b/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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0a27444..c53495c 100644 --- a/spec/spec_helper.rb +++ b/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' @@ -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') \ No newline at end of file +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 \ No newline at end of file