Skip to content

Commit

Permalink
Remove localized (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
andriusch authored Jan 19, 2023
1 parent 2103414 commit c26345d
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 280 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Drop support for taking `model` as first argument in default/readonly/enum/normalize. This means that `default: -> (model) { model.other_field}` is no longer supported and should be replaced with `default: -> { other_field }`.
* Add support for evaluating `Symbol` for readonly/enum/normalize. If symbol is passed in one of those options, method with that name will be called when evaluating the value.
* Remove `localized` attribute type.

## v0.3.0

Expand Down
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,6 @@ end

The keys list might be restricted with the `:keys` option. Default and enum modifiers are applied on each value, normalizers are applied on the hash.

#### Localized

`localized` is similar to how `Globalize 3` attributes work.

```ruby
localized :title, String
```

#### Represents

`represents` provides an easy way to expose model attributes through an interface.
Expand Down
1 change: 0 additions & 1 deletion lib/granite/form/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require 'granite/form/model/primary'
require 'granite/form/model/persistence'
require 'granite/form/model/associations'
require 'granite/form/model/localization'
require 'granite/form/model/representation'
require 'granite/form/model/dirty'

Expand Down
44 changes: 0 additions & 44 deletions lib/granite/form/model/attributes/localized.rb

This file was deleted.

45 changes: 0 additions & 45 deletions lib/granite/form/model/attributes/reflections/localized.rb

This file was deleted.

26 changes: 0 additions & 26 deletions lib/granite/form/model/localization.rb

This file was deleted.

103 changes: 0 additions & 103 deletions spec/granite/form/model/attributes/localized_spec.rb

This file was deleted.

37 changes: 0 additions & 37 deletions spec/granite/form/model/attributes/reflections/localized_spec.rb

This file was deleted.

16 changes: 6 additions & 10 deletions spec/granite/form/model/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
let(:model) do
stub_model do
include Granite::Form::Model::Associations
include Granite::Form::Model::Localization

attribute :id, Integer
attribute :full_name, String
alias_attribute :name, :full_name

localized :t, String
alias_attribute :title, :t

embeds_one(:author) {}
embeds_many(:projects) {}
end
Expand All @@ -34,8 +30,8 @@

describe '.attribute_names' do
specify { expect(stub_model.attribute_names).to eq([]) }
specify { expect(model.attribute_names).to eq(%w[id full_name t author projects]) }
specify { expect(model.attribute_names(false)).to eq(%w[id full_name t]) }
specify { expect(model.attribute_names).to eq(%w[id full_name author projects]) }
specify { expect(model.attribute_names(false)).to eq(%w[id full_name]) }
end

describe '.inspect' do
Expand Down Expand Up @@ -100,8 +96,8 @@

describe '#attribute_names' do
specify { expect(stub_model.new.attribute_names).to eq([]) }
specify { expect(model.new.attribute_names).to eq(%w[id full_name t author projects]) }
specify { expect(model.new.attribute_names(false)).to eq(%w[id full_name t]) }
specify { expect(model.new.attribute_names).to eq(%w[id full_name author projects]) }
specify { expect(model.new.attribute_names(false)).to eq(%w[id full_name]) }
end

describe '#attribute_present?' do
Expand All @@ -114,11 +110,11 @@
specify { expect(stub_model.new.attributes).to eq({}) }
specify do
expect(model.new(name: 'Name').attributes)
.to match('id' => nil, 'full_name' => 'Name', 't' => {}, 'author' => nil, 'projects' => nil)
.to match('id' => nil, 'full_name' => 'Name', 'author' => nil, 'projects' => nil)
end
specify do
expect(model.new(name: 'Name').attributes(false))
.to match('id' => nil, 'full_name' => 'Name', 't' => {})
.to match('id' => nil, 'full_name' => 'Name')
end
end

Expand Down
6 changes: 0 additions & 6 deletions spec/granite/form/model/dirty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
stub_class(:author, ActiveRecord::Base) {}
stub_model :premodel do
include Granite::Form::Model::Persistence
include Granite::Form::Model::Localization
include Granite::Form::Model::Associations

attribute :age, Integer, default: 33
Expand All @@ -22,7 +21,6 @@
attribute :name, String
alias_attribute :n, :name
collection :numbers, Integer
localized :title, String
end
end

Expand Down Expand Up @@ -70,10 +68,6 @@
specify { expect(Model.new(a: '42').tap { |m| m.update(a: '43') }.changes).to eq('age' => [33, 43]) }
specify { expect(Model.new(numbers: '42').changes).to eq('numbers' => [[], [42]]) }

# Have no idea how should it work right now
specify { expect(Model.new(title: 'Hello').changes).to eq('title' => [nil, 'Hello']) }
specify { expect(Model.new(title_translations: {en: 'Hello'}).changes).to eq('title' => [nil, 'Hello']) }

specify { expect(Model.new).not_to respond_to :something_changed? }
specify { expect(Model.new).to respond_to :n_changed? }

Expand Down

0 comments on commit c26345d

Please sign in to comment.