strip_attributes 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- require "shoulda/active_record"
1
+ require "shoulda/context"
2
2
 
3
3
  module StripAttributes
4
4
  module Shoulda
5
5
  module Macros
6
6
  def should_strip_attributes(*attributes)
7
- klass = respond_to?(:described_type) ? described_type : model_class
7
+ klass = described_type
8
8
  attributes.each do |attribute|
9
9
  attribute = attribute.to_sym
10
10
  should "strip whitespace from #{attribute}" do
@@ -17,7 +17,7 @@ module StripAttributes
17
17
  end
18
18
 
19
19
  def should_not_strip_attributes(*attributes)
20
- klass = respond_to?(:described_type) ? described_type : model_class
20
+ klass = described_type
21
21
  attributes.each do |attribute|
22
22
  attribute = attribute.to_sym
23
23
  should "not strip whitespace from #{attribute}" do
@@ -1,3 +1,3 @@
1
1
  module StripAttributes
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -2,11 +2,7 @@ require "test_helper"
2
2
 
3
3
  module MockAttributes
4
4
  def self.included(base)
5
- base.column :foo, :string
6
- base.column :bar, :string
7
- base.column :biz, :string
8
- base.column :baz, :string
9
- base.column :bang, :string
5
+ base.attributes :foo, :bar, :biz, :baz, :bang
10
6
  end
11
7
  end
12
8
 
data/test/test_helper.rb CHANGED
@@ -1,19 +1,39 @@
1
1
  require "test/unit"
2
2
  require "active_record"
3
+ require "active_support/core_ext/hash/indifferent_access"
3
4
  require "strip_attributes"
4
5
 
5
- # Tableless AR borrowed from
6
- # http://stackoverflow.com/questions/937429/activerecordbase-without-table
7
- class Tableless < ActiveRecord::Base
8
- def self.columns()
9
- @columns ||= []
6
+ # Tableless ActiveModel with some parts borrowed from both
7
+ # http://railscasts.com/episodes/219-active-model and ActiveRecord's
8
+ # implementation.
9
+ class Tableless
10
+ include ActiveModel::Validations
11
+ include ActiveModel::Validations::Callbacks
12
+
13
+ def initialize(attributes = {})
14
+ attributes.each { |name, value| send("#{name}=", value) }
15
+ end
16
+
17
+ def attributes
18
+ attrs = HashWithIndifferentAccess.new
19
+ self.class.attribute_names.each { |name| attrs[name] = self[name] }
20
+ attrs
21
+ end
22
+
23
+ def [](name)
24
+ send name
25
+ end
26
+
27
+ def []=(name, value)
28
+ send "#{name}=", value
10
29
  end
11
30
 
12
- def self.column(name, sql_type = nil, default = nil, null = true)
13
- columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type, null)
31
+ def self.attribute_names
32
+ @attribute_names ||= []
14
33
  end
15
34
 
16
- def save(validate = true)
17
- validate ? valid? : true
35
+ def self.attributes(*names)
36
+ attr_accessor *names
37
+ attribute_names.concat names
18
38
  end
19
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strip_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-28 00:00:00.000000000Z
12
+ date: 2012-02-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70235696883780 !ruby/object:Gem::Requirement
16
+ requirement: &70187844065480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70235696883780
24
+ version_requirements: *70187844065480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
27
- requirement: &70235696882660 !ruby/object:Gem::Requirement
27
+ requirement: &70187844049800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '3.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70235696882660
35
+ version_requirements: *70187844049800
36
36
  description: StripAttributes automatically strips all ActiveRecord model attributes
37
37
  of leading and trailing whitespace before validation. If the attribute is blank,
38
38
  it strips the value to nil.
@@ -62,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  segments:
64
64
  - 0
65
- hash: -1429259511036871871
65
+ hash: 575261520411560086
66
66
  required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
@@ -71,10 +71,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  version: '0'
72
72
  segments:
73
73
  - 0
74
- hash: -1429259511036871871
74
+ hash: 575261520411560086
75
75
  requirements: []
76
76
  rubyforge_project: strip_attributes
77
- rubygems_version: 1.8.10
77
+ rubygems_version: 1.8.16
78
78
  signing_key:
79
79
  specification_version: 3
80
80
  summary: Whitespace cleanup for ActiveRecord attributes