active_presenter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -8,12 +8,3 @@ task :default => :test
8
8
  task :test do
9
9
  Dir['test/**/*_test.rb'].each { |l| require l }
10
10
  end
11
-
12
- desc 'Generate documentation for the ResourceController plugin.'
13
- Rake::RDocTask.new(:rdoc) do |rdoc|
14
- rdoc.rdoc_dir = 'rdoc'
15
- rdoc.title = 'ActivePresenter'
16
- rdoc.options << '--line-numbers' << '--inline-source'
17
- rdoc.rdoc_files.include('README')
18
- rdoc.rdoc_files.include('lib/**/*.rb')
19
- end
@@ -58,7 +58,7 @@ module ActivePresenter
58
58
  # Set the attributes of the presentable instances using the type_attribute form (i.e. user_login => 'james')
59
59
  #
60
60
  def attributes=(attrs)
61
- attrs.each { |k,v| send("#{k}=", v) }
61
+ attrs.each { |k,v| send("#{k}=", v) unless attribute_protected?(k)}
62
62
  end
63
63
 
64
64
  # Makes sure that the presenter is accurate about responding to presentable's attributes, even though they are handled by method_missing.
@@ -145,7 +145,8 @@ module ActivePresenter
145
145
  end
146
146
 
147
147
  def presented_attribute?(method_name)
148
- !presentable_for(method_name).nil?
148
+ p = presentable_for(method_name)
149
+ !p.nil? && send(p).respond_to?(flatten_attribute_name(method_name,p))
149
150
  end
150
151
 
151
152
  def flatten_attribute_name(name, type)
@@ -161,5 +162,11 @@ module ActivePresenter
161
162
  errors.add(attribute_prefix(type)+att, msg)
162
163
  end
163
164
  end
165
+
166
+ def attribute_protected?(name)
167
+ presentable = presentable_for(name)
168
+ flat_attribute = {flatten_attribute_name(name, presentable) => ''} #remove_att... normally takes a hash, so we use a ''
169
+ presentable.to_s.classify.constantize.new.send(:remove_attributes_protected_from_mass_assignment, flat_attribute).empty?
170
+ end
164
171
  end
165
172
  end
@@ -2,7 +2,7 @@ module ActivePresenter
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,19 @@
1
+ desc 'Generate documentation for the ResourceController plugin.'
2
+ Rake::RDocTask.new(:rdoc) do |rdoc|
3
+ rdoc.rdoc_dir = 'rdoc'
4
+ rdoc.title = 'ActivePresenter'
5
+ rdoc.options << '--line-numbers' << '--inline-source'
6
+ rdoc.rdoc_files.include('README')
7
+ rdoc.rdoc_files.include('lib/**/*.rb')
8
+ end
9
+
10
+ task :upload_docs => :rdoc do
11
+ puts 'Deleting previous rdoc'
12
+ `ssh jamesgolick.com 'rm -Rf /home/apps/jamesgolick.com/public/active_presenter/rdoc'`
13
+
14
+ puts "Uploading current rdoc"
15
+ `scp -r rdoc jamesgolick.com:/home/apps/jamesgolick.com/public/active_presenter/rdoc`
16
+
17
+ puts "Deleting rdoc"
18
+ `rm -Rf rdoc`
19
+ end
data/test/base_test.rb CHANGED
@@ -17,6 +17,10 @@ Expectations do
17
17
  SignupPresenter.new(:user_login => 'james')
18
18
  end
19
19
 
20
+ # admin= should be protected from mass assignment
21
+ expect SignupPresenter.new.to.be.attribute_protected?(:user_admin)
22
+ expect SignupPresenter.new(:user_admin => true).user.not.to.be.admin?
23
+
20
24
  expect 'mymockvalue' do
21
25
  User.any_instance.stubs(:login).returns('mymockvalue')
22
26
  SignupPresenter.new.user_login
@@ -101,6 +105,7 @@ Expectations do
101
105
  expect SignupPresenter.new(:user => User.new(hash_for_user)).to.be.save!
102
106
 
103
107
  expect SignupPresenter.new.to.be.respond_to?(:user_login)
108
+ expect SignupPresenter.new.to.be.respond_to?(:user_password_confirmation)
104
109
  expect SignupPresenter.new.to.be.respond_to?(:valid?) # just making sure i didn't break everything :)
105
110
 
106
111
  expect User.create!(hash_for_user).not.to.be.login_changed? do |user|
data/test/test_helper.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  require File.dirname(__FILE__)+'/../lib/active_presenter'
2
2
  require 'expectations'
3
+ require 'logger'
3
4
 
4
5
  ActiveRecord::Base.configurations = {'sqlite3' => {:adapter => 'sqlite3', :database => ':memory:'}}
5
6
  ActiveRecord::Base.establish_connection('sqlite3')
6
7
 
8
+ ActiveRecord::Base.logger = Logger.new(STDERR)
9
+ ActiveRecord::Base.logger.level = Logger::WARN
10
+
7
11
  ActiveRecord::Schema.define(:version => 0) do
8
12
  create_table :users do |t|
9
13
  t.boolean :admin, :default => false
@@ -19,6 +23,8 @@ end
19
23
 
20
24
  class User < ActiveRecord::Base
21
25
  validates_presence_of :login, :password
26
+ attr_accessible :login, :password
27
+ attr_accessor :password_confirmation
22
28
  end
23
29
  class Account < ActiveRecord::Base; end
24
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Golick & Daniel Haran
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-27 00:00:00 -04:00
12
+ date: 2008-07-28 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -30,6 +30,7 @@ files:
30
30
  - lib/active_presenter/version.rb
31
31
  - lib/active_presenter.rb
32
32
  - lib/tasks
33
+ - lib/tasks/doc.rake
33
34
  - lib/tasks/gem.rake
34
35
  - test/base_test.rb
35
36
  - test/test_helper.rb