Posted by ch0wda on October 06 2007 at 08:51 AM
On
Gonwodo,
Aaron and I decided to use
RSpec for our tests. We were getting a really strange error when attempting to print out the spec docs through the rake tasks. We had actually never written any specifications, just it “foo foo foo” methods in order to get pending tests. The error we were getting was:
A New User
-- NO NAME (Because of --dry-run)
-- NO NAME (Because of --dry-run)
-- NO NAME (Because of --dry-run)
I was able to determine that the rake task does indeed call dry run. Here’s the task,
1
2
3
4
5
6
|
desc "Print Specdoc for all specs (excluding plugin specs)"
Spec::Rake::SpecTask.new(:doc) do |t|
t.spec_opts = ["--format", "specdoc", "--dry-run"]
t.spec_files = FileList['spec/**/*_spec.rb']
end
|
This is actually the expected behavior, as RSpec is attempting to generate the names of the specs using the code internally. The problem with the dry-run is that it never executes the code so the names cannot be determined. In order to have the empty tests generate the necessary spec doc you would do:
./script/spec spec -fs
I’m not sure that I understand why this is the expected behavior because I give the test a name, so I’m not expecting it to be run. If anyone has an explanation, I would greatly appreciate it.
Posted by ch0wda on June 08 2007 at 12:21 PM
For one of the projects I’m doing at
Cardinal, I’m using a polymorphic association. The nature of
Camping is to write terse, yet simple code. For example, creating a new record in a controller is normally done in a one-liner, like so:
1
2
3
4
5
6
7
8
|
class Add
def post
@person = Person.create(:name => input.person_name, :age => input.person_age)
redirect R(List)
end
end
|
Here’s something that I got caught up on for 20 minutes this morning. When adding polymorphic associations, make sure that the [polymorphic name]_type field includes all the namespace information. Here’s an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# models
def Person < Base; has_many :addresses, :as => :addressable; end
def Address < Base; belongs_to :addressable, :polymorphic => true; end
# relevant portion of the views
...
label 'Type', :for => 'addressable_type'; br
addressable_select("addressable_type"); br
label 'person', :for => 'person_id'; br
person_select("person_id", @people); br
...
# controller
class Add
def post
@addressable = Person.find(input.person_id) if input.addressable_type == "Person"
@address = Address.create(:street => input.address_street,
:city => input.address_city,
:state => input.address_state,
:zip => input.address_zip,
:addressable_type => @addressable.class, #use the class name to get namespace
:addressable_id => @addressable.id)
redirect List
end
end
|
There’s a number of ways to solve this, although I found this to be the simplest for a form where you can select multiple models. The point is to make sure that you have that namespace information in the database, otherwise you will receive “Uninitialized Constant” errors for the addressable class.
Happy Camping!
Posted by ch0wda on April 18 2007 at 12:56 PM
For the most part, I followed the instructions at Dima’s Rails On Emacs page. This worked for the most part, however there were several gotchas that crept up as I was working my way through. Here’s what I did, that might be different than the other tutorials:
- I placed the snippets.el and find-recursive.el into the folder that I checked out the Rails on Emacs code. (Perhaps this is what he meant by install, but I originally had them in .emacs.d, and that was wrong.) ruby-inf.el did, however remain in .emacs.d
- I reinstalled ruby and installed ruby-elisp from synaptic. I did this because I read that when you install ruby on debian/ubuntu it will automatically install the necessary emacs modes.
- Tip After opening emacs, change your buffer to “Messages” it will have all the init information, and I found it very handy for debugging.
I’m also going to install the Emacs Code Browser, which is supposed to provide some parsing of files to show methods, and other view-related functions.
Here’s my .emacs file:
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(standard-indent 2))
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(default ((t (:stipple nil :background "#000000" :foreground "#00ff00" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 164 :width normal :family "adobe-courier")))))
;; this line makes a file executable after saving it
;; (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
(setq load-path (cons "~/.emacs.d/emacs-rails" load-path))
(require 'rails)
Resourceful Links
Posted by ch0wda on March 29 2007 at 02:31 PM
Here’s a little tip for those using Mephisto/Ubuntu. I recently installed Dan Webb’s Delicious
Plugin for Mephisto. I could not get my blog started after I installed it however. A little digging lead me to the following line:
no such file to load 'net/https'
Huh? It turns out that since I’m using the Deprec gem, I did not have libopenssl-ruby debian package installed. A little apt-get tom foolery and we’re back up and running. Here’s my point though… I really wish that the Ubuntu camp and the Ruby camp would get together. I’m no OS architect, but it seems to me that it shouldn’t be a completely different ecosystem between the two. I love Gems and I love apt-get, I just wish they would work together.