Skip to content

Admin organizations order #361

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

Merged
merged 6 commits into from
Aug 8, 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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: ruby
sudo: required
cache: bundler
bundler_args: '--without production development'
rvm:
Expand Down
2 changes: 1 addition & 1 deletion app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
end
f.inputs "Members" do
f.has_many :members do |m|
m.input :organization
m.input :organization, collection: Organization.order(id: :asc).pluck(:name, :id)
m.input :manager
end
end
Expand Down
26 changes: 20 additions & 6 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ module ApplicationHelper
# from gravatar
def avatar_url(user, size = 32)
gravatar_id = Digest::MD5::hexdigest(user.email).downcase
gravatar_options = Hash[set: "set1",
gravatar: "hashed",
size: "#{size}x#{size}"]
"https://www.gravatar.com/avatar/#{gravatar_id}.png?" +
"#{Rack::Utils.build_query(gravatar_options)}&d=identicon"
gravatar_options = {
set: "set1",
gravatar: "hashed",
size: "#{size}x#{size}",
d: "identicon"
}

"https://www.gravatar.com/avatar/#{gravatar_id}.png?#{gravatar_options.to_param}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

Copy link
Collaborator

@sauloperez sauloperez May 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mean to do it now but these are the kind of things that I like to turn into a value object. And this will eventually reduce the amount of helpers. Just a thought worth sharing.

end

def mdash
Expand Down Expand Up @@ -38,7 +41,7 @@ def show_error_messages!(resource)
messages = resource.errors.
full_messages.map { |msg| content_tag(:li, msg) }.join
html = <<-HTML
<div class="alert alert-error alert-block">
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">x</button>
<ul>
#{messages}
Expand Down Expand Up @@ -80,4 +83,15 @@ def get_body_css_class(controller)

"#{classes[controller]}"
end

def alert_class(alert)
case alert
when 'error', 'alert'
'alert-danger'
when 'notice'
'alert-success'
else
'alert-info'
end
end
Copy link
Collaborator Author

@markets markets Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mllocs what do you think? specially this commit: 761c7ff 😄 I also fixed the css error class returned by show_error_messages!, now in develop looks like:

captura de pantalla 2018-06-21 a la s 22 04 56

end
2 changes: 0 additions & 2 deletions app/helpers/categories_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/devise_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/global_helper.rb

This file was deleted.

13 changes: 0 additions & 13 deletions app/helpers/messages_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/organizations_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/sessions_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/tags_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
module UsersHelper
private

def edit_user_path(user)
can_edit_user?(user) ? super : ""
end
Expand Down
10 changes: 5 additions & 5 deletions app/views/layouts/_messages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

<div class="alert <%= alert_class(key) %>">
<button type="button" class="close" data-dismiss="alert">x</button>
<ul>
<li>
<%= value %>
</li>
</ul>
<ul>
<li>
<%= value %>
</li>
</ul>
</div>
<% end %>
2 changes: 1 addition & 1 deletion config/initializers/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
config.error_notification_tag = :div

# CSS class to add for error notification helper.
config.error_notification_class = 'alert alert-error'
config.error_notification_class = 'alert alert-danger'

# ID to add for error notification helper.
# config.error_notification_id = nil
Expand Down
Empty file removed spec/helpers/.gitkeep
Empty file.
29 changes: 29 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

RSpec.describe ApplicationHelper do
it 'avatar_url returns url to gravatar' do
user = Fabricate(:user)
gravatar_id = Digest::MD5::hexdigest(user.email).downcase
expect(helper.avatar_url(user, 50)).to eq("https://www.gravatar.com/avatar/#{gravatar_id}.png?d=identicon&gravatar=hashed&set=set1&size=50x50")
end

describe 'seconds_to_hm' do
it 'with 0 returns em dash' do
expect(helper.seconds_to_hm(0)).to eq("&mdash;")
end

it 'with non-zero returns specific format' do
expect(helper.seconds_to_hm(10)).to eq("0:00")
expect(helper.seconds_to_hm(60)).to eq("0:01")
expect(helper.seconds_to_hm(-60)).to eq("-0:01")
expect(helper.seconds_to_hm(3600)).to eq("1:00")
end
end

it 'alert_class returns specific error classes' do
expect(helper.alert_class('error')).to eq('alert-danger')
expect(helper.alert_class('alert')).to eq('alert-danger')
expect(helper.alert_class('notice')).to eq('alert-success')
expect(helper.alert_class('foo')).to eq('alert-info')
end
end
14 changes: 14 additions & 0 deletions spec/helpers/glyph_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

RSpec.describe GlyphHelper do
describe 'glyph helper' do
it 'renders an span with glyphicon classes' do
expect(helper.glyph('foo')).to match(/<span class=\"glyphicon glyphicon-foo\"><\/span>/)
end

it 'special mappings' do
sample = GlyphHelper::GLYPHS.to_a.sample[0]
expect(helper.glyph(sample)).to match(GlyphHelper::GLYPHS[sample])
end
end
end
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
ENV["ADMINS"] = "superadmin@example.com"
ENV["ADMINS"] = "admin@timeoverflow.org"

require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Expand All @@ -11,6 +11,7 @@
require 'selenium/webdriver'
require 'faker'
require 'shoulda/matchers'

I18n.reload!

Capybara.register_driver :chrome do |app|
Expand All @@ -36,7 +37,7 @@
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

# Make sure schem persists when running tests.
# Make sure schema persists when running tests.
# We ran into an error that forced us to run rake db:migrate RAILS_ENV=test
# before running tests. This kind of fixes it, although we should have a closer
# look at this and find a better solution
Expand Down Expand Up @@ -75,7 +76,6 @@
feature_specs = items_by_type[:feature] || []
rest_of_specs = items_by_type[:rest] || []


random = Random.new(config.seed)

[
Expand Down