Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the 'class_icon' method because we could not use an icon named 'class' #26

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/models/material_icon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ class MaterialIcon

# Undefined method will ref to the icon.
def method_missing(name)
@icon = clear_icon(name)
@icon =
if name == :class_icon
'class' # Set the icon named 'class'
else
clear_icon(name)
end
self
end

Expand Down
23 changes: 23 additions & 0 deletions spec/models/material_icon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@
end
end

# Class icon
describe '#class_icon' do

it 'should set the class icon when the method has no params' do
mi = MaterialIcon.new
# Set the icon and style
res = mi.class_icon
# Check icon
expect(mi.instance_variable_get('@icon')).to eq 'class'
expect(res.class).to eq MaterialIcon
end

it 'should set the class icon and style' do
mi = MaterialIcon.new
css_style = 'margin-top: 10px;'
# Set the icon and style
mi.class_icon.style css_style
# Check icon
expect(mi.instance_variable_get('@icon')).to eq 'class'
expect(mi.instance_variable_get('@style')).to eq css_style
end
end

# Array join must be executed without any bug
describe '#to_str' do

Expand Down