This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
144 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,7 @@ tmtags | |
coverage | ||
rdoc | ||
pkg | ||
.bundle | ||
|
||
## PROJECT::SPECIFIC | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source :gemcutter | ||
|
||
gem 'bson_ext', '0.20.1' | ||
gem 'mongoid', '2.0.0.beta4' | ||
gem 'rspec', '2.0.0.beta.8' | ||
gem 'mocha' | ||
|
||
gem 'jeweler' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,33 @@ | ||
# encoding: utf-8 | ||
require 'rubygems' | ||
require 'rake' | ||
require 'rspec' | ||
require 'rspec/core/rake_task' | ||
|
||
begin | ||
require 'jeweler' | ||
Jeweler::Tasks.new do |gem| | ||
gem.name = "mongoid_i18n" | ||
gem.summary = %Q{Mongoid plugin to deal with localizable fields} | ||
gem.description = %Q{TODO: longer description of your gem} | ||
gem.description = %Q{This gem aims to be a transparent way to deal with localizable fields. | ||
Basically use localized_field() instead of field() and that's it. | ||
It will take care of locales for you when using find. | ||
} | ||
gem.email = "[email protected]" | ||
gem.homepage = "http://github.com/Papipo/mongoid_i18n" | ||
gem.authors = ["Rodrigo Álvarez"] | ||
gem.add_development_dependency "rspec", ">= 1.2.9" | ||
gem.add_dependency "mongoid", '2.0.0.beta4' | ||
gem.add_development_dependency "rspec", "2.0.0.beta.8" | ||
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings | ||
end | ||
Jeweler::GemcutterTasks.new | ||
rescue LoadError | ||
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" | ||
end | ||
|
||
require 'spec/rake/spectask' | ||
Spec::Rake::SpecTask.new(:spec) do |spec| | ||
spec.libs << 'lib' << 'spec' | ||
spec.spec_files = FileList['spec/**/*_spec.rb'] | ||
end | ||
|
||
Spec::Rake::SpecTask.new(:rcov) do |spec| | ||
spec.libs << 'lib' << 'spec' | ||
spec.pattern = 'spec/**/*_spec.rb' | ||
spec.rcov = true | ||
end | ||
|
||
task :spec => :check_dependencies | ||
desc "Run all examples" | ||
Rspec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
gem 'mongoid', '2.0.0.beta4' | ||
require 'mongoid' | ||
require 'mongoid/i18n/localized_field' | ||
|
||
module Mongoid | ||
module I18n | ||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
def localized_field(name, options = {}) | ||
field name, options.merge(:type => LocalizedField, :default => {}) | ||
end | ||
|
||
protected | ||
def create_accessors(name, meth, options = {}) | ||
if options[:type] == LocalizedField | ||
define_method(meth) { read_attribute(name)[::I18n.locale] } | ||
define_method("#{meth}=") do |value| | ||
write_attribute(name, (@attributes[name] || {}).merge(::I18n.locale => value)) | ||
end | ||
define_method("#{meth}_translations") { read_attribute(name) } | ||
define_method("#{meth}_translations=") { |value| write_attribute(name, value) } | ||
else | ||
super | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Mongoid | ||
module I18n | ||
class LocalizedField < Hash | ||
end | ||
end | ||
end |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# encoding: utf-8 | ||
require 'spec_helper' | ||
|
||
class Entry | ||
include Mongoid::Document | ||
include Mongoid::I18n | ||
|
||
localized_field :title | ||
field :published, :type => Boolean | ||
end | ||
|
||
describe Mongoid::I18n, "localized_field" do | ||
describe "with an assigned value" do | ||
before do | ||
I18n.locale = :en | ||
@entry = Entry.new(:title => 'Title') | ||
end | ||
|
||
it "should return that value" do | ||
@entry.title.should == 'Title' | ||
end | ||
|
||
describe "when the locale is changed" do | ||
before do | ||
I18n.locale = :es | ||
end | ||
|
||
it "should return a blank value value" do | ||
@entry.title.should be_blank | ||
end | ||
|
||
describe "a new value is assigned" do | ||
before do | ||
@entry.title = 'Título' | ||
end | ||
|
||
it "should return the new value" do | ||
@entry.title.should == 'Título' | ||
end | ||
|
||
describe "getter.translations" do | ||
it "should return all translations" do | ||
@entry.title_translations.should == {:en => 'Title', :es => 'Título'} | ||
end | ||
end | ||
|
||
describe "getter.translations=" do | ||
before do | ||
@entry.title_translations = {:en => 'New title', :es => 'Nuevo título'} | ||
end | ||
|
||
it "should accept new translations" do | ||
@entry.title_translations.should == {:en => 'New title', :es => 'Nuevo título'} | ||
end | ||
|
||
it "the setter should return the new translation" do | ||
@entry.title.should == 'Nuevo título' | ||
end | ||
end | ||
|
||
describe "and we go back to the original locale" do | ||
before do | ||
I18n.locale = :en | ||
end | ||
|
||
it "should return the original value" do | ||
@entry.title.should == 'Title' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
require 'mongoid_i18n' | ||
require 'spec' | ||
require 'spec/autorun' | ||
|
||
Spec::Runner.configure do |config| | ||
|
||
require 'mongoid/i18n' | ||
require 'rspec' | ||
require 'rspec/autorun' | ||
|
||
Rspec.configure do |config| | ||
config.mock_with :mocha | ||
config.after :each do | ||
Mongoid.master.collections.each(&:drop) | ||
end | ||
end | ||
|
||
Mongoid.configure do |config| | ||
config.master = Mongo::Connection.new.db('mongoid_i18n_test') | ||
config.allow_dynamic_fields = false | ||
end |