andrewroth_activeadmin 0.3.4.3 → 0.3.4.4

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.
Files changed (42) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +18 -32
  3. data/Gemfile +5 -7
  4. data/activeadmin.gemspec +1 -1
  5. data/features/step_definitions/additional_web_steps.rb +3 -3
  6. data/features/step_definitions/asset_steps.rb +1 -1
  7. data/features/step_definitions/comment_steps.rb +3 -3
  8. data/features/step_definitions/configuration_steps.rb +5 -5
  9. data/features/step_definitions/dashboard_steps.rb +2 -2
  10. data/features/step_definitions/index_scope_steps.rb +5 -5
  11. data/features/step_definitions/pagination_steps.rb +2 -2
  12. data/features/step_definitions/tab_steps.rb +1 -1
  13. data/features/step_definitions/user_steps.rb +1 -1
  14. data/features/step_definitions/web_steps.rb +4 -4
  15. data/lib/active_admin/arbre.rb +0 -1
  16. data/lib/active_admin/arbre/builder.rb +8 -5
  17. data/lib/active_admin/arbre/context.rb +1 -1
  18. data/lib/active_admin/arbre/html/attributes.rb +1 -1
  19. data/lib/active_admin/arbre/html/class_list.rb +0 -4
  20. data/lib/active_admin/arbre/html/collection.rb +2 -2
  21. data/lib/active_admin/arbre/html/document.rb +1 -1
  22. data/lib/active_admin/arbre/html/element.rb +5 -9
  23. data/lib/active_admin/arbre/html/tag.rb +3 -3
  24. data/lib/active_admin/arbre/html/text_node.rb +2 -2
  25. data/lib/active_admin/locales/de.yml +1 -0
  26. data/lib/active_admin/menu_item.rb +25 -17
  27. data/lib/active_admin/resource_controller/collection.rb +1 -1
  28. data/lib/active_admin/version.rb +1 -1
  29. data/lib/active_admin/views/components/columns.rb +4 -4
  30. data/script/use_rails +14 -7
  31. data/spec/spec_helper.rb +5 -11
  32. data/spec/spec_helper_without_rails.rb +10 -0
  33. data/spec/support/detect_rails_version.rb +22 -3
  34. data/spec/unit/arbre/context_spec.rb +1 -1
  35. data/spec/unit/arbre/html/element_spec.rb +5 -5
  36. data/spec/unit/arbre/html/tag_attributes_spec.rb +3 -3
  37. data/spec/unit/arbre/html_spec.rb +32 -22
  38. data/spec/unit/menu_item_spec.rb +25 -20
  39. data/spec/unit/views/tabbed_navigation_spec.rb +2 -1
  40. data/tasks/test.rake +15 -13
  41. metadata +10 -9
  42. data/lib/active_admin/arbre/core_extensions.rb +0 -5
@@ -65,14 +65,14 @@ module Arbre
65
65
 
66
66
  # Returns a string of classes
67
67
  def class_names
68
- class_list.to_html
68
+ class_list.to_s
69
69
  end
70
70
 
71
71
  def class_list
72
72
  get_attribute(:class) || set_attribute(:class, ClassList.new)
73
73
  end
74
74
 
75
- def to_html
75
+ def to_s
76
76
  indent("<#{tag_name}#{attributes_html}>", content, "</#{tag_name}>").html_safe
77
77
  end
78
78
 
@@ -118,7 +118,7 @@ module Arbre
118
118
 
119
119
 
120
120
  def attributes_html
121
- attributes.any? ? " " + attributes.to_html : nil
121
+ attributes.any? ? " " + attributes.to_s : nil
122
122
  end
123
123
 
124
124
  def set_for_attribute(record)
@@ -26,8 +26,8 @@ module Arbre
26
26
  nil
27
27
  end
28
28
 
29
- def to_html
30
- ERB::Util.html_escape(@content.to_html)
29
+ def to_s
30
+ ERB::Util.html_escape(@content.to_s)
31
31
  end
32
32
  end
33
33
 
@@ -9,6 +9,7 @@ de:
9
9
  delete: "Löschen"
10
10
  delete_confirmation: "Wollen Sie dieses Element wirklich löschen?"
11
11
  new_model: "%{model} erstellen"
12
+ create_model: "%{model} erstellen"
12
13
  edit_model: "%{model} bearbeiten"
13
14
  delete_model: "%{model} löschen"
14
15
  details: "%{model} Details"
@@ -1,18 +1,25 @@
1
1
  module ActiveAdmin
2
2
  class MenuItem
3
-
4
- # Use this to get to the routes
5
- include Rails.application.routes.url_helpers
6
-
3
+
4
+
5
+ # Generates a route using the rails application url helpers
6
+ #
7
+ # @param [Symbol] named_route
8
+ #
9
+ # @returns [String] The generated route
10
+ def self.generate_url(named_route)
11
+ Rails.application.routes.url_helpers.send(named_route)
12
+ end
13
+
7
14
  attr_accessor :name, :url, :priority, :parent, :display_if_block
8
-
15
+
9
16
  def initialize(name, url, priority = 10, options = {})
10
17
  @name, @url, @priority = name, url, priority
11
18
  @children = []
12
19
  @cached_url = {} # Stores the cached url in a hash to allow us to change it and still cache it
13
20
 
14
21
  @display_if_block = options.delete(:if)
15
-
22
+
16
23
  yield(self) if block_given? # Builder style syntax
17
24
  end
18
25
 
@@ -20,54 +27,55 @@ module ActiveAdmin
20
27
  item = MenuItem.new(name, url, priority, options, &block)
21
28
  item.parent = self
22
29
  @children << item
23
- end
24
-
30
+ end
31
+
25
32
  def children
26
33
  @children.sort
27
34
  end
28
-
35
+
29
36
  def parent?
30
37
  !parent.nil?
31
38
  end
32
-
39
+
33
40
  def dom_id
34
41
  name.downcase.gsub( " ", '_' ).gsub( /[^a-z0-9_]/, '' )
35
42
  end
36
-
43
+
37
44
  def url
38
45
  case @url
39
46
  when Symbol
40
- generated = send(@url) # Call the named route
47
+ generated = self.class.generate_url(@url) # Call the named route
41
48
  else
42
49
  generated = @url
43
50
  end
44
51
  @cached_url[@url] ||= generated
45
52
  end
46
-
53
+
47
54
  # Returns an array of the ancestory of this menu item
48
55
  # The first item is the immediate parent fo the item
49
56
  def ancestors
50
57
  return [] unless parent?
51
58
  [parent, parent.ancestors].flatten
52
59
  end
53
-
60
+
54
61
  # Returns the child item with the name passed in
55
62
  # @blog_menu["Create New"] => <#MenuItem @name="Create New" >
56
63
  def [](name)
57
64
  @children.find{ |i| i.name == name }
58
65
  end
59
-
66
+
60
67
  def <=>(other)
61
68
  result = priority <=> other.priority
62
69
  result = name <=> other.name if result == 0
63
70
  result
64
71
  end
65
-
72
+
66
73
  # Returns the display if block. If the block was not explicitly defined
67
74
  # a default block always returning true will be returned.
68
75
  def display_if_block
69
76
  @display_if_block || lambda { |_| true }
70
77
  end
71
78
 
72
- end
79
+
80
+ end
73
81
  end
@@ -124,7 +124,7 @@ module ActiveAdmin
124
124
  end
125
125
 
126
126
  def paginate(chain)
127
- chain.page(params[:page]).per(@per_page || active_admin_namespace.default_per_page)
127
+ chain.send(Kaminari.config.page_method_name, params[:page]).per(@per_page || active_admin_namespace.default_per_page)
128
128
  end
129
129
  end
130
130
 
@@ -1,3 +1,3 @@
1
1
  module ActiveAdmin
2
- VERSION = '0.3.4.3'
2
+ VERSION = '0.3.4.4'
3
3
  end
@@ -14,6 +14,10 @@ module ActiveAdmin
14
14
  calculate_columns!
15
15
  end
16
16
 
17
+ def to_s
18
+ super.to_s + "<div style=\"clear:both;\"></div>".html_safe
19
+ end
20
+
17
21
  protected
18
22
 
19
23
  def margin_size
@@ -35,10 +39,6 @@ module ActiveAdmin
35
39
  end
36
40
  end
37
41
 
38
- def to_html
39
- super.to_s + "<div style=\"clear:both;\"></div>".html_safe
40
- end
41
-
42
42
  end
43
43
 
44
44
  class Column < ActiveAdmin::Component
@@ -3,6 +3,8 @@
3
3
  # Switches the development environment to use the given
4
4
  # version of rails. Caches the Gemfile.locks so that
5
5
  # switching it very fast.
6
+ #
7
+ require File.expand_path("../../spec/support/detect_rails_version", __FILE__)
6
8
 
7
9
  def cmd(command)
8
10
  puts command
@@ -34,13 +36,18 @@ if File.exists?(gem_lock_file) && ARGV.include?('--clobber')
34
36
  cmd "rm #{gem_lock_file}"
35
37
  end
36
38
 
37
- unless File.exists?(gem_lock_file)
38
- # Generate it
39
+ write_rails_version(version)
40
+
41
+ # Ensure that bundler installs
42
+ ENV['RUBYOPT'] = ''
43
+
44
+ if File.exists?(gem_lock_file)
45
+ cmd("rm Gemfile.lock") if file_or_symlink?("Gemfile.lock")
46
+ cmd("ln -s #{gem_lock_file} Gemfile.lock")
47
+ cmd("bundle")
48
+ else
39
49
  cmd "rm Gemfile.lock" if file_or_symlink?("Gemfile.lock")
40
- cmd "export RAILS=#{version} && bundle install"
50
+ cmd "bundle install"
41
51
  cmd "mv Gemfile.lock #{gem_lock_file}"
52
+ cmd("ln -s #{gem_lock_file} Gemfile.lock")
42
53
  end
43
-
44
- cmd("rm Gemfile.lock") if file_or_symlink?("Gemfile.lock")
45
- cmd("ln -s #{gem_lock_file} Gemfile.lock")
46
- cmd("bundle")
@@ -1,13 +1,4 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH << File.expand_path('../support', __FILE__)
3
-
4
- ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
5
-
6
- require 'detect_rails_version'
7
- ENV['RAILS'] = detect_rails_version
8
-
9
- require "bundler"
10
- Bundler.setup
1
+ require File.expand_path("../spec_helper_without_rails", __FILE__)
11
2
 
12
3
  require 'shoulda/active_record'
13
4
  include Shoulda::ActiveRecord::Macros
@@ -97,7 +88,10 @@ module ActiveAdminIntegrationSpecHelper
97
88
  end
98
89
 
99
90
  ENV['RAILS_ENV'] = 'test'
100
- ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV["RAILS"]}", __FILE__)
91
+
92
+ require 'detect_rails_version'
93
+ rails_version = detect_rails_version
94
+ ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{rails_version}", __FILE__)
101
95
 
102
96
  # Create the test app if it doesn't exists
103
97
  unless File.exists?(ENV['RAILS_ROOT'])
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH << File.expand_path('../support', __FILE__)
3
+
4
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'detect_rails_version'
7
+ ENV['RAILS'] = detect_rails_version
8
+
9
+ require "bundler"
10
+ Bundler.setup
@@ -2,9 +2,28 @@
2
2
  #
3
3
  # You can pass it in as an ENV variable or it will use
4
4
  # the current Gemfile.lock to find it
5
+
6
+ unless defined?(RAILS_VERSION_FILE)
7
+ RAILS_VERSION_FILE = File.expand_path("../../../.rails-version", __FILE__)
8
+ end
9
+
10
+ unless defined?(DEFAULT_RAILS_VERSION)
11
+ DEFAULT_RAILS_VERSION = "3.1.3"
12
+ end
13
+
5
14
  def detect_rails_version
6
- return nil unless (File.exists?("Gemfile.lock") || File.symlink?("Gemfile.lock"))
15
+ detected_version = if File.exists?(RAILS_VERSION_FILE)
16
+ version = File.read(RAILS_VERSION_FILE).chomp.strip
17
+ version != "" ? version : DEFAULT_RAILS_VERSION
18
+ else
19
+ DEFAULT_RAILS_VERSION
20
+ end
21
+
22
+ puts "Detected Rails: #{detected_version}" if ENV['DEBUG']
23
+
24
+ detected_version
25
+ end
7
26
 
8
- File.read("Gemfile.lock").match(/^\W*rails \(([a-z\d.]*)\)/)
9
- return $1
27
+ def write_rails_version(version)
28
+ File.open(RAILS_VERSION_FILE, "w+"){|f| f << version }
10
29
  end
@@ -27,7 +27,7 @@ describe Arbre::Context do
27
27
  end
28
28
 
29
29
  it "should use a cached version of the HTML for method delegation" do
30
- current_dom_context.should_receive(:to_html).once.and_return("<h1>札幌市北区</h1>")
30
+ current_dom_context.should_receive(:to_s).once.and_return("<h1>札幌市北区</h1>")
31
31
  current_dom_context.index('<').should == 0
32
32
  current_dom_context.index('<').should == 0
33
33
  end
@@ -73,7 +73,7 @@ describe Arbre::HTML::Element do
73
73
  let(:child){ "Hello World" }
74
74
  it "should add as a TextNode" do
75
75
  element.children.first.should be_instance_of(Arbre::HTML::TextNode)
76
- element.children.first.to_html.should == "Hello World"
76
+ element.children.first.to_s.should == "Hello World"
77
77
  end
78
78
  end
79
79
  end
@@ -90,13 +90,13 @@ describe Arbre::HTML::Element do
90
90
  end
91
91
 
92
92
  it "should add the string as a child" do
93
- element.children.first.to_html.should == "Goodbye"
93
+ element.children.first.to_s.should == "Goodbye"
94
94
  end
95
95
 
96
96
  it "should html escape the string" do
97
97
  string = "Goodbye <br />"
98
98
  element.content = string
99
- element.content.to_html.should == "Goodbye &lt;br /&gt;"
99
+ element.to_s.should == "Goodbye &lt;br /&gt;"
100
100
  end
101
101
  end
102
102
 
@@ -146,8 +146,8 @@ describe Arbre::HTML::Element do
146
146
 
147
147
  describe "rendering to html" do
148
148
  it "should render the children collection" do
149
- element.children.should_receive(:to_html).and_return("content")
150
- element.to_html.should == "content"
149
+ element.children.should_receive(:to_s).and_return("content")
150
+ element.to_s.should == "content"
151
151
  end
152
152
  end
153
153
 
@@ -14,7 +14,7 @@ describe Arbre::HTML::Tag, "Attributes" do
14
14
  end
15
15
 
16
16
  it "should render the attributes to html" do
17
- tag.to_html.should == <<-HTML
17
+ tag.to_s.should == <<-HTML
18
18
  <tag id="my_id"></tag>
19
19
  HTML
20
20
  end
@@ -47,13 +47,13 @@ HTML
47
47
  describe "rendering attributes" do
48
48
  it "should html safe the attribute values" do
49
49
  tag.set_attribute(:class, "\">bad things!")
50
- tag.to_html.should == <<-HTML
50
+ tag.to_s.should == <<-HTML
51
51
  <tag class="&quot;&gt;bad things!"></tag>
52
52
  HTML
53
53
  end
54
54
  it "should should escape the attribute names" do
55
55
  tag.set_attribute(">bad", "things")
56
- tag.to_html.should == <<-HTML
56
+ tag.to_s.should == <<-HTML
57
57
  <tag &gt;bad="things"></tag>
58
58
  HTML
59
59
  end
@@ -6,7 +6,7 @@ describe Arbre do
6
6
 
7
7
  it "should render a single element" do
8
8
  content = span("Hello World")
9
- content.to_html.should == <<-HTML
9
+ content.to_s.should == <<-HTML
10
10
  <span>Hello World</span>
11
11
  HTML
12
12
  end
@@ -15,7 +15,7 @@ HTML
15
15
  content = span do
16
16
  span "Hello World"
17
17
  end
18
- content.to_html.should == <<-HTML
18
+ content.to_s.should == <<-HTML
19
19
  <span>
20
20
  <span>Hello World</span>
21
21
  </span>
@@ -28,7 +28,7 @@ HTML
28
28
  li "Second"
29
29
  li "Third"
30
30
  end
31
- content.to_html.should == <<-HTML
31
+ content.to_s.should == <<-HTML
32
32
  <ul>
33
33
  <li>First</li>
34
34
  <li>Second</li>
@@ -51,7 +51,7 @@ HTML
51
51
  li first
52
52
  li second
53
53
  end
54
- content.to_html.should == <<-EOS
54
+ content.to_s.should == <<-EOS
55
55
  <ul>
56
56
  <li>First</li>
57
57
  <li>Second</li>
@@ -66,7 +66,7 @@ EOS
66
66
  li
67
67
  end
68
68
  end
69
- content.to_html.should == <<-HTML
69
+ content.to_s.should == <<-HTML
70
70
  <div>
71
71
  <ul></ul>
72
72
  <li>
@@ -82,7 +82,7 @@ HTML
82
82
  li
83
83
  end
84
84
  end
85
- content.to_html.should == <<-HTML
85
+ content.to_s.should == <<-HTML
86
86
  <div>
87
87
  <ul>
88
88
  <li></li>
@@ -95,7 +95,7 @@ HTML
95
95
  content = div do
96
96
  span(ul(li))
97
97
  end
98
- content.to_html.should == <<-HTML
98
+ content.to_s.should == <<-HTML
99
99
  <div>
100
100
  <span>
101
101
  <ul>
@@ -113,7 +113,7 @@ HTML
113
113
  li
114
114
  end
115
115
  end
116
- content.to_html.should == <<-HTML
116
+ content.to_s.should == <<-HTML
117
117
  <div id="my-tag">
118
118
  <ul>
119
119
  <li></li>
@@ -131,12 +131,22 @@ HTML
131
131
  item.parent.should == list
132
132
  end
133
133
 
134
- it "should set a string content return value with no children" do
135
- li do
136
- "Hello World"
137
- end.to_html.should == <<-HTML
138
- <li>Hello World</li>
139
- HTML
134
+
135
+ ["Hello World", 1, 1.5].each do |value|
136
+ it "should append the return value of '#{value}' when no other children added to the DOM" do
137
+ li do
138
+ value
139
+ end.to_s.should == "<li>#{value}</li>\n"
140
+ end
141
+ end
142
+
143
+ ["Hello World", 1, 1.5].each do |value|
144
+ it "should not append the return value of '#{value}' when children have been added to the DOM" do
145
+ li do
146
+ text_node("Already Added")
147
+ value
148
+ end.to_s.should == "<li>Already Added</li>\n"
149
+ end
140
150
  end
141
151
 
142
152
  describe "text nodes" do
@@ -150,19 +160,19 @@ HTML
150
160
  describe "self-closing nodes" do
151
161
  it "should not self-close script tags" do
152
162
  tag = script :type => 'text/javascript'
153
- tag.to_html.should == <<-HTML
163
+ tag.to_s.should == <<-HTML
154
164
  <script type="text/javascript"></script>
155
165
  HTML
156
166
  end
157
167
  it "should self-close meta tags" do
158
168
  tag = meta :content => "text/html; charset=utf-8"
159
- tag.to_html.should == <<-HTML
169
+ tag.to_s.should == <<-HTML
160
170
  <meta content="text/html; charset=utf-8\"/>
161
171
  HTML
162
172
  end
163
173
  it "should self-close link tags" do
164
174
  tag = link :rel => "stylesheet"
165
- tag.to_html.should == <<-HTML
175
+ tag.to_s.should == <<-HTML
166
176
  <link rel="stylesheet"/>
167
177
  HTML
168
178
  end
@@ -170,17 +180,17 @@ HTML
170
180
 
171
181
  describe "html safe" do
172
182
  it "should escape the contents" do
173
- span("<br />").to_html.should == <<-HTML
183
+ span("<br />").to_s.should == <<-HTML
174
184
  <span>&lt;br /&gt;</span>
175
185
  HTML
176
186
  end
177
187
 
178
188
  it "should return html safe strings" do
179
- span("<br />").to_html.should be_html_safe
189
+ span("<br />").to_s.should be_html_safe
180
190
  end
181
191
 
182
192
  it "should not escape html passed in" do
183
- span(span("<br />")).to_html.should == <<-HTML
193
+ span(span("<br />")).to_s.should == <<-HTML
184
194
  <span>
185
195
  <span>&lt;br /&gt;</span>
186
196
  </span>
@@ -192,7 +202,7 @@ HTML
192
202
  span {
193
203
  "<br />"
194
204
  }
195
- }.to_html.should == <<-HTML
205
+ }.to_s.should == <<-HTML
196
206
  <span>
197
207
  <span>&lt;br /&gt;</span>
198
208
  </span>
@@ -200,7 +210,7 @@ HTML
200
210
  end
201
211
 
202
212
  it "should escape the contents of attributes" do
203
- span(:class => "<br />").to_html.should == <<-HTML
213
+ span(:class => "<br />").to_s.should == <<-HTML
204
214
  <span class="&lt;br /&gt;"></span>
205
215
  HTML
206
216
  end