Permalink
Browse files

Renamed link to url, since link was causing some problems (reserved w…

…ord?)
  • Loading branch information...
1 parent b99546a commit 3cd857eb51e8d1f5320b35be3758b5c1b9b1ece2 @ramontayag committed Jun 16, 2011
View
@@ -15,7 +15,7 @@ gem "ordered_tree", ">= 0.1.6"
# :test and :cucumber environments!
#
# Just remember to uncomment them when you publish (or make a pull request).
-group :development, :test, :cucumber do
+#group :development, :test, :cucumber do
gem "rspec", "~> 2.6.0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
@@ -39,10 +39,10 @@ group :development, :test, :cucumber do
gem 'capybara', ">= 1.0.0.rc1"
gem 'database_cleaner'
gem 'launchy'
- gem 'machinist'
+ gem 'machinist', :path => "/home/ramon/source/machinist"
gem 'faker'
gem 'guard-cucumber', '0.3.4'
gem 'libnotify'
gem 'rb-inotify'
gem 'nifty-generators'
-end
+#end
View
@@ -1,3 +1,8 @@
+PATH
+ remote: /home/ramon/source/machinist
+ specs:
+ machinist (1.0.6)
+
GEM
remote: http://rubygems.org/
specs:
@@ -96,7 +101,6 @@ GEM
configuration (>= 0.0.5)
rake (>= 0.8.1)
libnotify (0.5.5)
- machinist (1.0.6)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@@ -183,7 +187,7 @@ DEPENDENCIES
jquery-rails (>= 1.0.3)
launchy
libnotify
- machinist
+ machinist!
nifty-generators
ordered_tree (>= 0.1.6)
rails (= 3.0.7)
View
@@ -1,23 +1,27 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
-guard 'rspec', :version => 2 do
- watch(%r{^spec/.+_spec\.rb})
- watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
- watch('spec/spec_helper.rb') { "spec" }
+group 'specs' do
+ guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb})
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
- # Rails example
- watch('spec/spec_helper.rb') { "spec" }
- watch('config/routes.rb') { "spec/routing" }
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
- watch(%r{^spec/.+_spec\.rb})
- watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
- watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
- watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ # Rails example
+ watch('spec/spec_helper.rb') { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ watch(%r{^spec/.+_spec\.rb})
+ watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ end
end
-guard 'cucumber' do
- watch(%r{^features/.+\.feature$})
- watch(%r{^features/support/.+$}) { 'features' }
- watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
+group 'features' do
+ guard 'cucumber' do
+ watch(%r{^features/.+\.feature$})
+ watch(%r{^features/support/.+$}) { 'features' }
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
+ end
end
View
@@ -38,7 +38,7 @@ You can pass any of the following arguments, in a form of a hash, into @to_navig
* :label
* :title
-* :link
+* :url
* :highlights_on
* :parent_id
* :position
@@ -7,7 +7,6 @@ Feature: So that I can create a menu for my viewers to navigate my site
Given a page "Home" exists
And a category "Misc" exists
And I am on the menu items page
- And show me the page
When I create the page "Home" menu item
Then I should see "Home" in the list of menu items
When I create the category "Misc" menu item
@@ -12,6 +12,8 @@ module ClassMethods
self.abstract_class = true
belongs_to :navigable, :polymorphic => true
+ validates :label, :presence => true, :unless => Proc.new {|m| m.navigable.present?}
+ validates :url, :presence => true, :unless => Proc.new {|m| m.navigable.present?}
# Calling ordered_tree on the child is important because
# of this: http://stackoverflow.com/q/6262033/61018
@@ -8,8 +8,8 @@ def label
nil
end
- def link
- db_value = self.read_attribute :link
+ def url
+ db_value = self.read_attribute :url
return db_value if db_value
return navigable if navigable
nil
@@ -21,37 +21,37 @@ def title
if navigable && navigable_config(:title)
config = navigable_config :title
return case config
- when Symbol then navigable.send config
- when String then config
- when Proc then config.call navigable
+ when Symbol then navigable.send config
+ when String then config
+ when Proc then config.call navigable
+ end
end
+ return self.label
end
- return self.label
- end
- def highlights_on
- db_value = self.read_attribute :highlights_on
- value = if db_value
- Regexp.new db_value
- else # db_value.nil?
- if navigable && navigable_config(:highlights_on)
- config = navigable_config(:highlights_on)
- case config
- when Proc then config.call navigable
- else config
+ def highlights_on
+ db_value = self.read_attribute :highlights_on
+ value = if db_value
+ Regexp.new db_value
+ else # db_value.nil?
+ if navigable && navigable_config(:highlights_on)
+ config = navigable_config(:highlights_on)
+ case config
+ when Proc then config.call navigable
+ else config
+ end
+ else
+ self.url
end
- else
- self.link
end
- end
- end
+ end
- private
+ private
- def navigable_config(key)
- navigable.class.navigable_config[key]
- end
+ def navigable_config(key)
+ navigable.class.navigable_config[key]
+ end
+ end
end
end
-end
@@ -18,12 +18,10 @@ def create_dynamic_items(collection)
item = {}
item[:key] = @template.dom_id(nav_item).to_sym
item[:name] = nav_item.label
- if nav_item.link.is_a?(String)
- item[:url] = nav_item.link
+ if nav_item.url.is_a?(String)
+ item[:url] = nav_item.url
else # it's a database record then!
- puts "This is the link: #{nav_item.link.inspect}"
- item[:url] = @template.polymorphic_path(nav_item.link)
- #item[:url] = "/"
+ item[:url] = @template.polymorphic_path(nav_item.url)
end
item[:options] = {:title => nav_item.title, :class => nav_item.class.name.underscore}
item[:items] = create_dynamic_items(nav_item.children)
View
@@ -6,11 +6,18 @@
Sham.email { Faker::Internet.email }
Sham.title { Faker::Lorem.sentence }
Sham.body { Faker::Lorem.paragraph }
+#Sham.url { "http://somedomain.com" }
Category.blueprint do
name
end
+MenuItem.blueprint do
+ label {Sham.name}
+ url { "http://somedomain.com" }
+ site_id {1}
+end
+
Page.blueprint do
name
end
@@ -6,8 +6,8 @@
= f.label :label
= f.text_field :label
%fieldset
- = f.label :link
- = f.text_field :link
+ = f.label :url
+ = f.text_field :url
%fieldset
= f.label :title
= f.text_field :title
@@ -2,7 +2,7 @@ class CreateMenuItems < ActiveRecord::Migration
def self.up
create_table(:menu_items) do |t|
t.string :label
- t.string :link
+ t.string :url
t.string :title
t.integer :parent_id, :default => 0
t.integer :position
View
@@ -21,13 +21,14 @@
create_table "menu_items", :force => true do |t|
t.string "label"
- t.string "link"
+ t.string "url"
t.string "title"
t.integer "parent_id", :default => 0
t.integer "position"
t.string "highlights_on"
t.integer "navigable_id"
t.string "navigable_type"
+ t.integer "site_id"
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -2,11 +2,22 @@
describe MenuItem do
#before {reset_database}
+ describe "on validations" do
+ it "should require label and url if navigable is not present" do
+ MenuItem.new.should_not be_valid
+ MenuItem.new(:label => "Something").should_not be_valid
+ MenuItem.new(:url => "Something").should_not be_valid
+ MenuItem.new(:navigable => Page.make).should be_valid
+ MenuItem.new(:label => "", :url => "").should_not be_valid
+ MenuItem.new(:label => "Not blank", :url => "Some url").should be_valid
+ end
+ end
+
describe "when configuring ordered_tree" do
# After we run the tests, reset the ordered tree changes we may have made
after { MenuItem.class_eval {
ordered_tree # set ordered_tree with no args
- def scope_condition; "1"; end # this is the default scope condition in ordered_tree gem
+ def scope_condition; "1=1"; end # this is the default scope condition in ordered_tree gem
} }
it "should allow overriding of ordered_tree's scope_condition" do
@@ -15,19 +26,19 @@ def scope_condition
"site_id = #{site_id}"
end
end
- MenuItem.create(:site_id => 1)
- MenuItem.create(:site_id => 2)
- menu_item = MenuItem.create(:site_id => 1)
+ MenuItem.make(:site_id => 1)
+ MenuItem.make(:site_id => 2)
+ menu_item = MenuItem.make(:site_id => 1)
menu_item.position.should == 2
end
it "should allow reconfiguration of ordered_tree" do
MenuItem.class_eval do
ordered_tree :scope => :site
end
- MenuItem.create(:site_id => 3)
- MenuItem.create(:site_id => 4)
- menu_item = MenuItem.create(:site_id => 3)
+ MenuItem.make(:site_id => 3)
+ MenuItem.make(:site_id => 4)
+ menu_item = MenuItem.make(:site_id => 3)
menu_item.position.should == 2
end
end
@@ -104,7 +115,7 @@ def scope_condition
end
describe "and :title is not set," do
- it "should default to the value of the nav_item's link" do
+ it "should default to the value of the nav_item's url" do
c = Category.create
nav_item = MenuItem.new(:navigable => c)
nav_item.should_receive(:label).once
@@ -115,32 +126,32 @@ def scope_condition
end
end
- describe "#link" do
- describe "when the link field is not nil," do
+ describe "#url" do
+ describe "when the url field is not nil," do
it "should return the value" do
- MenuItem.new(:link => "/holy/moly").link.should == "/holy/moly"
+ MenuItem.new(:url => "/holy/moly").url.should == "/holy/moly"
end
end
- describe "when the link field is nil," do
+ describe "when the url field is nil," do
describe "and there is a nav_item," do
it "should return the nav_item" do
# by returning the nav_item we can leave it up to the renderer to convert it to a URL
c = Category.create
- MenuItem.new(:navigable => c).link.should == c
+ MenuItem.new(:navigable => c).url.should == c
end
end
describe "and there is no nav_item," do
it "should return nil" do
- MenuItem.new.link.should be_nil
+ MenuItem.new.url.should be_nil
end
end
end
end
describe "#highlights_on," do
- describe "when the link field is not nil" do
+ describe "when the url field is not nil" do
it "should return the string value converted to regex" do
item = MenuItem.create(:highlights_on => "holy")
item.highlights_on.should == /holy/
@@ -152,8 +163,8 @@ def scope_condition
end
end
- describe "when the link field is nil," do
- it "should return the same value as link" do
+ describe "when the url field is nil," do
+ it "should return the same value as url" do
c = Category.create
nav_item = MenuItem.new(:navigable => c)
nav_item.highlights_on.should == c
@@ -191,17 +202,17 @@ def scope_condition
end
describe "and the :highlights_on is not set," do
- it "should return the same value as the link" do
+ it "should return the same value as the url" do
c = Category.create
nav_item = MenuItem.new(:navigable => c)
- nav_item.highlights_on.should == nav_item.link
+ nav_item.highlights_on.should == nav_item.url
end
end
end
describe "and there is no navigable," do
it "should return nil" do
- MenuItem.new.link.should be_nil
+ MenuItem.new.url.should be_nil
end
end
end

0 comments on commit 3cd857e

Please sign in to comment.