Rspec selecting wrong table name - ruby-on-rails

I'm trying to get RSpec up and running on my new mountable engine gem. I've followed the guides for setting up rspec on a mountable engine. I'm falling short when I'm setting up fixtures. it's not namespacing the tablename _clips so i'm getting a sql error. I know there's some problems with this and was wondering if there was a good solution.
THanks for your help.

This might be fixed by https://github.com/rspec/rspec-rails/issues/448 (fixed in git, but not yet released). Try pointing your Gemfile to rspec-rails from github and see if does:
gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git"

Related

Security Update for Spree Finding Nil for Money:Class

This security update for spree just released, but after running some Cucumber tests, I had this recurring issue:
undefined method `assume_from_symbol' for Money:Class (ActionView::Template::Error)
I searched the project repo on GH and we don't use the method. Searched the Money repo and also no findings. Searched Spree and found this. The method appears to be undefined on my development environment.
I don't know if its Spree or the project I'm dealing with. Does anyone know how to fix this?
Update: When I run bundle exec zeus cucumber I don't get these errors...
Just had this issue, followed the advice in: https://github.com/spree/spree/issues/4517
IE: add this to your Gemfile
gem 'money', '6.0.1'
fixed my issue.
I believe this is a bug in Spree:
https://github.com/spree/spree/issues/4517
You should specify the following in your Gemfile:
gem 'money', '=6.0.1'
to work around the issue for now.
Answer provided by John worked for me. However, I also had to edit the Gemfile with TextMate (or your own text editor) to make sure the single quotes are correct, as explained in this post: Gem syntax error questions

how to set up nulldb in rails with rspec?

I'm almost new to rails development. I'm currently reading Avdi Grimm's Objects on Rails for having a #SOLID design in my rails apps instead of being forced to some conventions which will create mess and unreadable code and design.
I wanna setup nulldb and use it in my fast specs which are testing the business logic of the application but I can't get it to work. I read the installation guide at nulldb GitHub page here -> https://github.com/nulldb/nulldb. I installed the activerecord-nulldb-adapter gem and put it also in my Gemfile and ran the bundle install command so it's completely installed now. I have a spec_helper_lite.rb file which I use in my fast specs so I though it's a good idea to setup nulldb in it. Here's the code for nulldb part in my spec_helper_lite.rb file:
require 'nulldb_rspec'
def setup_nulldb
schema_path = File.expand_path("../db/schema.rb", File.dirname(__FILE__))
ActiveRecord::Base.establish_connection(:adapter => :nulldb,
:schema => schema_path)
NullDB.nullify(:schema => schema_path)
end
def teardown_nulldb
NullDB.restore
end
then I require this spec_helper_lite.rb in my fast specs and I call the setup and teardown nulldb method in before and after methods of my spec. when I run the specs I'll get the error Uninitialized Constant ActiveRecord::ConnectionNotEstablished (NameError). I tried different things like removing that establish_connection line in the setup_nulldb and I'll get the same error. I even required 'active_record' in my spec_helper_lite just to see what will happen and then I'll get the error "undefined method nullify" for NullDB module and obviously the spec became completely slow cause of requiring active_record. I searched a lot about how to setup nulldb and everything I saw explained about setting it up this way but it doesn't work for me. I use nulldb version 0.2.1, rails 3.0.0 and rspec 2.0.1
I appreciate your help about how to set this up correctly. Thanks in advance.
Sam
I was having similar issues (but using minitest, and activerecord independent of rails). I tried all the same stuff you mentioned. Turns out I was just using whatever was in rubygems. It looks like updating my Gemfile to pull directly from github resolved the issue:
group :development, :test do
gem 'activerecord-nulldb-adapter', :git => 'git://github.com/nulldb/nulldb.git'
end
You'll want to bundle install again after updating.

How do I ruby-debug in a spec or feature if I am using Guard and Spork?

I managed to get Cucumber, RSpec, Guard, and Spork play nicely with each other in a Rails 3 app, but now I am stuck with the above problem.
Currently I require 'spork/ext/ruby-debug' in the prefork block of spec_helper.rb but this works only if I run spork manually, without guard.
This worked for me: Replace your 'guard-spork' gem with this one:
gem 'guard-spork', :git => 'https://github.com/irohiroki/guard-spork.git'
More info on this blog post (in Japanese, but Google translate does a decent job).
The author also created this handy Rails 3 example app to show how to set things up.
Adding Guard to Spork makes it much more useful IMO. I may have to go back to using it now :)
If you still have problems (or even if you don't,) I would recommend using the pry and pry-nav gems instead of Ruby debug.. they work flawlessly with guard/spork/rspec/cucumber and test unit.

Installing and using acts-as-taggable-on

This is going to be a really dumb question, I just know it, but I'm going to ask anyways because it's driving me crazy.
How do I get acts-as-taggable-on to work?
I installed it as a gem with gem install acts-as-taggable-on because I can't ever seem to get installing plugins to work, but that's a whole other batch of questions that are all probably really dumb. Anyways, no problems there, it installed correctly.
I did ruby script/generate acts_as_taggable_on_migration and rake db:migrate, again no problems.
I added acts_as_taggable to the model I want to use tags with, started up the server and then loaded the index for the model just to see if what I've got so far is working and got the following error: undefined local variable or method `acts_as_taggable' for #.
I figure that just means I need to do something like require 'acts-as-taggable-on' to my model's file because that's typically what's necessary for gems. So I did that hit refresh and got uninitialized constant ActiveRecord::VERSION. I'm not even going to pretend to begin to know what that means went wrong.
Did I go wrong somewhere or there something else I need to do. The installation instructions seem to me like they just assume you generally know what you're doing and don't even begin to explain what to do when things go wrong.
Did you try to define your gem dependencies in config/environment.rb (Rails 2.3):
Rails::Initializer.run do |config|
#...
config.gem 'acts-as-taggable-on'
#...
end
Or in Gemfile for Rails 3 or if you use already Bundler with rails 2.3:
gem 'acts-as-taggable-on'
This should make the require 'acts-as-taggable-on' unnecessary
Maybe following the installation here can help.
For example you don't need to:
require 'acts-as-taggable-on'
but:
class User < ActiveRecord::Base
acts_as_taggable
end
Otherwise you need to post more details about the error.
I installed acts-as-taggable-on for my app through github. If you want to try that method instead of the gem, you can read my this post that explains my experience: http://blog.mediummassage.com/2010/04/27/creating-categories-in-the-store-with-tags/

Necessary steps for using a gem (e.g. json) in Ruby on Rails app?

I'm having trouble getting rubygems to work in my Rails app. Specifically, I'm trying to use the json gem, documented here: http://flori.github.com/json/ I can successfully use JSON.parse() in IRB and script/console but not in my rails app.
I know it's some combination of config.gem 'json' in environment.rb and other things, but can't find a good explanation anywhere.
Can someone give me a concise list of what is required to use this gem OR point me towards comprehensive documentation of using gems in Rails? thanks!
config.gem is used for gem dependency in rails and it does nothing more than telling rails that a gem is needed, and helping the user install the appropriate gem, etc (more details here: http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies)
however by installing a gem, it should be able to be used by the rails app automatically, if not, probably you can add require "json" into environment.rb or in an .rb files in the initializers folder?
Hope it helps =)
I solved it. There's decent documentation here: http://apidock.com/rails/Rails/Configuration/gem
Once you have used config.gem in environment.rb, you should not need to 'require' it later.
My problem was that I had not stopped and restarted the server! It worked in script/console because everything was getting reloaded every time.

Resources