Created
January 20, 2012 22:32
-
-
Save itspriddle/1649999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/autoload/rails.vim b/autoload/rails.vim | |
index efff7c1..ed7e0bd 100644 | |
--- a/autoload/rails.vim | |
+++ b/autoload/rails.vim | |
@@ -393,7 +393,7 @@ function! s:readable_model_name(...) dict abort | |
elseif f =~ '\<\%(test\|spec\)/exemplars/.*_exemplar\.rb$' | |
return s:sub(f,'.*<%(test|spec)/exemplars/(.*)_exemplar\.rb$','\1') | |
elseif f =~ '\<\%(test/\|spec/\)\=factories/.*\.rb$' | |
- return s:sub(f,'.*<%(test/|spec/)=factories/(.{-})%(_factory)=\.rb$','\1') | |
+ return rails#singularize(s:sub(f,'.*<%(test/|spec/)=factories/(.{-})%(_factory)=\.rb$','\1')) | |
elseif f =~ '\<\%(test/\|spec/\)\=fabricators/.*\.rb$' | |
return s:sub(f,'.*<%(test/|spec/)=fabricators/(.{-})%(_fabricator)=\.rb$','\1') | |
elseif a:0 && a:1 | |
@@ -2157,6 +2157,7 @@ function! s:BufFinderCommands() | |
call s:addfilecmds("lib") | |
call s:addfilecmds("environment") | |
call s:addfilecmds("initializer") | |
+ call s:addfilecmds("factory") | |
endfunction | |
function! s:completion_filter(results,A) | |
@@ -2275,6 +2276,10 @@ function! s:fixturesList(A,L,P) | |
return s:completion_filter(rails#app().relglob("test/fixtures/","**/*")+rails#app().relglob("spec/fixtures/","**/*"),a:A) | |
endfunction | |
+function! s:factoryList(A,L,P) | |
+ return s:completion_filter(rails#app().relglob("test/factories/","**/*",".rb")+rails#app().relglob("spec/factories/","**/*",".rb"),a:A) | |
+endfunction | |
+ | |
function! s:localeList(A,L,P) | |
return s:completion_filter(rails#app().relglob("config/locales/","**/*"),a:A) | |
endfunction | |
@@ -2556,6 +2561,26 @@ function! s:fixturesEdit(cmd,...) | |
endif | |
endfunction | |
+function! s:factoryEdit(cmd,...) | |
+ if a:0 | |
+ let c = rails#underscore(a:1) | |
+ else | |
+ let c = rails#pluralize(s:model(1)) | |
+ endif | |
+ if c == "" | |
+ return s:error("E471: Argument required") | |
+ endif | |
+ let e = fnamemodify(c,':e') | |
+ let e = e == '' ? e : '.'.e | |
+ let c = fnamemodify(c,':r') | |
+ let file = get(rails#app().test_suites(),0,'test').'/factories/'.c.e | |
+ if file =~ '\.\w\+$' && rails#app().find_file(c.e,["test/factories","spec/factories"]) ==# '' | |
+ call s:edit(a:cmd,file) | |
+ else | |
+ call s:findedit(a:cmd,rails#app().find_file(c.e,["test/factories","spec/factories"],[".rb"],file)) | |
+ endif | |
+endfunction | |
+ | |
function! s:localeEdit(cmd,...) | |
let c = a:0 ? a:1 : rails#app().default_locale() | |
if c =~# '\.' | |
diff --git a/doc/rails.txt b/doc/rails.txt | |
index 5701316..1ee1450 100644 | |
--- a/doc/rails.txt | |
+++ b/doc/rails.txt | |
@@ -294,6 +294,12 @@ itself!). | |
extension can be given, to distinguish between YAML | |
and CSV fixtures. | |
+ *rails-:Rfactories* | |
+:Rfactory [{name}] Edit the factory for the given or current model. If | |
+ an argument is given, it must be pluralized, like the | |
+ final filename (this may change in the future). If | |
+ omitted, the current model is pluralized. | |
+ | |
*rails-:Rfunctionaltest* | |
:Rfunctionaltest [{name}] | |
Edit the functional test or controller spec for the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment