spec/shared/users_and_tasks.rb in rom-sql-1.0.1 vs spec/shared/users_and_tasks.rb in rom-sql-1.0.2
- old
+ new
@@ -1,28 +1,42 @@
-shared_context 'users and tasks' do
- include_context 'database setup'
+RSpec.shared_context 'users and tasks' do
+ include_context 'users'
+ let(:tasks) { container.relations[:tasks] }
+
before do
- conn[:users].insert id: 1, name: 'Jane'
- conn[:users].insert id: 2, name: 'Joe'
+ inferrable_relations.concat %i(tasks tags task_tags)
+ end
+ before do |example|
+ ctx = self
+
+ conn.create_table :tasks do
+ primary_key :id
+ foreign_key :user_id, :users
+ String :title, unique: true
+ constraint(:title_length) { char_length(title) > 1 } if ctx.postgres?(example)
+ constraint(:title_length) { length(title) > 1 } if ctx.sqlite?(example)
+ end
+
+ conn.create_table :tags do
+ primary_key :id
+ String :name
+ end
+
+ conn.create_table :task_tags do
+ primary_key [:tag_id, :task_id]
+ Integer :tag_id
+ Integer :task_id
+ end
+ end
+
+ before do |example|
+ next if example.metadata[:seeds] == false
+
conn[:tasks].insert id: 1, user_id: 2, title: "Joe's task"
conn[:tasks].insert id: 2, user_id: 1, title: "Jane's task"
conn[:tags].insert id: 1, name: 'important'
conn[:task_tags].insert(tag_id: 1, task_id: 1)
-
- conn[:posts].insert(
- post_id: 1,
- author_id: 2,
- title: "Joe's post",
- body: 'Joe wrote sutin'
- )
-
- conn[:posts].insert(
- post_id: 2,
- author_id: 1,
- title: "Jane's post",
- body: 'Jane wrote sutin'
- )
end
end