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 country field in profiles table #396 #469

Merged
merged 12 commits into from Sep 19, 2016
@@ -29,6 +29,8 @@ gem 'auto_html', github: 'dejan/auto_html'
gem 'postmark-rails', '>= 0.10.0'
gem 'simple_form', '~> 3.0.2'

gem 'country_select'

gem 'globalize', '~> 4.0.2'

gem 'font-awesome-rails', '~> 4.3.0.0'
@@ -74,9 +74,16 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
countries (1.2.5)
currencies (~> 0.4.2)
i18n_data (~> 0.7.0)
country_select (2.5.2)
countries (~> 1.2.0)
sort_alphabetical (~> 1.0)
css_parser (1.2.6)
addressable
rdoc
currencies (0.4.2)
database_cleaner (1.2.0)
deadweight (0.2.2)
css_parser (~> 1.2.6)
@@ -227,6 +234,7 @@ GEM
hashie (3.4.2)
hike (1.2.3)
i18n (0.7.0)
i18n_data (0.7.0)
inflecto (0.0.2)
ipaddress (0.8.0)
jquery-rails (3.1.3)
@@ -380,6 +388,8 @@ GEM
actionpack (~> 4.0)
activemodel (~> 4.0)
slop (3.6.0)
sort_alphabetical (1.0.2)
unicode_utils (>= 1.2.2)
sprockets (2.12.4)
hike (~> 1.2)
multi_json (~> 1.0)
@@ -403,6 +413,7 @@ GEM
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
unicode_utils (1.4.0)
unicorn (4.9.0)
kgio (~> 2.6)
rack
@@ -427,6 +438,7 @@ DEPENDENCIES
capybara (~> 2.4.1)
carrierwave
coffee-rails (~> 4.0.1)
country_select
database_cleaner (~> 1.2.0)
deadweight
devise (~> 3.1.1)
@@ -466,5 +478,8 @@ DEPENDENCIES
uglifier (>= 1.0.3)
unicorn

RUBY VERSION
ruby 2.2.3p173

BUNDLED WITH
1.11.2
1.12.5
@@ -83,6 +83,7 @@ def profile_params
:password_confirmation,
:remember_me,
:city,
:country,
:languages,
:firstname,
:lastname,
@@ -121,6 +121,7 @@ def as_json(_options = {})
'firstname',
'lastname',
'city',
'country',
'twitter',
'created_at',
'updated_at',
@@ -35,6 +35,11 @@ def detailed_search_result
.where("firstname || ' ' || lastname ILIKE :name", name: "%#{@query[:name]}%")
.where('twitter ILIKE :twitter', twitter: "%#{@query[:twitter]}%")

if @query[:country].present?
result = result
.where('country ILIKE :country', country: "%#{@query[:country]}%")
end

if @query[:languages].present? # && @query[:languages] =~ /[abc]{2}/
result = result
.where('languages ILIKE :iso_start OR
@@ -62,6 +62,15 @@
<%= @profile.city %></span>
</p>
<% end %>

<% if @profile.country.present? %>
<h2 class="delta sans-serif mb-">
<%= t(:country, scope: 'profiles.profile') %>
</h2>
<p class="bb pb">
<%= @profile.country %></span>

This comment has been minimized.

Copy link
@zaziemo

zaziemo Aug 15, 2016

Member

could you change the displayed information into the country name of the corresponding locale? Currently if I chose "Germany" as a country in the profile show action "DE" is displayed. It would be cool if I would see "Deutschland" in the german locale, "Germany" in the english and "Alemanha" (in the future Portuguese locale)

This comment has been minimized.

Copy link
@tyranja

tyranja Sep 5, 2016

Member

It is still looking the same. You might have to add that to the Profile Model: https://github.com/stefanpenner/country_select#getting-the-country-name-from-the-countries-gem

</p>
<% end %>
</div><!--
--><div class="layout__item 1/6 palm-1/1">
@@ -6,6 +6,8 @@
<%= f.input :email, input_html: { class: "mb input--width-100" } %>
<%= f.input :twitter, placeholder: '@', input_html: { class: "mb input--width-100" } %>
<%= f.input :city, input_html: { class: "mb input--width-100" } %>
<%= f.label :country %>
<%= f.country_select :country, label: t(:country, scope: 'activerecord.attributes.profile').html_safe, input_html: { class: "mb input--width-100" } %>
<%= f.input :languages, label: t(:languages, scope: 'activerecord.attributes.profile').html_safe, input_html: { class: "mb input--width-100" } %>
<%= f.input :website, placeholder: 'http://', input_html: { class: "mb input--width-100" } %>
<%= f.input :topic_list, label: t(:topic_list, scope: 'activerecord.attributes.profile').html_safe, input_html: { class: "mb input--width-100" } %>
@@ -56,6 +56,12 @@
</div>
</div>

<div class="control-group">
<%= label_tag('search[country]',t(:country, scope: 'profiles.index'), class: 'control-label') %>
<div class="controls">
<%= select_tag('search[country]', options_from_collection_for_select(ISO3166::Country.countries.sort_by(&:name), 'un_locode', 'name'), prompt: t(:any, scope: 'search')) %>
</div>
</div>
<div class="control-group pb">
<%= label_tag('search[languages]', t(:language, scope: 'profiles.index'), class: 'control-label') %>
<div class="controls">
@@ -187,6 +187,7 @@ de:
contact: "Kontakt"
website: "Meine Webseite/Blog:"
city: "Meine Stadt:"
country: "Mein Land"
twitter: "Mein Twittername:"
show: "Anzeigen"
edit: "Profil bearbeiten"
@@ -207,6 +208,7 @@ de:
twitter: "Twitter"
topics: "Themen"
city: "Stadt"
country: "Land"
language: "Sprache"
new:
new_profile: "Neues Profil"
@@ -254,6 +256,7 @@ de:
talks: "Vortragsthemen"
languages: 'Sprachen<br><small>Programmiersprachen bitte bei Themen angeben, nicht hier.</small>'
city: "Stadt"
country: "Land"
twitter: "Twitter"
picture: "Bild"
translation: "<strong>Hier kannst Du Dein Hauptthema und Deine Bio auf Deutsch und Englisch eintragen:</strong>"
@@ -187,6 +187,7 @@ en:
contact: "Contact"
website: "My website/blog:"
city: "My city:"
country: "My country"

This comment has been minimized.

Copy link
@zaziemo

zaziemo Aug 5, 2016

Member

could you also please add that field to the German locale? country: "Land"

twitter: "My twitter handle:"
show: "Show"
edit: "Edit profile"
@@ -207,6 +208,7 @@ en:
twitter: "Twitter"
topics: "Topics"
city: "City"
country: "Country"
language: "Language"
new:
new_profile: "New Profile"
@@ -252,6 +254,7 @@ en:
talks: "Talks"
languages: "Languages<br><small>Please add programming languages in 'Topics', not here</small>"
city: "City"
country: "Country"
twitter: "Twitter"
picture: "Picture"
translation: "<strong>You can fill in your maintopic and your bio both in German and English:</strong>"
@@ -0,0 +1,5 @@
class AddColumnToProfiles < ActiveRecord::Migration
def change
add_column :profiles, :country, :string
end
end
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160418192104) do
ActiveRecord::Schema.define(version: 20160728194836) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -124,6 +124,7 @@
t.string "website"
t.text "admin_comment"
t.string "slug"
t.string "country"
end

add_index "profiles", ["confirmation_token"], name: "index_profiles_on_confirmation_token", unique: true, using: :btree
@@ -8,6 +8,7 @@
email: "jane_doe#{i}@example.com",
languages: "Deutsch, English, Français",
city: "Berlin",
country: 'DE'
twitter: "@janedoe##{i}",
confirmed_at: DateTime.now,
published: true,
@@ -1,6 +1,6 @@
describe 'profile search' do
let!(:profile) { FactoryGirl.create(:published, firstname: 'Ada', lastname: 'Lovelace', city: 'London', twitter: 'Adalove', languages: 'Spanish, English') }
let!(:profile1) { FactoryGirl.create(:published, firstname: 'Marie', lastname: 'Curie', city: 'Paris', twitter: 'mcurie', languages: 'Polish, French') }
let!(:profile) { FactoryGirl.create(:published, firstname: 'Ada', lastname: 'Lovelace', city: 'London', country: 'GB', twitter: 'Adalove', languages: 'Spanish, English') }
let!(:profile1) { FactoryGirl.create(:published, firstname: 'Marie', lastname: 'Curie', city: 'Paris', country: 'FR', twitter: 'mcurie', languages: 'Polish, French') }
let!(:profile2) { FactoryGirl.create(:published, firstname: 'Christiane', lastname: 'Nüsslein-Volhard', city: 'Heidelberg', languages: 'German') }
let!(:profile3) { FactoryGirl.create(:published, firstname: 'Maren ', lastname: 'Meier') }

@@ -68,6 +68,14 @@
expect(page).to have_content('Ada')
end

it 'displays profiles that match of the selected country' do
within '#detailed-search' do
select 'United Kingdom', :from => 'Country'
click_button I18n.t(:search, scope: 'pages.home.search')
end
expect(page).to have_content('Ada')
end

it 'displays profiles that match any of the selected languages' do
within '#detailed-search' do
select 'Spanish', :from => 'Language'
@@ -1,7 +1,7 @@
describe ProfilesSearch, type: :model do
let!(:profile) { FactoryGirl.create(:published, firstname: 'Ada', lastname: 'Lovelace', twitter: 'alovelace', city: 'London', languages: 'English') }
let!(:profile) { FactoryGirl.create(:published, firstname: 'Ada', lastname: 'Lovelace', twitter: 'alovelace', city: 'London', country: 'GB', languages: 'English') }
# have to add city and twitter because the search needs them for params, at least as empty strings
let!(:profile2) { FactoryGirl.create(:published, firstname: 'Marie', lastname: 'Curie', twitter: 'marieecurie', city: 'Paris') }
let!(:profile2) { FactoryGirl.create(:published, firstname: 'Marie', lastname: 'Curie', twitter: 'marieecurie', city: 'Paris', country: 'FR') }

let!(:profile_not_matched) { FactoryGirl.create(:published, firstname: 'Angela', lastname: 'Davis') }
let!(:profile_not_published) { FactoryGirl.create(:unpublished, firstname: 'Fred') }
@@ -86,7 +86,7 @@
end

it 'does return nothing if detailed search is empty' do
expect(ProfilesSearch.new(topics: '', twitter: '', name: '', city: '', languages: '').results).to be_empty
expect(ProfilesSearch.new(topics: '', twitter: '', name: '', city: '', country: '', languages: '').results).to be_empty
end
end
end
@@ -9,6 +9,7 @@
main_topic: 'first computer programm',
bio: 'first programmer',
city: 'London',
country: 'UK',
languages: 'english, french',
topic_list: 'algorithm, mathematic'
)) }
@@ -28,6 +29,7 @@
expect(page).to have_content('Lovelace')
expect(page).to have_content('@alove')
expect(page).to have_content('London')
expect(page).to have_content('UK')
expect(page).to have_content('first programmer')
expect(page).to have_content('first computer programm')
expect(page).to have_content('algorithm')
@@ -3,7 +3,7 @@
Capybara.javascript_driver = :poltergeist

describe 'profile search', type: :view do
let!(:ada) { FactoryGirl.create(:published, firstname: 'Ada', lastname: 'Lovelace', city: 'London', twitter: 'Adalove', languages: "Spanish, English") }
let!(:ada) { FactoryGirl.create(:published, firstname: 'Ada', lastname: 'Lovelace', city: 'London', country: 'GB', twitter: 'Adalove', languages: "Spanish, English") }

context 'on startpage' do
before { visit root_path }
@@ -65,5 +65,4 @@
end
end
end

end
@@ -84,6 +84,7 @@ class ProfileTest < ActiveSupport::TestCase
'lastname' => 'Lovelace',
#'languages' => 'Deutsch',
'city' => 'New York',
'country' => nil,
'twitter' => 'alove',
'created_at' => '2014-12-06T15:04:13.000Z',
'updated_at' => '2014-12-06T15:04:20.000Z',
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.