On 9 Jun 2011, at 15:06, Iain Barnett wrote:
>
> On 9 Jun 2011, at 04:27, Jeremy Evans wrote:
>
>> You can use the Sequel::Migration API:
>>
>> Sequel.extension :migration
>> Sequel::Migration.descendants.clear
>> require 'migrate/001_project'
>> Sequel::Migration.descendants.each{|m| m.apply(DB, :up)}
>>
>> You may want to give migration.rb a read:
>> https://github.com/jeremyevans/sequel/tree/master/lib/sequel/extensions/migration.rb
>
> Thanks Jeremy, that's very helpful indeed. Much appreciated.
>
> Regards,
> Iain
Hi again,
I got halfway through this when life had other plans for me, but I'm back to it
and I'm having some problems, I'm not sure if it's to do with the migration or
the model I've set up.
I've set up a very simple spec just to get started with - set up the db, a
model, and save a instance of the model. I'm trying out the models with the
Twitter bot I had running with non-model sequel, but on running rspec I get
this error message:
Failures:
1) TwitterSearchBot::Tweet save
Failure/Error: Tweet.new( {
Sequel::Error:
method profile_image_url= doesn't exist or access is restricted to it
I check via logger that the tables exists and the schema for Tweets is correct,
and it is.
Here's the model:
module TwitterSearchBot
class Tweet < Sequel::Model
require 'digest/sha2'
def before_create
self.signature ||= Digest::SHA2.hexdigest( self.text_of )
super
end # def
end
end
the migration:
Sequel.migration do
up do
create_table(:tweets) do
primary_key :tweets_id
Bignum :id, :null=>false
Integer :from_user_id
String :from_user, :size=>15, :null=>false
String :profile_image_url, :size=>120
DateTime :created_at, null: false, default: DateTime.now
String :text_of, :size=>200, :null=>false
String :iso_language_code, :size=>2, :fixed=>true
String :source, :size=>160
String :signature, size:64, :fixed=>true
unique [:id, :signature]
end
end
down do
drop_table(:tweets)
end
end
and here's the spec:
require 'rspec'
require 'sequel'
module TwitterSearchBot
DB = Sequel.sqlite #File.join( File.dirname(__FILE__), 'test.db' ) # I
initially tried it with an in-memory db, but a file is no different to the
outcome
require_relative "../lib/twittersearchbot/models/tweets.rb"
describe Tweet do
before(:all){
Sequel.extension :migration
Sequel::Migration.descendants.clear
require_relative '../migrations/001_project.rb'
Sequel::Migration.descendants.each{|m| m.apply(DB, :up)}
}
describe :save do
let(:tweet) {
Tweet.new( {
profile_image_url:
"http://a2.twimg.com/profile_images/1265498387/IMG00039-20101216-2004_normal.jpg",
#this is where it blows up
created_at: "Thu, 17 Mar 2011 20:10:14 +0000",
from_user: "iain_mk2",
text_of: ""You are the light. The calm in the day." That
Stephen Malkmus knows how to write a lyric.",
id: rand(100_000_000_000_000_000),
from_user_id: rand(1000_000_000),
source: "<a href="http://blackberry.com/twitter"
rel="nofollow">Twitter for BlackBerry\\u00ae</a>" , })
}
subject { tweet.save }
it { should_not be_nil }
end # :save
end # Tweet
end # module
I just don't see what it is I'm doing wrong here. I've also tried filling the
db before the test is called using some data I've already downloaded from
Twitter, using `DB[:tweets].multi_insert tweets` and it works fine.
Sorry if I'm missing something that should be obvious, I don't mean to waste
anyone's time and I appreciate all the help I've been getting on here.
sequel (3.24.1), rspec (2.6.0)
Btw, that's not my picture at the end of the image link in case anyone looks!
:-D
Regards,
Iain
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.