Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rename cothread/thread source_language -> source_locale.

  • Loading branch information...
commit 24c04e338f32b65aa10d1d4ecb499397b9ca6cf6 1 parent e5d873c
@shioyama shioyama authored
View
2  app/assets/javascripts/application.js
@@ -35,5 +35,5 @@
//
//= require bootstrap
//
-//= require pushstate_links
//= require mixins
+//= require pushstate_links
View
10 app/assets/javascripts/models/thread.js.coffee
@@ -16,17 +16,17 @@ App.Thread = App.Models.Thread = Backbone.Model.extend
title: _(I18n.t("attributes.thread.summary")).capitalize()
toJSON: -> thread: @attributes
- getAttrInSourceLanguage: (attr_name) -> @get("#{attr_name}_in_source_language")
- getAttrAsHtml: (attr_name) -> @get(attr_name) || ('<em>' + @getAttrInSourceLanguage(attr_name) + '</em>')
+ getAttrInSourceLocale: (attr_name) -> @get("#{attr_name}_in_source_locale")
+ getAttrAsHtml: (attr_name) -> @get(attr_name) || ('<em>' + @getAttrInSourceLocale(attr_name) + '</em>')
getId: -> @id
getTitle: -> @get('title')
- getTitleInSourceLanguage: -> @getAttrInSourceLanguage('title')
+ getTitleInSourceLocale: -> @getAttrInSourceLocale('title')
getTitleAsHtml: -> @getAttrAsHtml('title')
getSummary: -> @get('summary')
- getSummaryInSourceLanguage: -> @getAttrInSourceLanguage('summary')
+ getSummaryInSourceLocale: -> @getAttrInSourceLocale('summary')
getSummaryAsHtml: -> @getAttrAsHtml('summary')
getCreatedAt: -> @toDateStr(@get('created_at'))
- getSourceLanguage: -> @get('source_language')
+ getSourceLocale: -> @get('source_locale')
getUserName: -> @get('user').name
getUserFullname: -> @get('user').fullname
getUserAvatarUrl: -> @get('user').avatar_url
View
20 app/models/cothread.rb
@@ -1,5 +1,5 @@
class Cothread < ActiveRecord::Base
- attr_accessible :title, :summary, :source_language
+ attr_accessible :title, :summary, :source_locale
#scopes
scope :recent, lambda { order("created_at DESC") }
@@ -8,8 +8,8 @@ class Cothread < ActiveRecord::Base
#validations
validates :user, :presence => true
- validates :title, :presence => true, :if => :in_source_language?
- validates :source_language, :presence => :true
+ validates :title, :presence => true, :if => :in_source_locale?
+ validates :source_locale, :presence => :true
#callbacks
before_validation :default_values
@@ -17,27 +17,27 @@ class Cothread < ActiveRecord::Base
#associations
belongs_to :user
- def in_source_language?
- (source_language == Globalize.locale.to_s) or (source_language == nil)
+ def in_source_locale?
+ (source_locale == Globalize.locale.to_s) or (source_locale == nil)
end
def as_json(options = {})
- super(options.merge(:only => [:id, :title, :summary, :created_at, :updated_at, :source_language],
+ super(options.merge(:only => [:id, :title, :summary, :created_at, :updated_at, :source_locale],
:include => [ :user ],
- :methods => [ :title_in_source_language, :summary_in_source_language ]))
+ :methods => [ :title_in_source_locale, :summary_in_source_locale ]))
end
# define locale helper methods for translated attributes
translated_attribute_names.each do |attr|
- define_method("#{attr}_in_source_language") do
- read_attribute attr, { :locale => source_language }
+ define_method("#{attr}_in_source_locale") do
+ read_attribute attr, { :locale => source_locale }
end
end
private
def default_values
- self.source_language ||= I18n.locale.to_s
+ self.source_locale ||= I18n.locale.to_s
end
end
View
9 db/migrate/20120715131851_rename_source_language_to_source_locale.rb
@@ -0,0 +1,9 @@
+class RenameSourceLanguageToSourceLocale < ActiveRecord::Migration
+ def up
+ rename_column :cothreads, :source_language, :source_locale
+ end
+
+ def down
+ rename_column :cothreads, :source_locale, :source_language
+ end
+end
View
8 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120602070944) do
+ActiveRecord::Schema.define(:version => 20120715131851) do
create_table "authorizations", :force => true do |t|
t.string "provider"
@@ -34,10 +34,10 @@
add_index "cothread_translations", ["locale"], :name => "index_cothread_translations_on_locale"
create_table "cothreads", :force => true do |t|
- t.string "source_language", :limit => 2
+ t.string "source_locale", :limit => 2
t.integer "user_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
View
40 spec/javascripts/models/thread_spec.js.coffee
@@ -31,14 +31,14 @@ describe 'App.Thread', ->
@thread.set(
'title': 'title'
'summary': 'summary'
- 'source_language': 'source_language'
+ 'source_locale': 'source_locale'
)
it 'wraps JSON in thread object', ->
expect(@thread.toJSON().thread).toBeDefined()
expect(@thread.toJSON().thread.title).toEqual('title')
expect(@thread.toJSON().thread.summary).toEqual('summary')
- expect(@thread.toJSON().thread.source_language).toEqual('source_language')
+ expect(@thread.toJSON().thread.source_locale).toEqual('source_locale')
describe '#getId', ->
it 'is defined', -> expect(@thread.getId).toBeDefined()
@@ -50,14 +50,14 @@ describe 'App.Thread', ->
@thread.id = 66;
expect(@thread.getId()).toEqual(66)
- describe '#getAttrInSourceLanguage', ->
- it 'is defined', -> expect(@thread.getAttrInSourceLanguage).toBeDefined()
+ describe '#getAttrInSourceLocale', ->
+ it 'is defined', -> expect(@thread.getAttrInSourceLocale).toBeDefined()
- it 'returns value for the attr_in_source_language helper method', ->
+ it 'returns value for the attr_in_source_locale helper method', ->
stub = sinon.stub(@thread, 'get').returns('Attribute in source language')
- expect(@thread.getAttrInSourceLanguage('attribute')).toEqual('Attribute in source language')
- expect(stub).toHaveBeenCalledWith('attribute_in_source_language')
+ expect(@thread.getAttrInSourceLocale('attribute')).toEqual('Attribute in source language')
+ expect(stub).toHaveBeenCalledWith('attribute_in_source_locale')
describe '#getAttrAsHtml', ->
it 'is defined', -> expect(@thread.getAttrAsHtml).toBeDefined()
@@ -68,16 +68,16 @@ describe 'App.Thread', ->
expect(@thread.getAttrAsHtml('attribute')).toEqual('Attribute')
expect(stub).toHaveBeenCalledWith('attribute')
- expect(stub).not.toHaveBeenCalledWith('attribute_in_source_language')
+ expect(stub).not.toHaveBeenCalledWith('attribute_in_source_locale')
- it 'returns value for attribute_in_source_language in italics if attribute is undefined', ->
+ it 'returns value for attribute_in_source_locale in italics if attribute is undefined', ->
stub = sinon.stub(@thread, 'get')
stub.withArgs('attribute').returns(undefined)
- stub.withArgs('attribute_in_source_language').returns('Attribute in source language')
+ stub.withArgs('attribute_in_source_locale').returns('Attribute in source language')
expect(@thread.getAttrAsHtml('attribute')).toEqual('<em>Attribute in source language</em>')
expect(stub).toHaveBeenCalledWith('attribute')
- expect(stub).toHaveBeenCalledWith('attribute_in_source_language')
+ expect(stub).toHaveBeenCalledWith('attribute_in_source_locale')
describe '#getTitle', ->
it 'is defined', -> expect(@thread.getTitle).toBeDefined()
@@ -110,14 +110,14 @@ describe 'App.Thread', ->
stub = sinon.stub(@thread, 'get').returns(undefined)
expect(@thread.getCreatedAt()).toEqual(undefined)
- describe '#getSourceLanguage', ->
- it 'is defined', -> expect(@thread.getSourceLanguage).toBeDefined()
+ describe '#getSourceLocale', ->
+ it 'is defined', -> expect(@thread.getSourceLocale).toBeDefined()
- it 'returns value for the source_language attribute', ->
+ it 'returns value for the source_locale attribute', ->
stub = sinon.stub(@thread, 'get').returns('ja')
- expect(@thread.getSourceLanguage()).toEqual('ja')
- expect(stub).toHaveBeenCalledWith('source_language')
+ expect(@thread.getSourceLocale()).toEqual('ja')
+ expect(stub).toHaveBeenCalledWith('source_locale')
describe '#getUserName', ->
it 'is defined', -> expect(@thread.getUserName).toBeDefined()
@@ -185,14 +185,14 @@ describe 'App.Thread', ->
@thread.save
title: 'Co-working spaces in Tokyo',
summary: 'I\'m collecting blog posts on co-working spaces in Tokyo.'
- source_language: 'en'
+ source_locale: 'en'
request = @server.requests[0]
params = JSON.parse(request.requestBody)
expect(params.thread).toBeDefined()
expect(params.thread.title).toEqual('Co-working spaces in Tokyo')
expect(params.thread.summary).toEqual('I\'m collecting blog posts on co-working spaces in Tokyo.')
- expect(params.thread.source_language).toEqual('en')
+ expect(params.thread.source_locale).toEqual('en')
describe 'on create', ->
beforeEach ->
@@ -245,5 +245,5 @@ describe 'App.Thread', ->
.toEqual(@fixture.summary)
expect(@thread.getCreatedAt())
.toEqual(@thread.toDateStr(@fixture.created_at))
- expect(@thread.getSourceLanguage())
- .toEqual(@fixture.source_language)
+ expect(@thread.getSourceLocale())
+ .toEqual(@fixture.source_locale)
View
6 spec/javascripts/support/fixtures.js.coffee
@@ -6,7 +6,7 @@ beforeEach ->
valid:
"created_at":"1337829167"
"id":5
- "source_language":"en"
+ "source_locale":"en"
"title":"Co-working spaces in Tokyo"
"summary":"I'm collecting blog posts on co-working spaces in Tokyo."
"user":
@@ -18,7 +18,7 @@ beforeEach ->
{
id: 1
created_at: "1337829500"
- source_language: "en"
+ source_locale: "en"
title: "Co-working spaces in Tokyo"
summary: "I'm collecting blog posts on co-working spaces in Tokyo."
user:
@@ -28,7 +28,7 @@ beforeEach ->
{
id: 2
created_at: "1337829777"
- source_language: "en"
+ source_locale: "en"
title: "Geisha bloggers"
summary: "Anyone know any geisha bloggers?"
user:
View
2  spec/javascripts/views/threads/new_thread_spec.js.coffee
@@ -96,7 +96,7 @@ describe "App.NewThreadView", ->
@server.respondWith(
'POST',
'/en/threads',
- [ 200, {'Content-Type': 'application/json'},'{"created_at":1339766056,"id":123,"source_language":"en","summary":"a summary","title":"a title","updated_at":1339766056,"user":{"fullname":"Cojiro Sasaki","id":1,"location":"Tokyo","name":"csasaki","profile":"A profile.","avatar_url":"/uploads/avatars/1/60v5906zg8b8bvp3nd9z.png","avatar_mini_url":"/uploads/avatars/1/mini_60v5906zg8b8bvp3nd9z.png"}}']
+ [ 200, {'Content-Type': 'application/json'},'{"created_at":1339766056,"id":123,"source_locale":"en","summary":"a summary","title":"a title","updated_at":1339766056,"user":{"fullname":"Cojiro Sasaki","id":1,"location":"Tokyo","name":"csasaki","profile":"A profile.","avatar_url":"/uploads/avatars/1/60v5906zg8b8bvp3nd9z.png","avatar_mini_url":"/uploads/avatars/1/mini_60v5906zg8b8bvp3nd9z.png"}}']
)
sinon.stub(App.appRouter, 'navigate')
@view.$('form input[name="title"]').val("a title")
View
24 spec/models/cothread_spec.rb
@@ -41,9 +41,9 @@
end
it "sets default source language" do
- @cothread.source_language = nil
+ @cothread.source_locale = nil
@cothread.save
- @cothread.source_language.should == "en"
+ @cothread.source_locale.should == "en"
end
end
@@ -57,10 +57,10 @@
shared_examples_for "attribute with locale methods" do |attr_name|
- it "has #{attr_name}_in_source_language method" do
+ it "has #{attr_name}_in_source_locale method" do
I18n.with_locale(:ja) do
@cothread.send(attr_name).should == nil
- @cothread.send("#{attr_name}_in_source_language").should == "a #{attr_name} in English"
+ @cothread.send("#{attr_name}_in_source_locale").should == "a #{attr_name} in English"
end
end
@@ -92,16 +92,16 @@
JSON(@cothread_json)["title"].should be
end
- it "has a title_in_source_language" do
- JSON(@cothread_json)["title_in_source_language"].should be
+ it "has a title_in_source_locale" do
+ JSON(@cothread_json)["title_in_source_locale"].should be
end
it "has a summary" do
JSON(@cothread_json)["summary"].should be
end
- it "has a summary_in_source_language" do
- JSON(@cothread_json)["summary_in_source_language"].should be
+ it "has a summary_in_source_locale" do
+ JSON(@cothread_json)["summary_in_source_locale"].should be
end
it "has created_at and updated_at timestamps" do
@@ -110,7 +110,7 @@
end
it "has a source language" do
- JSON(@cothread_json)["source_language"].should be
+ JSON(@cothread_json)["source_locale"].should be
end
it "includes user" do
@@ -127,12 +127,12 @@
JSON(@cothread_json).keys.delete_if { |k|
[ "id",
"title",
- "title_in_source_language",
+ "title_in_source_locale",
"summary",
- "summary_in_source_language",
+ "summary_in_source_locale",
"created_at",
"updated_at",
- "source_language",
+ "source_locale",
"user"
].include?(k)
}.should be_empty
View
14 spec/requests/cothreads_api_spec.rb
@@ -6,13 +6,13 @@
@bob = FactoryGirl.create(:bob)
Timecop.freeze(Time.utc(2002,7,20,12,20)) do
- @cothread1 = FactoryGirl.create(:cothread, :title => "An old post", :summary => "summary 1", :source_language => "ja", :user => @alice)
+ @cothread1 = FactoryGirl.create(:cothread, :title => "An old post", :summary => "summary 1", :source_locale => "ja", :user => @alice)
end
Timecop.freeze(Time.utc(2012,7,20,12,20)) do
- @cothread2 = FactoryGirl.create(:cothread, :title => "A very recent post", :summary => "summary 3", :source_language => "ja", :user => @alice)
+ @cothread2 = FactoryGirl.create(:cothread, :title => "A very recent post", :summary => "summary 3", :source_locale => "ja", :user => @alice)
end
Timecop.freeze(Time.utc(2005,7,20,12,20)) do
- @cothread3 = FactoryGirl.create(:cothread, :title => "A somewhat recent post", :summary => "summary 2", :source_language => "en", :user => @bob)
+ @cothread3 = FactoryGirl.create(:cothread, :title => "A somewhat recent post", :summary => "summary 2", :source_locale => "en", :user => @bob)
end
end
@@ -26,21 +26,21 @@
@json[0].should include(
"title" => "A very recent post",
"summary" => "summary 3",
- "source_language" => "ja",
+ "source_locale" => "ja",
"created_at" => "2012-07-20T12:20:00Z",
"updated_at" => "2012-07-20T12:20:00Z",
)
@json[1].should include(
"title" => "A somewhat recent post",
"summary" => "summary 2",
- "source_language" => "en",
+ "source_locale" => "en",
"created_at" => "2005-07-20T12:20:00Z",
"updated_at" => "2005-07-20T12:20:00Z"
)
@json[2].should include(
"title" => "An old post",
"summary" => "summary 1",
- "source_language" => "ja",
+ "source_locale" => "ja",
"created_at" => "2002-07-20T12:20:00Z",
"updated_at" => "2002-07-20T12:20:00Z"
)
@@ -75,7 +75,7 @@
@json.should include(
"title" => "An old post",
"summary" => "summary 1",
- "source_language" => "ja",
+ "source_locale" => "ja",
"created_at" => "2002-07-20T12:20:00Z",
"updated_at" => "2002-07-20T12:20:00Z"
)
Please sign in to comment.
Something went wrong with that request. Please try again.