forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/feature/proposal-editing-time-…
…hours-days' into feature/co-authorships-in-proposals
- Loading branch information
Showing
11 changed files
with
273 additions
and
14 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
9 changes: 3 additions & 6 deletions
9
decidim-admin/app/packs/src/decidim/admin/proposal_infinite_edit.js
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
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Attributes | ||
# Custom attributes value to represent an Integer with units. | ||
class IntegerWithUnits < ActiveModel::Type::Value | ||
def type | ||
:"decidim/attributes/integer_with_units" | ||
end | ||
|
||
def cast(value) | ||
return nil if value.nil? | ||
|
||
case value | ||
when ::Hash | ||
[value["0"].to_i.abs, value["1"].to_s] | ||
when ::Array | ||
return value if value.size != 2 | ||
|
||
[value[0].to_i.abs, value[1].to_s] | ||
else | ||
value | ||
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
69 changes: 69 additions & 0 deletions
69
decidim-core/spec/lib/attributes/integer_with_units_spec.rb
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,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
module Decidim | ||
describe Attributes::IntegerWithUnits do | ||
describe "#cast" do | ||
subject { described_class.new.cast(value) } | ||
|
||
describe "#cast" do | ||
context "when given nil" do | ||
let(:value) { nil } | ||
|
||
it "returns nil" do | ||
expect(subject).to be_nil | ||
end | ||
end | ||
|
||
context "when given a Hash" do | ||
let(:value) { { "0" => "5", "1" => "minutes" } } | ||
|
||
it "returns an array with the integer and the unit" do | ||
expect(subject).to eq([5, "minutes"]) | ||
end | ||
|
||
context "when the integer is negative" do | ||
let(:value) { { "0" => "-5", "1" => "minutes" } } | ||
|
||
it "returns an array with the absolute value of the integer and the unit" do | ||
expect(subject).to eq([5, "minutes"]) | ||
end | ||
end | ||
end | ||
|
||
context "when given an Array" do | ||
let(:value) { %w(5 minutes) } | ||
|
||
it "returns an array with the integer and the unit" do | ||
expect(subject).to eq([5, "minutes"]) | ||
end | ||
|
||
context "when the array size is not 2" do | ||
let(:value) { ["5"] } | ||
|
||
it "returns the original value" do | ||
expect(subject).to eq(["5"]) | ||
end | ||
end | ||
|
||
context "when the integer is negative" do | ||
let(:value) { %w(-5 minutes) } | ||
|
||
it "returns an array with the absolute value of the integer and the unit" do | ||
expect(subject).to eq([5, "minutes"]) | ||
end | ||
end | ||
end | ||
|
||
context "when given other values" do | ||
let(:value) { "some string" } | ||
|
||
it "returns the original value" do | ||
expect(subject).to eq("some string") | ||
end | ||
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
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
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
Oops, something went wrong.