muck-profiles 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.13
1
+ 0.1.14
@@ -1,7 +1,10 @@
1
1
  class Muck::ProfilesController < ApplicationController
2
2
  unloadable
3
3
 
4
+ before_filter :setup_user, :only => [:show, :edit]
5
+
4
6
  def index
7
+ @users = User.by_newest.paginate(:page => @page, :per_page => @per_page, :include => 'profile')
5
8
  respond_to do |format|
6
9
  format.html { render :template => 'profiles/index' }
7
10
  end
@@ -9,7 +12,6 @@ class Muck::ProfilesController < ApplicationController
9
12
 
10
13
  # show a given user's public profile information
11
14
  def show
12
- @user = User.find(params[:id])
13
15
  @profile = @user.profile
14
16
  @page_title = @user.display_name
15
17
  respond_to do |format|
@@ -17,10 +19,20 @@ class Muck::ProfilesController < ApplicationController
17
19
  end
18
20
  end
19
21
 
22
+ # Renders an edit for for the current user's profile
23
+ #
24
+ # It is simple to override the edit template. Simply create a template in app/views/profiles/edit.html.erb
25
+ # and add something similar to the following:
26
+ # <div id="edit_profile">
27
+ # <%= output_errors(t('muck.profiles.problem_editing_profile'), {:class => 'help-box'}, @profile) %>
28
+ # <% profile_form(@profile) do |f| -%>
29
+ # <%# Add custom fields here. ie %>
30
+ # <%= f.text_field :custom_thing %>
31
+ # <% end -%>
32
+ # </div>
20
33
  def edit
21
- @page_title = t('muck.profiles.edit_profile')
22
- @user = User.find(params[:user_id])
23
34
  @profile = @user.profile
35
+ @page_title = t('muck.profiles.edit_profile_title', :name => @user.display_name)
24
36
  respond_to do |format|
25
37
  format.pjs do
26
38
  render_as_html do
@@ -32,9 +44,9 @@ class Muck::ProfilesController < ApplicationController
32
44
  end
33
45
 
34
46
  def update
35
- @page_title = t('muck.profiles.edit_profile')
36
47
  @user = User.find(params[:user_id])
37
48
  @profile = @user.profile
49
+ @page_title = t('muck.profiles.edit_profile_title', :name => @user.display_name)
38
50
  @profile.update_attributes!(params[:profile])
39
51
  respond_to do |format|
40
52
  flash[:notice] = t('muck.profiles.edit_success')
@@ -45,4 +57,11 @@ class Muck::ProfilesController < ApplicationController
45
57
  render :action => :edit
46
58
  end
47
59
 
60
+ protected
61
+ def setup_user
62
+ if params[:user_id]
63
+ @user = User.find(params[:user_id]) rescue nil
64
+ end
65
+ @user ||= User.find(params[:id])
66
+ end
48
67
  end
@@ -1,3 +1,12 @@
1
1
  module MuckProfilesHelper
2
2
 
3
+ # Renders a profile edit form
4
+ # content: Optional content object to be edited.
5
+ # options: html options for form. For example:
6
+ # :html => {:id => 'a form'}
7
+ def profile_form(profile, options = {}, &block)
8
+ options[:html] = {} if options[:html].nil?
9
+ raw_block_to_partial('profiles/form', options.merge(:profile => profile), &block)
10
+ end
11
+
3
12
  end
@@ -0,0 +1,12 @@
1
+ <div id="<%= "#{profile.dom_id}" %>" class="edit_profile">
2
+ <% custom_form_for(profile, :url => user_profile_path(profile.user), :html => html.merge(:id => "edit-profile-form", :name => 'edit-profile-form', :method => :put, :multipart => true ) ) do |f| -%>
3
+ <div id="edit_profile_image">
4
+ <%= image_tag profile.photo.url(:thumb) %>
5
+ <%= f.file_field :photo, { :label => t('muck.profiles.upload_photo') } %>
6
+ </div>
7
+ <%= capture(f, &block) %>
8
+ <div id="edit_profile_submit" class="button form-row">
9
+ <%= f.submit t('muck.general.update') %>
10
+ </div>
11
+ <% end %>
12
+ </div>
@@ -0,0 +1,4 @@
1
+ <div class="user-profile-small">
2
+ <%= icon user, :tiny %>
3
+ <%= link_to user.display_name, profile_path(user) %>
4
+ </div>
@@ -0,0 +1,6 @@
1
+ <div id="edit_content" class="span-24 colborder column">
2
+ <%= output_errors(t('muck.profiles.problem_editing_profile'), {:class => 'help-box'}, @profile) %>
3
+ <% profile_form(@profile) do |f| -%>
4
+ <%# can add form fields as desired here -%>
5
+ <% end -%>
6
+ </div>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'profiles/profile', :collection => @users, :as => :user %>
@@ -2,4 +2,4 @@
2
2
  <%= icon @user, :thumb %>
3
3
  <p><%= @user.full_name %></p>
4
4
  <p><%= link_to t('muck.profiles.edit_profile'), edit_user_profile_path(@user) if @profile.can_edit?(current_user) %></p>
5
- </div>
5
+ </div>
@@ -17,8 +17,8 @@ module ActiveRecord
17
17
  :icon => "50x50>",
18
18
  :tiny => "24x24>" },
19
19
  :default_url => "/images/profile_default.jpg"
20
-
21
-
20
+
21
+
22
22
  class_eval <<-EOV
23
23
  attr_protected :created_at, :updated_at, :photo_file_name, :photo_content_type, :photo_file_size
24
24
  EOV
@@ -36,12 +36,6 @@ module ActiveRecord
36
36
 
37
37
  # All the methods available to a record that has had <tt>acts_as_muck_profile</tt> specified.
38
38
  module InstanceMethods
39
-
40
- # def query_services
41
- # uri = read_attribute(:blog)
42
- # rss_link = RssMethods::auto_detect_rss_url(uri)
43
- # write_attribute(:blog_rss, rss_link) if rss_link
44
- # end
45
39
 
46
40
  def can_edit?(user)
47
41
  return false if user.nil?
data/locales/en.yml CHANGED
@@ -2,8 +2,9 @@ en:
2
2
  muck:
3
3
  profiles:
4
4
  upload_photo: "Upload a photo:"
5
- problem_editing_account: "There was a problem updating your profile"
5
+ problem_editing_profile: "There was a problem updating your profile"
6
6
  edit_profile: "Edit Profile"
7
+ edit_profile_title: "Editing profile for {{name}}"
7
8
  view_profile: "View Profile"
8
9
  update_profile: "Update Profile"
9
10
  edit_success: "Successfully updated your profile"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{muck-profiles}
8
- s.version = "0.1.13"
8
+ s.version = "0.1.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Ball"]
12
- s.date = %q{2009-10-27}
12
+ s.date = %q{2009-10-29}
13
13
  s.description = %q{Profile engine for the muck system.}
14
14
  s.email = %q{justinball@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
25
25
  "app/controllers/muck/profiles_controller.rb",
26
26
  "app/helpers/muck_profiles_helper.rb",
27
27
  "app/views/admin/profiles/edit.html.erb",
28
+ "app/views/profiles/_form.html.erb",
29
+ "app/views/profiles/_profile.html.erb",
28
30
  "app/views/profiles/edit.html.erb",
29
31
  "app/views/profiles/index.html.erb",
30
32
  "app/views/profiles/show.html.erb",
@@ -90,6 +92,8 @@ Gem::Specification.new do |s|
90
92
  "test/rails_root/Rakefile",
91
93
  "test/rails_root/app/controllers/application_controller.rb",
92
94
  "test/rails_root/app/controllers/default_controller.rb",
95
+ "test/rails_root/app/controllers/profiles_controller.rb",
96
+ "test/rails_root/app/controllers/users_controller.rb",
93
97
  "test/rails_root/app/helpers/application_helper.rb",
94
98
  "test/rails_root/app/models/.keep",
95
99
  "test/rails_root/app/models/profile.rb",
@@ -297,6 +301,8 @@ Gem::Specification.new do |s|
297
301
  s.test_files = [
298
302
  "test/rails_root/app/controllers/application_controller.rb",
299
303
  "test/rails_root/app/controllers/default_controller.rb",
304
+ "test/rails_root/app/controllers/profiles_controller.rb",
305
+ "test/rails_root/app/controllers/users_controller.rb",
300
306
  "test/rails_root/app/helpers/application_helper.rb",
301
307
  "test/rails_root/app/models/profile.rb",
302
308
  "test/rails_root/app/models/user.rb",
@@ -5,10 +5,17 @@ class ApplicationController < ActionController::Base
5
5
 
6
6
  protected
7
7
 
8
+ # **********************************************
9
+ # SSL method
10
+ # only require ssl if we are in production
11
+ def ssl_required?
12
+ return false
13
+ end
14
+
8
15
  # called by Admin::Muck::BaseController to check whether or not the
9
16
  # user should have access to the admin UI
10
- def admin_access?
11
- admin?
17
+ def admin_access_required
18
+ access_denied unless admin?
12
19
  end
13
-
20
+
14
21
  end
@@ -0,0 +1,3 @@
1
+ class ProfilesController < Muck::ProfilesController
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class UsersController < Muck::UsersController
2
+
3
+ end
@@ -1,4 +1,4 @@
1
- RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
1
+ RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
2
2
 
3
3
  require File.join(File.dirname(__FILE__), 'boot')
4
4
 
@@ -16,7 +16,8 @@ end
16
16
  Rails::Initializer.run do |config|
17
17
  config.time_zone = 'UTC'
18
18
  config.gem "authlogic"
19
- config.gem "binarylogic-searchlogic", :lib => 'searchlogic', :source => 'http://gems.github.com', :version => '~> 2.0.0'
19
+ config.gem "searchlogic"
20
+ config.gem 'mislav-will_paginate', :lib => 'will_paginate', :source => 'http://gems.github.com'
20
21
  config.gem "bcrypt-ruby", :lib => "bcrypt"
21
22
  config.gem 'thoughtbot-paperclip', :lib => 'paperclip', :source => "http://gems.github.com"
22
23
  config.gem 'muck-engine', :lib => 'muck_engine'
@@ -2,6 +2,9 @@ ActionController::Routing::Routes.draw do |map|
2
2
 
3
3
  map.root :controller => 'default', :action => 'index'
4
4
 
5
+ map.resources :profiles
6
+ map.resources :users, :has_one => :profile
7
+
5
8
  # Install the default routes as the lowest priority.
6
9
  map.connect ':controller/:action/:id'
7
10
  map.connect ':controller/:action/:id.:format'
@@ -5,10 +5,19 @@ class Admin::Muck::ProfilesControllerTest < ActionController::TestCase
5
5
  tests Admin::Muck::ProfilesController
6
6
 
7
7
  should_require_login :edit => :get, :login_url => '/login'
8
- should_require_role(:admin, '/login', :index)
9
8
 
9
+ context "logged in as normal user" do
10
+ setup do
11
+ @user = Factory(:user)
12
+ activate_authlogic
13
+ login_as @user
14
+ end
15
+
16
+ should_require_role(:admin, '/login', :edit)
17
+ end
18
+
10
19
  context "logged in as admin" do
11
-
20
+
12
21
  setup do
13
22
  @admin = Factory(:user)
14
23
  @admin_role = Factory(:role, :rolename => 'administrator')
@@ -16,7 +25,7 @@ class Admin::Muck::ProfilesControllerTest < ActionController::TestCase
16
25
  activate_authlogic
17
26
  login_as @admin
18
27
  end
19
-
28
+
20
29
  context "GET edit" do
21
30
  setup do
22
31
  get :edit
@@ -13,4 +13,13 @@ class Muck::ProfilesControllerTest < ActionController::TestCase
13
13
  should_render_template :show
14
14
  end
15
15
 
16
+ context "GET edit" do
17
+ setup do
18
+ @user = Factory(:user)
19
+ get :edit, :user_id => @user.to_param
20
+ end
21
+ should_respond_with :success
22
+ should_render_template :edit
23
+ end
24
+
16
25
  end
@@ -5,7 +5,11 @@ module MuckControllerMacros
5
5
  login_url = args.delete :login_url
6
6
  args.each do |action, verb|
7
7
  should "Require login for '#{action}' action" do
8
- send(verb, action)
8
+ if [:put, :delete].include?(verb) # put and delete require an id even if it is a bogus one
9
+ send(verb, action, :id => 1)
10
+ else
11
+ send(verb, action)
12
+ end
9
13
  assert_redirected_to(login_url)
10
14
  end
11
15
  end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class ProfileTest < ActiveSupport::TestCase
4
+
5
+ context 'A profile' do
6
+ setup do
7
+ @user = Factory(:user)
8
+ @profile = @user.profile
9
+ end
10
+ subject { @profile }
11
+
12
+ should_belong_to :user
13
+
14
+ end
15
+
16
+ end
@@ -6,6 +6,8 @@ class UserTest < ActiveSupport::TestCase
6
6
  setup do
7
7
  @user = Factory(:user)
8
8
  end
9
+ subject { @user }
10
+
9
11
  should_accept_nested_attributes_for :profile
10
12
  should_have_one :profile
11
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muck-profiles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Ball
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-27 00:00:00 -06:00
12
+ date: 2009-10-29 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,8 @@ files:
50
50
  - app/controllers/muck/profiles_controller.rb
51
51
  - app/helpers/muck_profiles_helper.rb
52
52
  - app/views/admin/profiles/edit.html.erb
53
+ - app/views/profiles/_form.html.erb
54
+ - app/views/profiles/_profile.html.erb
53
55
  - app/views/profiles/edit.html.erb
54
56
  - app/views/profiles/index.html.erb
55
57
  - app/views/profiles/show.html.erb
@@ -115,6 +117,8 @@ files:
115
117
  - test/rails_root/Rakefile
116
118
  - test/rails_root/app/controllers/application_controller.rb
117
119
  - test/rails_root/app/controllers/default_controller.rb
120
+ - test/rails_root/app/controllers/profiles_controller.rb
121
+ - test/rails_root/app/controllers/users_controller.rb
118
122
  - test/rails_root/app/helpers/application_helper.rb
119
123
  - test/rails_root/app/models/.keep
120
124
  - test/rails_root/app/models/profile.rb
@@ -343,6 +347,8 @@ summary: Profile engine for the muck system
343
347
  test_files:
344
348
  - test/rails_root/app/controllers/application_controller.rb
345
349
  - test/rails_root/app/controllers/default_controller.rb
350
+ - test/rails_root/app/controllers/profiles_controller.rb
351
+ - test/rails_root/app/controllers/users_controller.rb
346
352
  - test/rails_root/app/helpers/application_helper.rb
347
353
  - test/rails_root/app/models/profile.rb
348
354
  - test/rails_root/app/models/user.rb