WIP attempt to create new profile for conference
This commit is contained in:
parent
a1a3155e0b
commit
7a8bba1646
|
@ -18,19 +18,30 @@ module Management
|
||||||
@conference = find_conference
|
@conference = find_conference
|
||||||
@user = find_user
|
@user = find_user
|
||||||
@profile = @user.personal_profile(@conference)
|
@profile = @user.personal_profile(@conference)
|
||||||
|
|
||||||
|
if not @profile
|
||||||
|
flash[:error] = "No profile, needs to be created"
|
||||||
|
redirect_to action: :edit
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@conference = find_conference
|
@conference = find_conference
|
||||||
@user = find_user
|
@user = find_user
|
||||||
@profile = @user.personal_profile(@conference)
|
@profile = @user.personal_profile(@conference)
|
||||||
|
|
||||||
|
# TODO (2015-07-26) Totally not working, can't create new profile properly
|
||||||
|
if not @profile
|
||||||
|
@profile = @user.clone_recent_profile(@conference)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@conference = find_conference
|
||||||
@user = find_user
|
@user = find_user
|
||||||
|
|
||||||
if @user.update_attributes(user_params)
|
if @user.update_attributes(user_params)
|
||||||
redirect_to [:management, @user]
|
redirect_to [:management, @conference, @user]
|
||||||
else
|
else
|
||||||
render action: 'edit'
|
render action: 'edit'
|
||||||
end
|
end
|
||||||
|
@ -56,7 +67,7 @@ module Management
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(
|
params.require(:user).permit(
|
||||||
:email,
|
:email,
|
||||||
personal_profile_attributes: [
|
personal_profiles_attributes: [
|
||||||
:picture,
|
:picture,
|
||||||
:first_name,
|
:first_name,
|
||||||
:last_name,
|
:last_name,
|
||||||
|
|
|
@ -12,4 +12,8 @@ class Event < ActiveRecord::Base
|
||||||
validates :agreement, acceptance: true
|
validates :agreement, acceptance: true
|
||||||
|
|
||||||
scope :confirmed, -> { where.not confirmed_at: nil }
|
scope :confirmed, -> { where.not confirmed_at: nil }
|
||||||
|
|
||||||
|
def proposer_profile
|
||||||
|
proposer.personal_profile(conference)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,15 +9,28 @@ class User < ActiveRecord::Base
|
||||||
has_many :workshops
|
has_many :workshops
|
||||||
has_many :events
|
has_many :events
|
||||||
|
|
||||||
accepts_nested_attributes_for :personal_profiles, update_only: true
|
accepts_nested_attributes_for :personal_profiles
|
||||||
|
|
||||||
default_scope { order id: :desc }
|
default_scope { order id: :desc }
|
||||||
|
|
||||||
def personal_profile(conference)
|
def personal_profile(conference)
|
||||||
personal_profiles.find_by!(conference_id: conference.id)
|
personal_profiles.find_by(conference_id: conference.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_admin!
|
def toggle_admin!
|
||||||
update admin: !admin
|
update admin: !admin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clone_recent_profile(new_conference)
|
||||||
|
recent_profile = personal_profiles.order('created_at DESC').first
|
||||||
|
|
||||||
|
personal_profiles.build(conference: new_conference) do |new_profile|
|
||||||
|
if recent_profile.present?
|
||||||
|
new_profile.attributes = recent_profile.attributes.except(
|
||||||
|
"id", "created_at", "updated_at", "conference_id"
|
||||||
|
)
|
||||||
|
new_profile.remote_picture_url = recent_profile.picture.url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
tbody
|
tbody
|
||||||
- @events.each do |event|
|
- @events.each do |event|
|
||||||
- proposer = event.proposer
|
- proposer = event.proposer
|
||||||
|
- proposer_profile = event.proposer_profile
|
||||||
|
|
||||||
tr
|
tr
|
||||||
td= event.title
|
td= event.title
|
||||||
td= event.subtitle
|
td= event.subtitle
|
||||||
td= link_to proposer.personal_profile(@conference).name, [:management, @conference, proposer]
|
td= link_to proposer_profile.name, [:management, @conference, proposer]
|
||||||
td #{event.length} minutes
|
td #{event.length} minutes
|
||||||
td= event.language
|
td= event.language
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,13 @@
|
||||||
hr
|
hr
|
||||||
.row
|
.row
|
||||||
.col-lg-12
|
.col-lg-12
|
||||||
-# TODO we have many personal_profiles now
|
= f.simple_fields_for :personal_profiles do |ff|
|
||||||
= f.simple_fields_for :personal_profile do |ff|
|
= ff.object.inspect
|
||||||
- if @profile.picture.present?
|
- next if ff.object.conference != @conference
|
||||||
|
|
||||||
|
- if ff.object.picture.present?
|
||||||
.col-sm-offset-3.col-sm-9
|
.col-sm-offset-3.col-sm-9
|
||||||
= image_tag @profile.picture.medium.url, class: 'img-thumbnail'
|
= image_tag ff.object.picture.medium.url, class: 'img-thumbnail'
|
||||||
|
|
||||||
= ff.input :picture, wrapper: :horizontal_file_input
|
= ff.input :picture, wrapper: :horizontal_file_input
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ module Clarion
|
||||||
config.i18n.available_locales = [:bg, :en]
|
config.i18n.available_locales = [:bg, :en]
|
||||||
config.i18n.default_locale = :bg
|
config.i18n.default_locale = :bg
|
||||||
|
|
||||||
|
config.active_record.raise_in_transactional_callbacks = true
|
||||||
|
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.test_framework :rspec, fixtures: true,
|
g.test_framework :rspec, fixtures: true,
|
||||||
view_specs: false,
|
view_specs: false,
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
FactoryGirl.define do
|
||||||
|
factory :personal_profile do
|
||||||
|
association :user
|
||||||
|
|
||||||
|
first_name "Some"
|
||||||
|
last_name "Person"
|
||||||
|
picture File.open(Rails.root.join("spec/support/picture.jpg"))
|
||||||
|
mobile_phone "0883 123 456"
|
||||||
|
biography "Biography"
|
||||||
|
sequence(:public_email) { |n| "email#{n}@example.com" }
|
||||||
|
twitter "example"
|
||||||
|
github "example"
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,4 +4,28 @@ RSpec.describe User do
|
||||||
it 'lets Devise handle email and password validations' do
|
it 'lets Devise handle email and password validations' do
|
||||||
expect(build(:user)).to be_a Devise::Models::Validatable
|
expect(build(:user)).to be_a Devise::Models::Validatable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can clone a previous profile for use in a different conference" do
|
||||||
|
user = create :user
|
||||||
|
old_conference = create :conference
|
||||||
|
new_conference = create :conference
|
||||||
|
|
||||||
|
old_profile = create :personal_profile, {
|
||||||
|
user: user,
|
||||||
|
biography: "Old profile bio",
|
||||||
|
conference: old_conference
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(user.personal_profile(old_conference)).to eq old_profile
|
||||||
|
expect(user.personal_profile(new_conference)).to be_nil
|
||||||
|
|
||||||
|
new_profile = user.clone_recent_profile(new_conference)
|
||||||
|
expect(new_profile.biography).to eq old_profile.biography
|
||||||
|
|
||||||
|
user.reload
|
||||||
|
user.personal_profiles << new_profile
|
||||||
|
|
||||||
|
expect(user.personal_profile(old_conference)).to eq old_profile
|
||||||
|
expect(user.personal_profile(new_conference)).to eq new_profile
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue