Permalink
Browse files

Saner method for creating profiles.

  • Loading branch information...
1 parent 484fe77 commit 99cedf010ba487064b44a9b1d48544e7169acf0e @pwnall committed Feb 22, 2014
@@ -41,6 +41,10 @@ def show
# GET /_/profiles/new.xml
def new
@profile = Profile.new
+ unless current_user.profile
+ @profile.user = current_user
+ @profile.display_email = current_user.email
+ end
respond_to do |format|
format.html # new.html.erb
@@ -56,14 +60,14 @@ def edit
# POST /_/profiles.xml
def create
@profile = Profile.new profile_params
+ unless current_user.profile
+ @profile.user = current_user
+ end
respond_to do |format|
if @profile.save
if current_user.profile
AclEntry.set current_user, @profile, :edit
- else
- current_user.profile = @profile
- current_user.save!
end
FeedSubscription.add current_user.profile, @profile
@@ -16,8 +16,11 @@ def welcome
# Sets up the 'session/home' view. A user is logged in.
def home
# Pull information about the current user.
- @profile = current_user.profile ||
- Profile.new(display_email: current_user.email)
+ @profile = current_user.profile
+ unless @profile
+ redirect_to new_profile_url
+ return
+ end
end
private :home
@@ -5,7 +5,7 @@
<ol>
<li>
<%= header_user_image current_user %>
- <% if current_user.profile %>
+ <% if current_user.profile && current_user.profile.name %>
<%= link_to current_user.profile.name, current_user.profile %>
<% else %>
<%= current_user.email %>
@@ -1,47 +1,40 @@
-<% if !@profile.new_record? %>
- <div class="home_panel feed">
- <h2>News Feed</h2>
- <%= render 'feed_items/list',
- :feed_items => @profile.recent_subscribed_feed_items %>
- </div>
+<div class="home_panel feed">
+ <h2>News Feed</h2>
+ <%= render 'feed_items/list',
+ :feed_items => @profile.recent_subscribed_feed_items %>
+</div>
- <div class="home_panel repositories">
- <h2>Repositories</h2>
- <p class="actions">
- <%= link_to 'New Repository', new_repository_path, :class => 'button' %>
- </p>
- <%= render 'repositories/list', :repositories => @profile.repositories %>
+<div class="home_panel repositories">
+ <h2>Repositories</h2>
+ <p class="actions">
+ <%= link_to 'New Repository', new_repository_path, :class => 'button' %>
+ </p>
+ <%= render 'repositories/list', :repositories => @profile.repositories %>
- <h2>Team Repositories</h2>
- <%= render 'repositories/list', :repositories => @profile.user.team_repositories %>
- </div>
+ <h2>Team Repositories</h2>
+ <%= render 'repositories/list', :repositories => @profile.user.team_repositories %>
+</div>
- <div class="home_panel keys">
- <h2>SSH Keys</h2>
- <p class="actions">
- <%= link_to 'New Key', new_ssh_key_path, :class => 'button' %>
- </p>
- <% if @profile.user.ssh_keys.empty? %>
- <p>You have no SSH keys!</p>
- <p>
- <%= link_to 'Add a key', new_ssh_key_path %> to access your repositories
- via git.
- </p>
- <% else %>
- <%= render 'ssh_keys/list', :ssh_keys => @profile.user.ssh_keys %>
- <% end %>
- </div>
+<div class="home_panel keys">
+ <h2>SSH Keys</h2>
+ <p class="actions">
+ <%= link_to 'New Key', new_ssh_key_path, :class => 'button' %>
+ </p>
+ <% if @profile.user.ssh_keys.empty? %>
+ <p>You have no SSH keys!</p>
+ <p>
+ <%= link_to 'Add a key', new_ssh_key_path %> to access your repositories
+ via git.
+ </p>
+ <% else %>
+ <%= render 'ssh_keys/list', :ssh_keys => @profile.user.ssh_keys %>
+ <% end %>
+</div>
- <div class="home_panel teams">
- <h2>Teams</h2>
- <p class="actions">
- <%= link_to 'New Team', new_profile_path, :class => 'button' %>
- </p>
- <%= render 'profiles/list', :profiles => @profile.user.team_profiles %>
- </div>
-
-<% else %>
- <h2>Create a profile</h2>
-
- <%= render 'profiles/form' %>
-<% end %>
+<div class="home_panel teams">
+ <h2>Teams</h2>
+ <p class="actions">
+ <%= link_to 'New Team', new_profile_path, :class => 'button' %>
+ </p>
+ <%= render 'profiles/list', :profiles => @profile.user.team_profiles %>
+</div>
@@ -38,9 +38,21 @@ class ProfilesControllerTest < ActionController::TestCase
assert_response :forbidden
end
- test "should get new" do
+ test "get new should show team creation for user with profile" do
get :new
assert_response :success
+
+ assert_equal true, assigns(:profile).team?
+ end
+
+ test "should get new for user without profile" do
+ user = users(:disconnected)
+ set_session_current_user user
+ get :new
+ assert_response :success
+
+ assert_equal false, assigns(:profile).team?
+ assert_equal user.email, assigns(:profile).display_email
end
test "should create user's main profile" do
@@ -20,9 +20,7 @@ class SessionControllerTest < ActionController::TestCase
user = users(:disconnected)
set_session_current_user user
get :show
-
- assert_equal user.email, assigns(:profile).display_email
- assert_select 'a[href="/_/session"][data-method="delete"]', 'Sign out'
+ assert_redirected_to new_profile_url
end
test "user login works and purges old sessions" do

0 comments on commit 99cedf0

Please sign in to comment.