dejavu 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Dejavu
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/dejavu.rb CHANGED
@@ -40,10 +40,19 @@ module Dejavu
40
40
  module ControllerMethods
41
41
  def save_for_dejavu(obj, opts = {})
42
42
  attrs = obj.attributes
43
+
44
+ missing_keys = obj.errors.keys.map(&:to_sym).select{|x| obj.respond_to?(x)} - attrs.keys.map(&:to_sym)
45
+
43
46
  if keys = opts[:nested]
44
47
  keys = [keys] unless keys.is_a? Array
45
48
  keys.each { |key| attrs = save_nested_for_dejavu(obj, key, attrs) }
49
+ missing_keys -= keys.map(&:to_sym)
46
50
  end
51
+
52
+ missing_keys.each do |key|
53
+ attrs[key] = obj.send(key)
54
+ end
55
+
47
56
  flash[:"saved_#{obj.class.model_name.underscore}_for_redisplay"] = attrs
48
57
  end
49
58
 
@@ -35,7 +35,7 @@ describe "Dejavu" do
35
35
 
36
36
  describe "update" do
37
37
  before do
38
- @p = Product.create! :name => "A mug", :code => "PX54", :category => (Category.create! :name => "Mugs")
38
+ @p = Product.create! :virtual => "foo", :name => "A mug", :code => "PX54", :category => (Category.create! :name => "Mugs")
39
39
  Color.create! :name => "Blue", :product => @p
40
40
 
41
41
  visit edit_product_path(@p)
@@ -64,4 +64,22 @@ describe "Dejavu" do
64
64
  field_should_have "product_colors_attributes_0_name", "Blue"
65
65
  end
66
66
  end
67
+
68
+ describe "virtual attributes" do
69
+ before do
70
+ visit new_product_path
71
+ fill_in "Name", :with => "Mug"
72
+ fill_in "Code", :with => "PT"
73
+ fill_in "Virtual", :with => "ou"
74
+ click_button "Create Product"
75
+ end
76
+
77
+ it "should be prefilled" do
78
+ field_should_have "product_virtual", "ou"
79
+ end
80
+
81
+ it "should show existing errors" do
82
+ page.should have_content("Virtual is too short")
83
+ end
84
+ end
67
85
  end
@@ -6,6 +6,9 @@ class Product < ActiveRecord::Base
6
6
  validates_presence_of :name, :code
7
7
  validates_length_of :name, :in => 3..10
8
8
  validates_length_of :code, :in => 3..10
9
+ validates_length_of :virtual, :in => 3..10
9
10
 
10
11
  accepts_nested_attributes_for :category, :colors
12
+
13
+ attr_accessor :virtual
11
14
  end
@@ -19,6 +19,10 @@
19
19
  <%= f.label :code %><br />
20
20
  <%= f.text_field :code %>
21
21
  </div>
22
+ <div class="field">
23
+ <%= f.label :virtual %><br />
24
+ <%= f.text_field :virtual %>
25
+ </div>
22
26
  <div>
23
27
  <%= f.fields_for :category do |ctf| %>
24
28
  <%= ctf.label :category_name %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dejavu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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: 2012-02-12 00:00:00.000000000 Z
12
+ date: 2012-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &75307960 !ruby/object:Gem::Requirement
16
+ requirement: &79605650 !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: *75307960
24
+ version_requirements: *79605650
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-rails
27
- requirement: &75307000 !ruby/object:Gem::Requirement
27
+ requirement: &79605170 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.7'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *75307000
35
+ version_requirements: *79605170
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: capybara
38
- requirement: &75306270 !ruby/object:Gem::Requirement
38
+ requirement: &79604600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.1.1
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *75306270
46
+ version_requirements: *79604600
47
47
  description: Remember your object after a redirect
48
48
  email:
49
49
  - roger@itnig.net
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  segments:
150
150
  - 0
151
- hash: 848035681
151
+ hash: 730709121
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  segments:
159
159
  - 0
160
- hash: 848035681
160
+ hash: 730709121
161
161
  requirements: []
162
162
  rubyforge_project:
163
163
  rubygems_version: 1.8.15