-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New Field::Password * Modify the Customer Dashboard to show new field * Add field information in Customizing Dashboards documentation
- Loading branch information
1 parent
3609db5
commit 709b614
Showing
11 changed files
with
172 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<%# | ||
# Password Form Partial | ||
This partial renders an input element for a password attribute. | ||
By default, the input is a password field. | ||
## Local variables: | ||
- `f`: | ||
A Rails form generator, used to help create the appropriate input fields. | ||
- `field`: | ||
An instance of [Administrate::Field::Password][1]. | ||
A wrapper around the Password. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Password | ||
%> | ||
|
||
<div class="field-unit__label"> | ||
<%= f.label field.attribute %> | ||
</div> | ||
<div class="field-unit__field"> | ||
<%= f.password_field field.attribute, value: field.data %> | ||
</div> |
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,18 @@ | ||
<%# | ||
# Password Index Partial | ||
This partial renders a password attribute | ||
to be displayed on a resource's index page. | ||
By default, the attribute is rendered as a truncated string. | ||
## Local variables: | ||
- `field`: | ||
An instance of [Administrate::Field::Password][1]. | ||
A wrapper around the Password. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Password | ||
%> | ||
|
||
<%= field.truncate %> |
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,18 @@ | ||
<%# | ||
# Password Show Partial | ||
This partial renders a password attribute, | ||
to be displayed on a resource's show page. | ||
By default, the attribute is rendered as an truncate string. | ||
## Local variables: | ||
- `field`: | ||
An instance of [Administrate::Field::Password][1]. | ||
A wrapper around the Password. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Password | ||
%> | ||
|
||
<%= field.truncate %> |
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,25 @@ | ||
require_relative "base" | ||
|
||
module Administrate | ||
module Field | ||
class Password < Field::Base | ||
def self.searchable? | ||
false | ||
end | ||
|
||
def truncate | ||
data.to_s.gsub(/./, character)[0...truncation_length] | ||
end | ||
|
||
private | ||
|
||
def truncation_length | ||
options.fetch(:truncate, 50) | ||
end | ||
|
||
def character | ||
options.fetch(:character, "•") | ||
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
5 changes: 5 additions & 0 deletions
5
spec/example_app/db/migrate/20171006144755_add_password_to_customers.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,5 @@ | ||
class AddPasswordToCustomers < ActiveRecord::Migration[4.2] | ||
def change | ||
add_column :customers, :password, :string | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require "administrate/field/password" | ||
require "support/field_matchers" | ||
|
||
describe Administrate::Field::Password do | ||
include FieldMatchers | ||
|
||
describe "#to_partial_path" do | ||
it "returns a partial based on the page being rendered" do | ||
page = :show | ||
field = Administrate::Field::Password.new(:password, "my_password", page) | ||
|
||
path = field.to_partial_path | ||
|
||
expect(path).to eq("/fields/password/#{page}") | ||
end | ||
end | ||
|
||
it { should_permit_param(:foo, for_attribute: :foo) } | ||
|
||
describe "#truncate" do | ||
it "renders an empty string for nil" do | ||
string = Administrate::Field::Password.new(:secret, nil, :show) | ||
|
||
expect(string.truncate).to eq("") | ||
end | ||
|
||
it "defaults to displaying up to 50 characters" do | ||
short = Administrate::Field::Password.new(:short_secret, lorem(30), :show) | ||
long = Administrate::Field::Password.new(:long_secret, lorem(60), :show) | ||
|
||
expect(short.truncate).to eq(lorem(30)) | ||
expect(long.truncate).to eq(lorem(50)) | ||
end | ||
|
||
context "with a `truncate` option" do | ||
it "shortens to the given length" do | ||
password = password_with_options(lorem(30), truncate: 20) | ||
|
||
expect(password.truncate).to eq(lorem(20)) | ||
end | ||
|
||
it "different to default character" do | ||
password = password_with_options(lorem(30), character: "*") | ||
|
||
expect(password.truncate).to eq(lorem(30, "*")) | ||
end | ||
|
||
it "shortens to the given length & different to default character" do | ||
password = password_with_options(lorem(30), | ||
truncate: 10, | ||
character: "-") | ||
|
||
expect(password.truncate).to eq(lorem(10, "-")) | ||
end | ||
end | ||
end | ||
|
||
def password_with_options(string, options) | ||
Administrate::Field::Password.new(:string, string, :page, options) | ||
end | ||
|
||
def lorem(n, character = "•") | ||
character * n | ||
end | ||
end |