Apply position to routes annotations, enable index annotations #4

Merged
merged 3 commits into from Mar 18, 2012
Jump to file or symbol
Failed to load files and symbols.
+44 −4
Diff settings

Always

Just for now

View
@@ -67,6 +67,12 @@ You can disable run at start with (default is true):
...
end
+You can annotate indexes on your models with (default is false):
+
+ guard 'annotate', :show_indexes => true
+ ...
+ end
+
== Development
- Source hosed at {GitHub}[https://github.com/cpjolicoeur/guard-annotate]
View
@@ -15,6 +15,7 @@ def initialize( watchers=[], options={} )
options[:tests] = false if options[:tests].nil?
options[:routes] = false if options[:routes].nil?
options[:run_at_start] = true if options[:run_at_start].nil?
+ options[:show_indexes] = false if options[:show_indexes].nil?
end
def start
@@ -55,15 +56,21 @@ def annotate_tests_flags
options[:tests] ? "" : "--exclude tests,fixtures"
end
+ def show_indexes?
+ options[:show_indexes]
+ end
+
def run_annotate
UI.info 'Running annotate', :reset => true
started_at = Time.now
- @result = system("bundle exec annotate #{annotate_tests_flags} -p #{annotation_position}")
+ annotate_models_command = "bundle exec annotate #{annotate_tests_flags} -p #{annotation_position}"
+ annotate_models_command += " --show-indexes" if show_indexes?
+ @result = system(annotate_models_command)
Notifier::notify( @result, Time.now - started_at ) if notify?
if annotate_routes?
started_at = Time.now
- @result = system("bundle exec annotate -r")
+ @result = system("bundle exec annotate -r -p #{annotation_position}")
Notifier::notify( @result, Time.now - started_at ) if notify?
end
@@ -39,7 +39,22 @@
it "should allow the users to run routes if desired" do
subject = Guard::Annotate.new( [], :routes => true)
- subject.should_receive(:system).twice
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
+ subject.should_receive(:system).with("bundle exec annotate -r -p before")
+ subject.start
+ end
+
+ it "should allow the user to customize routes annotation position (before)" do
+ subject = Guard::Annotate.new( [], :routes => true, :position => 'before')
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
+ subject.should_receive(:system).with("bundle exec annotate -r -p before")
+ subject.start
+ end
+
+ it "should allow the user to customize routes annotation position (after)" do
+ subject = Guard::Annotate.new( [], :routes => true, :position => 'after')
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p after")
+ subject.should_receive(:system).with("bundle exec annotate -r -p after")
subject.start
end
end
@@ -49,12 +64,24 @@
subject.options[:tests].should be_false
end
- it "should allo user to run tests and fixtures annotations if desired" do
+ it "should allow user to run tests and fixtures annotations if desired" do
subject = Guard::Annotate.new( [], :tests => true )
subject.should_receive(:system).with("bundle exec annotate -p before")
subject.start
end
end
+
+ describe "indexes" do
+ it "should not add indexes to annotations by default" do
+ subject.options[:show_indexes].should be_false
+ end
+
+ it "should allow user to add indexes to annotations if desired" do
+ subject = Guard::Annotate.new( [], :show_indexes => true )
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before --show-indexes")
+ subject.start
+ end
+ end
end
end