repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
postmodern/nokogiri-diff
https://github.com/postmodern/nokogiri-diff/blob/ea873edceb4e42fcdfc5a729ba899dff6ee68d80/lib/nokogiri/diff/xml.rb
lib/nokogiri/diff/xml.rb
# frozen_string_literal: true require_relative 'xml/node' require_relative 'xml/document'
ruby
MIT
ea873edceb4e42fcdfc5a729ba899dff6ee68d80
2026-01-04T17:49:08.631513Z
false
postmodern/nokogiri-diff
https://github.com/postmodern/nokogiri-diff/blob/ea873edceb4e42fcdfc5a729ba899dff6ee68d80/lib/nokogiri/diff/xml/node.rb
lib/nokogiri/diff/xml/node.rb
# frozen_string_literal: true require 'nokogiri' require 'tdiff' class Nokogiri::XML::Node include TDiff include TDiff::Unordered # # Compares the XML/HTML node with another. # # @param [Nokogiri::XML::Node] node # The other XMl/HTML node. # # @return [Boolean] # Specifies whether the two nodes are equal. # def tdiff_equal(node) if (self.class == node.class) case node when Nokogiri::XML::Attr (self.name == node.name && self.value == node.value) when Nokogiri::XML::Element, Nokogiri::XML::DTD self.name == node.name when Nokogiri::XML::Text, Nokogiri::XML::Comment self.text == node.text when Nokogiri::XML::ProcessingInstruction (self.name == node.name && self.content == node.content) else false end else false end end # # Enumerates over the children of another XML/HTML node. # # @param [Nokogiri::XML::Node] node # The other XMl/HTML node. # # @yield [child] # The given block will be passed every child of the node. # # @yieldparam [Nokogiri::XML::Node] node # A child node. # def tdiff_each_child(node,&block) if node.kind_of?(Nokogiri::XML::Element) node.attribute_nodes.sort_by(&:name).each(&block) end node.children.each(&block) end # # Finds the differences between the node and another node. # # @param [Nokogiri::XML::Node] other # The other node to compare against. # # @param [Hash] options # Additional options for filtering changes. # # @option options [Boolean] :added # Yield nodes that were added. # # @option options [Boolean] :removed # Yield nodes that were removed. # # @yield [change, node] # The given block will be passed each changed node. # # @yieldparam [' ', '-', '+'] change # Indicates whether the node stayed the same, was removed or added. # # @yieldparam [Nokogiri::XML::Node] node # The changed node. # # @return [Enumerator] # If no block was given, an Enumerator object will be returned. # def diff(other,options={},&block) return enum_for(__method__,other,options) unless block if (options[:added] || options[:removed]) tdiff_unordered(other) do |change,node| if (change == '+' && options[:added]) then yield change, node elsif (change == '-' && options[:removed]) then yield change, node end end else tdiff(other,&block) end end end
ruby
MIT
ea873edceb4e42fcdfc5a729ba899dff6ee68d80
2026-01-04T17:49:08.631513Z
false
postmodern/nokogiri-diff
https://github.com/postmodern/nokogiri-diff/blob/ea873edceb4e42fcdfc5a729ba899dff6ee68d80/lib/nokogiri/diff/xml/document.rb
lib/nokogiri/diff/xml/document.rb
# frozen_string_literal: true require_relative 'node' class Nokogiri::XML::Document < Nokogiri::XML::Node # # Overrides `tdiff` to only compare the child nodes of the document. # def tdiff(tree,&block) return enum_for(__method__,tree) unless block tdiff_recursive(tree,&block) return self end # # Overrides `tdiff_unordered` to only compare the child nodes of the document. # def tdiff_unordered(tree,&block) return enum_for(__method__,tree) unless block tdiff_recursive_unordered(tree,&block) return self end end
ruby
MIT
ea873edceb4e42fcdfc5a729ba899dff6ee68d80
2026-01-04T17:49:08.631513Z
false
masa16/holiday_japan
https://github.com/masa16/holiday_japan/blob/92515c93e9f36cf46be49f1255137ee85aa41a28/test/holiday_japan_test.rb
test/holiday_japan_test.rb
require "test/unit" require "holiday_japan" require "csv" $csv_file = File.join(__dir__,"holiday.csv") # write CSV data and exit case ARGV[0] when /^w/i CSV.open($csv_file,"w"){|c| HolidayJapan.between($first_year,$last_year).each{|a| c<<a}} exit end $csv = CSV.open(File.join(__dir__,"holiday.csv"),"r") $hash = {} $list = [] $csv.each do |str,name| date = Date.parse(str) $hash[date.year] ||= {} $hash[date.year][date] = name $list << [date,name] end y = $hash.keys $range = y.min..y.max class HolidayJapanTest < Test::Unit::TestCase test "name" do $list.each do |date,name| assert{ HolidayJapan.name(date) == name } end end test "hash_year" do $range.each do |year| assert{ HolidayJapan.hash_year(year) == $hash[year] } end end test "list_year" do $range.each do |year| HolidayJapan.list_year(year).each do |date,name| assert{ $hash[year][date] == name } end end end end
ruby
MIT
92515c93e9f36cf46be49f1255137ee85aa41a28
2026-01-04T17:49:13.265241Z
false
masa16/holiday_japan
https://github.com/masa16/holiday_japan/blob/92515c93e9f36cf46be49f1255137ee85aa41a28/lib/holiday_japan.rb
lib/holiday_japan.rb
# -*- coding: utf-8 -*- # (C) Copyright 2003-2017 by Masahiro TANAKA # This program is free software under MIT license. # NO WARRANTY. require "date" module HolidayJapan VERSION = "1.4.4" WEEK1 = 1 WEEK2 = 8 WEEK3 = 15 WEEK4 = 22 SUN,MON,TUE,WED,THU,FRU,SAT = (0..6).to_a INF = (defined? Float::INFINITY) ? Float::INFINITY : 1e16 # 祝日データ: 1948年7月20日以降で有効 DATA = [ ["元日", [1949..INF , 1, 1 ]], ["成人の日", [2000..INF , 1, [WEEK2,MON]], [1949..1999, 1, 15 ]], ["建国記念の日",[1967..INF , 2, 11 ]], ["昭和の日", [2007..INF , 4, 29 ]], ["憲法記念日", [1949..INF , 5, 3 ]], ["みどりの日", [2007..INF , 5, 4 ], [1989..2006, 4, 29 ]], ["こどもの日", [1949..INF , 5, 5 ]], ["海の日", [2020, 7, 23 ], [2021, 7, 22 ], [2003..INF, 7, [WEEK3,MON]], [1996..2002, 7, 20 ]], ["山の日", [2020, 8, 10 ], [2021 , 8, 8 ], [2016..INF , 8, 11 ]], ["敬老の日", [2003..INF , 9, [WEEK3,MON]], [1966..2002, 9, 15 ]], ["体育の日", [2000..2019, 10, [WEEK2,MON]], [1966..1999, 10, 10 ]], ["スポーツの日",[2020, 7, 24 ], [2021, 7, 23 ], [2022..INF , 10, [WEEK2,MON]]], ["文化の日", [1948..INF , 11, 3 ]], ["勤労感謝の日",[1948..INF , 11, 23 ]], ["天皇誕生日", [2020..INF , 2, 23 ], [1989..2018, 12, 23 ], [1949..1988, 4, 29 ]], ["春分の日", [1980..2099, 3, proc{|y|(20.8431+0.242194*(y-1980)).to_i-((y-1980)/4.0).to_i} ], [1949..1979, 3, proc{|y|(20.8357+0.242194*(y-1980)).to_i-((y-1983)/4.0).to_i} ], [2100..2150, 3, proc{|y|(21.8510+0.242194*(y-1980)).to_i-((y-1980)/4.0).to_i} ], ], ["秋分の日" , [1980..2099, 9, proc{|y|(23.2488+0.242194*(y-1980)).to_i-((y-1980)/4.0).to_i} ], [1948..1979, 9, proc{|y|(23.2588+0.242194*(y-1980)).to_i-((y-1983)/4.0).to_i} ], [2100..2150, 9, proc{|y|(24.2488+0.242194*(y-1980)).to_i-((y-1980)/4.0).to_i} ], ], ["即位礼正殿の儀", [2019, 10, 22 ], [1990, 11, 12 ]], ["天皇の即位の日", [2019, 5, 1 ]], ["皇太子徳仁親王の結婚の儀", [1993, 6, 9 ]], ["昭和天皇の大喪の礼", [1989, 2, 24 ]], ["皇太子明仁親王の結婚の儀", [1959, 4, 10 ]] ] DATA.each{|x| x.each{|y| y .freeze}} DATA.freeze TABLE = {} FURIKAE_START = Date.new(1973,4,12).freeze module_function def holiday_date(year,data) data.each do |item| next if item.kind_of?(String) year_range,mon,day = *item if year_range === year case day when Integer # skip when Array day0,wday = day wday0 = Date.new(year,mon,day0).wday day = day0+(wday-wday0+7)%7 when Proc day = day.call(year) else raise "invalid holiday data" end return Date.new( year, mon, day ) end end nil end def create_table(y) h={} a=[] # list holidays DATA.each do |x| if d = holiday_date(y,x) h[d] = x[0] a << d end end # compensating holiday if y >= 2007 a.each do |d| if d.wday==SUN d+=1 while h[d] h[d] = "振替休日" end end elsif y >= 1973 a.each do |d| if d.wday==SUN and d>=FURIKAE_START h[d+1] = "振替休日" end end end # consecutive holiday if y >= 1986 a.each do |d| if h[d+2] and !h[d+1] and d.wday!=SAT h[d+1] = "国民の休日" end end end Hash[h.sort_by{|d,| d}].freeze end def name(date) y = date.year (TABLE[y] ||= create_table(y))[date] end def check(date) !HolidayJapan.name(date).nil? end def list_year(year) year = Integer(year) TABLE[year] ||= create_table(year) TABLE[year].sort_by{|x| x[0]} end def hash_year(year) TABLE[year] ||= create_table(year) end def between(from_date,to_date) case from_date when String from_date = Date.parse(from_date) when Integer from_date = Date.new(from_date,1,1) when Date else raise ArgumentError, "invalid type for from_date" end case to_date when String to_date = Date.parse(to_date) when Integer to_date = Date.new(to_date,12,31) when Date else raise ArgumentError, "invalid type for to_date" end if from_date > to_date raise ArgumentError, "to_date is earlier than from_date" end y1 = from_date.year y2 = to_date.year if y1 == y2 result = hash_year(y1).select{|d,n| d >= from_date && d <= to_date} else result = hash_year(y1).select{|d,n| d >= from_date} y = y1 + 1 while y < y2 result.merge!(hash_year(y)) y += 1 end hash_year(y).each{|d,n| result[d]=n if d <= to_date} end result end def _print_year(year) puts "listing year #{year}..." list_year(year).each do |y| puts "#{y[0].strftime('%Y-%m-%d %a')} #{y[1]}" end end def print_year(year) case year when Range year.each do |y| _print_year(y) end else _print_year(year) end end def print_between(from_date,to_date) between(from_date,to_date).each do |y| puts "#{y[0].strftime('%Y-%m-%d %a')} #{y[1]}" end end end # compatible with Funaba-san's holiday.rb class Date def national_holiday? HolidayJapan.name(self) ? true : false end end # command line if __FILE__ == $0 # print holiday list of the year begin arg = eval(ARGV[0]) rescue raise ArgumentError,"invalid argument : #{ARGV[0].inspect} usage: ruby holiday_japan.rb year" end HolidayJapan.print_year(arg) end
ruby
MIT
92515c93e9f36cf46be49f1255137ee85aa41a28
2026-01-04T17:49:13.265241Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/decorators/schema_memo_decorator.rb
app/decorators/schema_memo_decorator.rb
module SchemaMemoDecorator include MarkdownDescriptionDecorator end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/decorators/column_memo_decorator.rb
app/decorators/column_memo_decorator.rb
module ColumnMemoDecorator include MarkdownDescriptionDecorator end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/decorators/table_memo_decorator.rb
app/decorators/table_memo_decorator.rb
module TableMemoDecorator include MarkdownDescriptionDecorator end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/decorators/keyword_decorator.rb
app/decorators/keyword_decorator.rb
module KeywordDecorator include MarkdownDescriptionDecorator end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/decorators/database_memo_decorator.rb
app/decorators/database_memo_decorator.rb
module DatabaseMemoDecorator include MarkdownDescriptionDecorator end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/decorators/markdown_description_decorator.rb
app/decorators/markdown_description_decorator.rb
module MarkdownDescriptionDecorator def description_markdown @description_markdown ||= Markdown.new(description) end def description_html @description_html ||= description_markdown.html.html_safe end def description_text @description_text ||= description_markdown.text.html_safe end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/helpers/application_helper.rb
app/helpers/application_helper.rb
module ApplicationHelper def render_diff(diff) Markdown.new(<<~DIFF).html ```diff #{diff} ``` DIFF end def markdown_html(markdown) Markdown.new(markdown).html end def sql_query_format(query) rule = AnbtSql::Rule.new rule.indent_string = ' ' rule.space_after_comma = true formatter = AnbtSql::Formatter.new(rule) formatter.format(query) end def favicon_override if Rails.env.production? favicon_link_tag '/favicon.ico' else favicon_link_tag '/favicon_gray.ico' end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/helpers/data_source_helper.rb
app/helpers/data_source_helper.rb
module DataSourceHelper def subscribe?(schema_name) @subscribe_schema_names.include?(schema_name) end def exist?(schema_name) @data_source_schema_names.include?(schema_name) end def able_to_import?(schema_name) !subscribe?(schema_name) && exist?(schema_name) end def able_to_unlink?(schema_name) subscribe?(schema_name) end def disable_import_button(schema_name) able_to_import?(schema_name) ? "" : "disabled" end def disable_unlink_button(schema_name) able_to_unlink?(schema_name) ? "" : "disabled" end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/settings_controller.rb
app/controllers/settings_controller.rb
class SettingsController < ApplicationController def show @data_sources = DataSource.all @ignored_tables = IgnoredTable.all end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/table_memos_controller.rb
app/controllers/table_memos_controller.rb
class TableMemosController < ApplicationController permits :description before_action :redirect_named_path, only: :show def show(database_name, schema_name, name) @table_memo = TableMemo. includes(column_memos: :logs). joins(:schema_memo). merge(SchemaMemo.where(name: schema_name).joins(:database_memo).merge(DatabaseMemo.where(name: database_name))). where(name:). take! @view_meta_data = @table_memo.view_meta_data end def edit(id) @table_memo = TableMemo.find(id) end def update(id, table_memo) @table_memo = TableMemo.find(id) @table_memo.assign_attributes(table_memo) if @table_memo.changed? @table_memo.build_log(current_user.id) @table_memo.save! end redirect_to database_schema_table_path(@table_memo.database_memo.name, @table_memo.schema_memo.name, @table_memo.name) end def destroy(id) table_memo = TableMemo.find(id) table_memo.destroy! redirect_to database_memo_path(table_memo.database_memo.name) end private def redirect_named_path(id = nil) return unless id =~ /\A\d+\z/ table_memo = TableMemo.find(id) redirect_to database_schema_table_path(table_memo.database_memo.name, table_memo.schema_memo.name, table_memo.name) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/search_results_controller.rb
app/controllers/search_results_controller.rb
class SearchResultsController < ApplicationController permits :keyword def show(search_result) @search_result = SearchResult.new(search_result) @search_result.search!(table_page: params[:table_page], column_page: params[:column_page], per_page: 30) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/schema_memo_logs_controller.rb
app/controllers/schema_memo_logs_controller.rb
class SchemaMemoLogsController < ApplicationController def index(schema_memo_id) @schema_memo = SchemaMemo.find(schema_memo_id) @schema_memo_logs = @schema_memo.logs.reorder(id: :desc) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/column_memo_logs_controller.rb
app/controllers/column_memo_logs_controller.rb
class ColumnMemoLogsController < ApplicationController layout "colorbox" def index(column_memo_id) @column_memo = ColumnMemo.find(column_memo_id) @column_memo_logs = @column_memo.logs.reorder(id: :desc) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/markdown_previews_controller.rb
app/controllers/markdown_previews_controller.rb
class MarkdownPreviewsController < ApplicationController def create(md) @preview = MarkdownPreview.new(md) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/database_memos_controller.rb
app/controllers/database_memos_controller.rb
class DatabaseMemosController < ApplicationController permits :description before_action :redirect_named_path, only: :show def index redirect_to root_path end def show(id) @database_memo = DatabaseMemo.where(name: id).includes(schema_memos: :table_memos ).take! end def edit(id) @database_memo = DatabaseMemo.find(id) end def update(id, database_memo) @database_memo = DatabaseMemo.find(id) @database_memo.assign_attributes(database_memo) if @database_memo.changed? @database_memo.build_log(current_user.id) @database_memo.save! end redirect_to database_memo_path(@database_memo.name) end def destroy(id) database_memo = DatabaseMemo.find(id) database_memo.destroy! redirect_to root_path end private def redirect_named_path(id = nil) return unless id =~ /\A\d+\z/ redirect_to database_memo_path(DatabaseMemo.where(id:).pluck(:name).first) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/database_memo_logs_controller.rb
app/controllers/database_memo_logs_controller.rb
class DatabaseMemoLogsController < ApplicationController def index(database_memo_id) @database_memo = DatabaseMemo.find(database_memo_id) @database_memo_logs = @database_memo.logs.reorder(id: :desc) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/users_controller.rb
app/controllers/users_controller.rb
class UsersController < ApplicationController permits :name, :admin before_action :require_editable, only: %w(edit update) def index @users = User.all end def edit(id) @user = User.find(id) end def update(id, user) return head 401 if user.has_key?("admin") && !current_user.admin? @user = User.find(id) @user.update!(user) flash[:info] = "User #{@user.name} updated" redirect_to edit_user_path(@user) end private def require_editable(id) head 401 unless current_user.editable_user?(id) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/data_sources_controller.rb
app/controllers/data_sources_controller.rb
class DataSourcesController < ApplicationController before_action :require_admin_login, only: %w(new create edit update destroy import_schema remove_schema) DUMMY_PASSWORD = "__DUMMY__" def index redirect_to setting_path end def show redirect_to setting_path end def new @data_source = DataSource.new end def create ActiveRecord::Base.transaction do @data_source = DataSource.create!(data_source_params) create_or_update_bigquery_config(@data_source) end flash[:info] = t("data_source_updated", name: @data_source.name) redirect_to data_sources_path rescue ActiveRecord::ActiveRecordError => e flash[:error] = e.message redirect_to new_data_source_path end def edit(id) @data_source = DataSource.find(id) begin @data_source_schemas = @data_source.data_source_adapter.fetch_schema_names # [[schema_name, schema_owner], ...] @data_source_schema_names = @data_source_schemas.map(&:first) @imported_schema_memos = @data_source.database_memo.schema_memos @subscribe_schema_names = @imported_schema_memos.where(linked: true).map(&:name) @only_dmemo_schema_names = @imported_schema_memos.pluck(:name) - @data_source_schema_names @only_dmemo_schemas = @only_dmemo_schema_names.map { |s| [s, 'unknown'] } @all_schemas = (@data_source_schemas + @only_dmemo_schemas).sort_by { |s| s[0] } # s[0] is schema name rescue NotImplementedError => e # when not implement fetch_schema_names for adapter # data_sources/:id/edit page does not view Schema Candidates block rescue ActiveRecord::ActiveRecordError, DataSource::ConnectionBad => e flash[:error] = e.message redirect_to data_sources_path end @data_source.password = DUMMY_PASSWORD end def update(id) @data_source = DataSource.find(id) ActiveRecord::Base.transaction do @data_source.update!(data_source_params) create_or_update_bigquery_config(@data_source) end flash[:info] = t("data_source_updated", name: @data_source.name) redirect_to data_sources_path rescue ActiveRecord::ActiveRecordError, DataSource::ConnectionBad => e flash[:error] = e.message redirect_to edit_data_source_path(id) end def destroy(id) data_source = DataSource.find(id) data_source.destroy! redirect_to data_sources_path end def import_schema(id, schema_name) data_source = DataSource.includes(:database_memo).find(id) schema_memo = data_source.database_memo.schema_memos.find_or_create_by(name: schema_name) schema_memo.update!(linked: true) # import_schema redirect_to edit_data_source_path(id) end def unlink_schema(id, schema_name) data_source = DataSource.includes(database_memo: :schema_memos).find(id) schema_memo = data_source.database_memo.schema_memos.find_by(name: schema_name) schema_memo.update!(linked: false) redirect_to edit_data_source_path(id) end private def data_source_params params.require(:data_source).permit( :name, :description, :adapter, :host, :port, :dbname, :user, :password, :encoding) .reject { |k, v| k == "password" && v == DUMMY_PASSWORD } end def create_or_update_bigquery_config(data_source) return unless params[:data_source][:adapter] == 'bigquery' bigquery_config_params = params[:data_source].require(:bigquery_config).permit(:project_id, :dataset, :credentials) if bigquery_config_params[:credentials] bigquery_config_params[:credentials] = bigquery_config_params[:credentials].read end BigqueryConfig.find_or_initialize_by(data_source:).update!(bigquery_config_params) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/schema_memos_controller.rb
app/controllers/schema_memos_controller.rb
class SchemaMemosController < ApplicationController permits :description before_action :redirect_named_path, only: :show def show(database_name, name) @schema_memo = SchemaMemo.includes(table_memos: [:logs, :column_memos]).joins(:database_memo).merge(DatabaseMemo.where(name: database_name)).where(name:).take! redirect_to database_memo_path(@schema_memo.database_memo.name) if @schema_memo.single_schema? end def edit(id) @schema_memo = SchemaMemo.find(id) end def update(id, schema_memo) @schema_memo = SchemaMemo.find(id) @schema_memo.assign_attributes(schema_memo) if @schema_memo.changed? @schema_memo.build_log(current_user.id) @schema_memo.save! end redirect_to database_schema_path(@schema_memo.database_memo.name, @schema_memo.name) end def destroy(id) schema_memo = SchemaMemo.find(id) schema_memo.destroy! redirect_to database_memo_path(schema_memo.database_memo.name) end private def redirect_named_path(id = nil) return unless id =~ /\A\d+\z/ schema_memo = SchemaMemo.find(id) redirect_to database_schema_path(schema_memo.database_memo.name, schema_memo.name) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/table_memo_logs_controller.rb
app/controllers/table_memo_logs_controller.rb
class TableMemoLogsController < ApplicationController def index(table_memo_id) @table_memo = TableMemo.find(table_memo_id) @table_memo_logs = @table_memo.logs.reorder(id: :desc) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/ignored_tables_controller.rb
app/controllers/ignored_tables_controller.rb
class IgnoredTablesController < ApplicationController permits :data_source_id, :pattern before_action :require_admin_login, only: %w(new create destroy) def index redirect_to setting_path end def show redirect_to setting_path end def new @ignored_table = IgnoredTable.new @database_name_options = DataSource.pluck(:name, :id) end def create(ignored_table) @ignored_table = IgnoredTable.create!(ignored_table) redirect_to setting_path rescue ActiveRecord::ActiveRecordError => e flash[:error] = e.message redirect_to new_ignored_table_path(@ignored_table) end def destroy(id) @ignored_table = IgnoredTable.find(id) @ignored_table.destroy! redirect_to setting_path end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/keywords_controller.rb
app/controllers/keywords_controller.rb
class KeywordsController < ApplicationController permits :name, :description before_action :redirect_named_path, only: :show def index @keywords = Keyword.all.order(:name) end def show(id) @keyword = Keyword.find_by!(name: id) end def new @keyword = Keyword.new end def create(keyword) @keyword = Keyword.new(keyword) @keyword.build_log(current_user.id) @keyword.save! redirect_to @keyword end def edit(id) @keyword = Keyword.find(id) end def update(id, keyword) @keyword = Keyword.find(id) @keyword.assign_attributes(keyword) if @keyword.changed? @keyword.build_log(current_user.id) @keyword.save! end redirect_to @keyword end def destroy(id) keyword = Keyword.find(id) keyword.destroy! redirect_to keywords_path end private def redirect_named_path(id) return unless id =~ /\A\d+\z/ keyword = Keyword.find(id) redirect_to keyword_path(keyword.name) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/top_controller.rb
app/controllers/top_controller.rb
class TopController < ApplicationController def show @database_memos = DatabaseMemo.all.includes(:data_source, schema_memos: :table_memos).sort_by(&:display_order) @favorite_tables = TableMemo.where(id: current_user.favorite_tables.pluck(:table_memo_id)) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/column_memos_controller.rb
app/controllers/column_memos_controller.rb
class ColumnMemosController < ApplicationController permits :description skip_before_action :set_sidebar_databases, :set_search_result def show(id) @column_memo = ColumnMemo.find(id) redirect_to @column_memo.table_memo end def edit(id) @column_memo = ColumnMemo.find(id) render layout: "colorbox" end def update(id, column_memo) @column_memo = ColumnMemo.find(id) @column_memo.assign_attributes(column_memo) if @column_memo.changed? @column_memo.build_log(current_user.id) @column_memo.save! end redirect_to database_schema_table_path(@column_memo.database_memo.name, @column_memo.schema_memo.name, @column_memo.table_memo.name) end def destroy(id) column_memo = ColumnMemo.find(id) column_memo.destroy! redirect_to table_memo_path(column_memo.table_memo_id) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/keyword_logs_controller.rb
app/controllers/keyword_logs_controller.rb
class KeywordLogsController < ApplicationController def index(keyword_id) @keyword = Keyword.find(keyword_id) @keyword_logs = @keyword.logs.reorder(id: :desc) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/favorite_tables_controller.rb
app/controllers/favorite_tables_controller.rb
class FavoriteTablesController < ApplicationController def create(table_memo_id) @favorite_table = FavoriteTable.create!(user_id: current_user.id, table_memo_id:) end def destroy(table_memo_id) @favorite_table = FavoriteTable.find_by!(user_id: current_user.id, table_memo_id:) @favorite_table.destroy! end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/sessions_controller.rb
app/controllers/sessions_controller.rb
class SessionsController < ApplicationController skip_before_action :require_login, only: [:new, :callback] def new redirect_to root_path if session[:user_id] session[:return_to] = params[:return_to] end def callback auth = request.env["omniauth.auth"] user = User.find_or_initialize_by( provider: auth[:provider], uid: auth[:uid], ) user.assign_attributes( name: auth[:info][:name], email: auth[:info][:email], image_url: auth[:info][:image], ) user.save! if user.changed? session[:user_id] = user.id if ReturnToValidator.valid?(session[:return_to]) redirect_to session[:return_to] else redirect_to root_path end end def destroy session[:user_id] = nil redirect_to root_path end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/controllers/application_controller.rb
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base helper_method :current_user before_action :require_login before_action :set_sidebar_databases, :set_search_result, only: %w(index show new edit) private def current_user @current_user ||= User.find_by(id: session[:user_id]) if session[:user_id] end def require_login return if current_user redirect_to sign_in_path(return_to: url_for(params.to_unsafe_h.merge(only_path: true))) end def require_admin_login redirect_to root_path unless current_user.admin? end def set_sidebar_databases @sidebar_databases = DatabaseMemo.all.select(:name).order(:name) end def set_search_result @search_result = SearchResult.new end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/view_meta_datum.rb
app/models/view_meta_datum.rb
class ViewMetaDatum < ApplicationRecord belongs_to :table_memo end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/keyword.rb
app/models/keyword.rb
class Keyword < ApplicationRecord include TextDiff include DescriptionLogger has_many :logs, -> { order(:id) }, class_name: "KeywordLog" validates :name, :description, presence: true after_save :clear_keyword_links after_destroy :clear_keyword_links private def clear_keyword_links AutolinkKeyword.clear_links! if saved_change_to_name? || destroyed? end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/column_memo.rb
app/models/column_memo.rb
class ColumnMemo < ApplicationRecord include TextDiff include DescriptionLogger belongs_to :table_memo has_many :logs, -> { order(:id) }, class_name: "ColumnMemoLog" validates :name, presence: true delegate :schema_memo, to: :table_memo delegate :database_memo, to: :schema_memo def full_name "#{table_memo.database_memo.name}/#{schema_memo.name}.#{table_memo.name}/#{name}" end def display_order [linked? ? 0 : 1, position] end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source.rb
app/models/data_source.rb
class DataSource < ApplicationRecord validates :name, :adapter, presence: true validates :host, :dbname, :user, presence: true, if: :standard_adapter? has_many :ignored_tables has_one :database_memo, class_name: "DatabaseMemo", foreign_key: :name, primary_key: :name, dependent: :destroy has_one :bigquery_config, dependent: :destroy class ConnectionBad < IOError end def source_table_names table_names = access_logging { data_source_adapter.fetch_table_names } table_names.reject { |schema_name, table_name| ignore?(schema_name, table_name) } end def data_source_table(schema_name, table_name, table_names) return if ignore?(schema_name, table_name) schema_name, _ = table_names.find { |schema, table| schema == schema_name && table == table_name } return nil unless schema_name DataSourceTable.new(self, schema_name, table_name) end def data_source_tables table_names = source_table_names table_names.map do |schema_name, table_name| data_source_table(schema_name, table_name, table_names) end end def access_logging Rails.logger.tagged("DataSource #{name}") { yield } end def data_source_adapter @data_source_adapter ||= DataSourceAdapters.adapters[adapter].new(self) end def standard_adapter? adapter.in? DataSourceAdapters.standard_adapter_names end private def ignore?(schema_name, table_name) ignored_table_patterns.match("#{schema_name}.#{table_name}") end def ignored_table_patterns @ignored_table_patterns ||= Regexp.union(ignored_tables.pluck(:pattern).map { |pattern| Regexp.new(pattern, true) }) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/search_result.rb
app/models/search_result.rb
class SearchResult include ActiveModel::Model attr_accessor :keyword, :tables, :columns def search!(table_page:, column_page:, per_page:) return unless keyword.present? pattern = "%#{keyword}%" self.tables = TableMemo.where("table_memos.name LIKE ? OR table_memos.description LIKE ?", pattern, pattern) .eager_load(schema_memo: :database_memo) .order(description: :desc, updated_at: :desc) .page(table_page).per(per_page) self.columns = ColumnMemo.where("column_memos.name LIKE ? OR column_memos.description LIKE ?", pattern, pattern) .eager_load(table_memo: { schema_memo: :database_memo }) .order(description: :desc, updated_at: :desc) .page(column_page).per(per_page) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/database_memo.rb
app/models/database_memo.rb
class DatabaseMemo < ApplicationRecord include TextDiff include DescriptionLogger scope :id_or_name, ->(id, name) { where("database_memos.id = ? OR database_memos.name = ?", id.to_i, name) } has_many :schema_memos, dependent: :destroy has_many :logs, -> { order(:id) }, class_name: "DatabaseMemoLog" has_one :data_source, class_name: "DataSource", foreign_key: :name, primary_key: :name validates :name, presence: true def linked? data_source.present? end def single_schema? schema_memos.count == 1 end def display_order [linked? ? 0 : 1, name] end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/bigquery_config.rb
app/models/bigquery_config.rb
class BigqueryConfig < ApplicationRecord validates :project_id, :dataset, presence: true validates :data_source, uniqueness: true belongs_to :data_source end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/column_memo_log.rb
app/models/column_memo_log.rb
class ColumnMemoLog < ApplicationRecord belongs_to :column_memo belongs_to :user end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_table.rb
app/models/data_source_table.rb
class DataSourceTable attr_reader :data_source, :schema_name, :table_name, :full_table_name, :defined_at delegate :data_source_adapter, to: :data_source def initialize(data_source, schema_name, table_name) @data_source = data_source @schema_name = schema_name @table_name = table_name @full_table_name = "#{schema_name}.#{table_name}" @defined_at = Time.now end def columns @columns ||= data_source.access_logging { data_source_adapter.fetch_columns(self) } end def fetch_view_query @view_query ||= @data_source.access_logging { data_source_adapter.fetch_view_query(self) } end def fetch_view_query_plan @view_query_plan ||= @data_source.access_logging { data_source_adapter.fetch_view_query_plan(@view_query) } end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/ignored_table.rb
app/models/ignored_table.rb
class IgnoredTable < ApplicationRecord belongs_to :data_source validates :pattern, presence: true end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/database_memo_log.rb
app/models/database_memo_log.rb
class DatabaseMemoLog < ApplicationRecord belongs_to :database_memo belongs_to :user end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/autolink_keyword.rb
app/models/autolink_keyword.rb
class AutolinkKeyword def self.links @links ||= generate_links end def self.generate_links urls = Rails.application.routes.url_helpers links = {} DatabaseMemo.includes(schema_memos: :table_memos).each do |database_memo| database_memo.schema_memos.each do |schema_memo| schema_memo.table_memos.each do |table_memo| path = urls.database_schema_table_path(database_memo.name, schema_memo.name, table_memo.name) links[table_memo.name] = path links["#{schema_memo.name}.#{table_memo.name}"] = path end end end Keyword.pluck(:name).each do |keyword| links[keyword] = urls.keyword_path(keyword) end links end def self.clear_links! @links = nil end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters.rb
app/models/data_source_adapters.rb
module DataSourceAdapters def self.adapters @adapters ||= {} end def self.register_adapter(adapter, name) adapters[name] = adapter end def self.adapter_names adapters.keys end def self.standard_adapter_names adapters.select { |_, adapter| adapter < StandardAdapter }.keys end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/favorite_table.rb
app/models/favorite_table.rb
class FavoriteTable < ApplicationRecord belongs_to :user belongs_to :table_memo end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/keyword_log.rb
app/models/keyword_log.rb
class KeywordLog < ApplicationRecord belongs_to :keyword belongs_to :user end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/application_record.rb
app/models/application_record.rb
class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/table_memo.rb
app/models/table_memo.rb
class TableMemo < ApplicationRecord include TextDiff include DescriptionLogger scope :id_or_name, ->(id, name) { where("table_memos.id = ? OR table_memos.name = ?", id.to_i, name) } belongs_to :schema_memo has_one :view_meta_data, class_name: "ViewMetaDatum", dependent: :destroy has_many :column_memos, dependent: :destroy has_many :logs, -> { order(:id) }, class_name: "TableMemoLog", dependent: :destroy has_many :favorite_tables, dependent: :destroy validates :name, presence: true delegate :database_memo, to: :schema_memo delegate :data_source, to: :schema_memo after_save :clear_keyword_links after_destroy :clear_keyword_links def favorited_by?(user) FavoriteTable.where(user_id: user.id, table_memo_id: id).exists? end def full_name "#{database_memo.name}/#{schema_memo.name}.#{name}" end def display_order [linked? ? 0 : 1, name] end private def clear_keyword_links AutolinkKeyword.clear_links! if saved_change_to_name? || destroyed? end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/markdown.rb
app/models/markdown.rb
class Markdown attr_reader :md def initialize(md) @md = md end def html @html ||= Rails.application.config.markdown_to_html_pipeline.call(@md, html_context)[:output].html_safe end def html_context { autolink_keywords: AutolinkKeyword.links } end def text @text ||= Rails.application.config.markdown_to_text_pipeline.call(@md)[:output].html_safe end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/schema_memo_log.rb
app/models/schema_memo_log.rb
class SchemaMemoLog < ApplicationRecord belongs_to :schema_memo belongs_to :user end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/table_memo_log.rb
app/models/table_memo_log.rb
class TableMemoLog < ApplicationRecord belongs_to :table_memo belongs_to :user end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/schema_memo.rb
app/models/schema_memo.rb
class SchemaMemo < ApplicationRecord include TextDiff include DescriptionLogger belongs_to :database_memo has_many :table_memos, dependent: :destroy has_many :logs, -> { order(:id) }, class_name: "SchemaMemoLog" validates :name, presence: true delegate :data_source, to: :database_memo delegate :single_schema?, to: :database_memo def display_order [linked? ? 0 : 1, name] end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/markdown_preview.rb
app/models/markdown_preview.rb
class MarkdownPreview attr_reader :markdown delegate :html, to: :markdown def initialize(md) @markdown = Markdown.new(md) end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/user.rb
app/models/user.rb
class User < ApplicationRecord has_many :favorite_tables def editable_user?(user_id) self.id == user_id.to_i || admin? end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/concerns/text_diff.rb
app/models/concerns/text_diff.rb
module TextDiff extend ActiveSupport::Concern included do def diff(old_text, new_text) Diffy::Diff.new(old_text.to_s.chomp + "\r\n", new_text.to_s.chomp + "\r\n").to_s end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/concerns/description_logger.rb
app/models/concerns/description_logger.rb
module DescriptionLogger extend ActiveSupport::Concern included do def build_log(user_id) last_log = logs.last current_revision = last_log.try(:revision).to_i logs.build( revision: current_revision + 1, user_id:, description: self.description, description_diff: diff(last_log.try(:description), self.description), ) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters/bigquery_adapter.rb
app/models/data_source_adapters/bigquery_adapter.rb
require "google/cloud/bigquery" module DataSourceAdapters class BigqueryAdapter < Base def fetch_table_names latest_table_names.keys.map do |prefix| [bq_dataset.dataset_id, prefix] end end def fetch_columns(table) bq_table = bq_table(table) flatten_fields(bq_table.fields, '') end def disconnect_data_source! @bq_dataset = nil @latest_table_names = nil end def reset! disconnect_data_source! end private def bq_dataset return @bq_dataset if @bq_dataset config = @data_source.bigquery_config client = if config.credentials Google::Cloud::Bigquery.new( project_id: config.project_id, credentials: JSON.parse(config.credentials), ) else Google::Cloud::Bigquery.new(project_id: config.project_id) end @bq_dataset = client.dataset(config.dataset) raise DataSource::ConnectionBad.new("dataset \"#{config.dataset}\" not found") if @bq_dataset.nil? @bq_dataset end def bq_table(table) bq_dataset.table(latest_table_names[table.table_name]) end def latest_table_names return @latest_table_names if @latest_table_names @latest_table_names = {} fetch_all_table_ids.group_by { |table_id| match = table_id.match(/(.*)\d{8}\z/) # bigquery partitoned table name suffix is 'yyyymmdd' match ? match[1] : table_id }.each do |prefix, ids| @latest_table_names[prefix] = ids.max # take the latest partitoned table name end @latest_table_names end def fetch_all_table_ids bq_dataset.tables(max: 1000).all.map(&:table_id) end def flatten_fields(fields, field_prefix) result = [] fields.each do |field| nullable = field.mode.nil? || field.mode == 'NULLABLE' type = field.mode == 'REPEATED' ? "#{field.type}[]" : field.type result << Column.new("#{field_prefix}#{field.name}", type, '', nullable) result.concat(flatten_fields(field.fields, "#{field_prefix}#{field.name}.")) if field.type == 'RECORD' end result end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters/mysql2_adapter.rb
app/models/data_source_adapters/mysql2_adapter.rb
module DataSourceAdapters class Mysql2Adapter < StandardAdapter def fetch_schema_names @schema_names ||= [[@data_source.dbname, 'unknown']] end def fetch_table_names source_base_class.connection.tables.map { |table_name| [@data_source.dbname, table_name] } rescue ActiveRecord::ActiveRecordError, Mysql2::Error => e raise DataSource::ConnectionBad.new(e) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters/standard_adapter.rb
app/models/data_source_adapters/standard_adapter.rb
module DataSourceAdapters class StandardAdapter < Base def fetch_schema_names raise NotImplementedError end def fetch_table_names raise NotImplementedError end def fetch_columns(table) adapter = connection.pool.connection raw_columns(table).map { |c| Column.new(c.name, c.sql_type, adapter.quote(c.default), c.null) } rescue ActiveRecord::ActiveRecordError, Mysql2::Error, PG::Error => e raise DataSource::ConnectionBad.new(e) end def fetch_view_query_plan(query) adapter = connection.pool.connection connection.query("EXPLAIN #{query}", 'EXPLAIN').join("\n") rescue ActiveRecord::ActiveRecordError, Mysql2::Error, PG::Error => e raise DataSource::ConnectionBad.new(e) end def source_base_class return DynamicTable.const_get(source_base_class_name) if DynamicTable.const_defined?(source_base_class_name) base_class = Class.new(DynamicTable::AbstractTable) DynamicTable.const_set(source_base_class_name, base_class) base_class.establish_connection(connection_config) base_class end def reset! source_base_class.establish_connection.disconnect! DynamicTable.send(:remove_const, source_base_class_name) if DynamicTable.const_defined?(source_base_class_name) end private def raw_columns(table) connection.columns(table.full_table_name) end def connection source_base_class.connection end def source_base_class_name "#{@data_source.name.gsub(/[^\w_-]/, '').underscore.classify}_Base" end def connection_config { adapter: @data_source.adapter, host: @data_source.host, port: @data_source.port, database: @data_source.dbname, username: @data_source.user, password: @data_source.password.presence, encoding: @data_source.encoding.presence, pool: @data_source.pool.presence, }.compact end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters/postgresql_adapter.rb
app/models/data_source_adapters/postgresql_adapter.rb
module DataSourceAdapters class PostgresqlAdapter < StandardAdapter def fetch_schema_names @schema_names ||= source_base_class.connection.query(<<~SQL, 'SCHEMA') SELECT nspname as schema_name, usename as owner_name FROM pg_catalog.pg_namespace s join pg_catalog.pg_user u on u.usesysid = s.nspowner ORDER BY schema_name; SQL end def fetch_table_names source_base_class.connection.query(<<~SQL, 'SCHEMA') SELECT schemaname, tablename FROM ( SELECT schemaname, tablename FROM pg_tables UNION SELECT schemaname, viewname AS tablename FROM pg_views ) tables WHERE schemaname not in ('pg_catalog', 'information_schema') ORDER BY schemaname, tablename; SQL rescue ActiveRecord::ActiveRecordError, PG::Error => e raise DataSource::ConnectionBad.new(e) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters/base.rb
app/models/data_source_adapters/base.rb
module DataSourceAdapters class Base def initialize(data_source) @data_source = data_source end def fetch_schema_names raise NotImplementedError end def fetch_table_names raise NotImplementedError end def fetch_columns(table) raise NotImplementedError end def fetch_view_query(view) nil end def fetch_view_query_plan(query) raise NotImplementedError end def reset! raise NotImplementedError end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters/presto_adapter.rb
app/models/data_source_adapters/presto_adapter.rb
require 'presto-client' module DataSourceAdapters class PrestoAdapter < StandardAdapter DataSourceAdapters.register_adapter(self, 'presto') def fetch_table_names schemas = run_query('show schemas')[1].flatten schemas.flat_map do |schema| run_query("show tables from #{schema}")[1].flatten.map { |table| [schema, table] } end end def fetch_columns(table) columns = run_query("show columns from #{table.full_table_name}") columns[1].map do |column| # e.g. ["updated_at", "timestamp", "", ""] Column.new(column[0], column[1], '', true); end end def reset! @client = nil end private def client @client ||= Presto::Client.new(connection_config) end def connection_config { catalog: @data_source.dbname, server: "#{@data_source.host}:#{@data_source.port}", user: @data_source.user, password: @data_source.password.presence, }.compact end def run_query(query) Rails.logger.info "Run Query: #{query}" client.run(query) rescue Presto::Client::PrestoError => e raise DataSource::ConnectionBad.new(e) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters/redshift_adapter.rb
app/models/data_source_adapters/redshift_adapter.rb
module DataSourceAdapters class RedshiftAdapter < StandardAdapter def fetch_schema_names @schema_names ||= exec_query(<<~SQL) SELECT nspname as schema_name, usename as owner_name FROM pg_catalog.pg_namespace s join pg_catalog.pg_user u on u.usesysid = s.nspowner WHERE usename != 'rdsdb' ORDER BY schema_name; SQL end def fetch_table_names query_result = exec_query(<<~SQL) SELECT table_schema, table_name, table_type FROM ( SELECT table_schema, table_name, table_type FROM svv_tables UNION SELECT DISTINCT view_schema, view_name, 'LATE BINDING' FROM pg_get_late_binding_view_cols() cols(view_schema name, view_name name, col_name name, col_type varchar, col_num int) ) tables WHERE table_schema not in ('pg_catalog', 'information_schema') ORDER BY table_schema, table_name; SQL table_groups = group_by_table_type(query_result) @base_table_names = table_groups['BASE TABLE'] || [] @external_table_names = table_groups['EXTERNAL TABLE'] || [] @view_names = table_groups['VIEW'] || [] @late_binding_view_names = table_groups['LATE BINDING'] || [] (@base_table_names + @external_table_names + @view_names + @late_binding_view_names).uniq rescue PG::Error => e raise DataSource::ConnectionBad.new(e) end def fetch_columns(table) query = <<~SQL SELECT column_name, data_type, column_default, is_nullable, character_maximum_length FROM svv_columns WHERE table_schema = '#{table.schema_name}' and table_name = '#{table.table_name}' ORDER BY ordinal_position; SQL exec_query(query).map do |name, sql_type, default, nullable, char_length| is_nullable = if spectrum?(table) # FIXME: could not get nullable info from Spectrum table true else # is_nullable column in svv_columns contains 'YES' or 'NO' or null. # It must be correctly converted to a boolean. case nullable when 'YES' true when 'NO' false else false end end column_type = sql_type == 'character varying' ? "varchar(#{char_length})" : sql_type Column.new(name, column_type, default.nil? ? 'NULL' : default, is_nullable) end rescue PG::Error => e raise DataSource::ConnectionBad.new(e) end def fetch_view_query(table) return nil unless view?(table) exec_query(<<~SQL).join("\n") SELECT definition FROM pg_views WHERE schemaname = '#{table.schema_name}' and viewname = '#{table.table_name}'; SQL end def fetch_view_query_plan(query) return nil if query.blank? # to explain, extract of select statement from view query without 'with no schema binding' query = query.match(/select(.|\n)+/i)[0].sub(/\)? ?with no schema binding/, '') exec_query("EXPLAIN #{query}").join("\n") end def reset! # We don't use any transactions for Redshift, so it's enough to just remove the source base class. DynamicTable.send(:remove_const, source_base_class_name) if DynamicTable.const_defined?(source_base_class_name) end private def connection_config { host: @data_source.host, port: @data_source.port, dbname: @data_source.dbname, user: @data_source.user, password: @data_source.password, client_encoding: @data_source.encoding, }.compact end def connection @connection ||= PG.connect(connection_config) end def exec_query(query) Rails.logger.info(query) connection.exec(query).values end def group_by_table_type(records) records.group_by { |r| r[2] }.map { |k, v| [k, reject_table_type(v)] }.to_h end def reject_table_type(records) records.map { |r| [r[0], r[1]] } end def spectrum?(table) raise "@external_table_names must be defined, execute fetch_table befor spectrum?" unless instance_variable_defined?(:@external_table_names) @external_table_names.include?(table.full_table_name.split('.')) end def view?(table) base_view?(table) || late_binding_view?(table) end def base_view?(table) raise "@view_names must be defined, execute fetch_table befor view?" unless instance_variable_defined?(:@view_names) @view_names.include?(table.full_table_name.split('.')) end def late_binding_view?(table) raise "@late_binding_view_names must be defined, execute fetch_table befor late_binding_view?" unless instance_variable_defined?(:@late_binding_view_names) @late_binding_view_names.include?(table.full_table_name.split('.')) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters/column.rb
app/models/data_source_adapters/column.rb
module DataSourceAdapters Column = Struct.new(:name, :sql_type, :default, :null) end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/models/data_source_adapters/dynamic_table.rb
app/models/data_source_adapters/dynamic_table.rb
module DataSourceAdapters module DynamicTable class AbstractTable < ApplicationRecord self.abstract_class = true end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/batches/import_table_definitions.rb
app/batches/import_table_definitions.rb
class ImportTableDefinitions def self.run(data_source_name, schema_name, table_name) Rails.logger.info "[Start] Import definition of #{schema_name}.#{table_name} table in #{data_source_name}" data_source = DataSource.find_by(name: data_source_name) source_table = data_source.data_source_tables.find { |dst| dst.full_table_name == "#{schema_name}.#{table_name}" } schema_memo = data_source.database_memo.schema_memos.find_by!(name: schema_name, linked: true) table_memo = schema_memo.table_memos.find_or_create_by!(name: table_name) if source_table.nil? Rails.logger.info "Not found #{schema_name}.#{table_name} in #{data_source_name}" table_memo.linked = false else table_memo.linked = true begin import_column_memos!(source_table, table_memo) rescue DataSource::ConnectionBad => e Rails.logger.error e end end table_memo.save! if table_memo.has_changes_to_save? Rails.logger.info "[Update] #{schema_name}.#{table_name} table" if table_memo.saved_changes? Rails.logger.info "[Finish] Imported definition" end def self.import_column_memos!(source_table, table_memo) column_memos = table_memo.column_memos.to_a columns = source_table.columns column_names = columns.map(&:name) column_memos.reject { |memo| column_names.include?(memo.name) }.each { |memo| memo.update!(linked: false) } columns.each_with_index do |column, position| column_memo = column_memos.find { |memo| memo.name == column.name } || table_memo.column_memos.build(name: column.name) column_memo.linked = true column_memo.assign_attributes(sql_type: column.sql_type, default: column.default, nullable: column.null, position:) column_memo.save! if column_memo.has_changes_to_save? Rails.logger.info "[Update Column] #{column_memo.name} column" if column_memo.saved_changes? end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/batches/synchronize_definitions.rb
app/batches/synchronize_definitions.rb
class SynchronizeDefinitions def self.run Rails.logger.info "[Start] Synchronized definition" DataSource.all.find_each do |data_source| ImportDataSourceDefinitions.run(data_source.name) end Rails.logger.info "[Finish] Synchronized definition" end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/batches/import_schema_definitions.rb
app/batches/import_schema_definitions.rb
class ImportSchemaDefinitions def self.run(data_source_name, schema_name) Rails.logger.info "[Start] Import definition of #{schema_name} schema in #{data_source_name}" data_source = DataSource.find_by(name: data_source_name) source_tables = data_source.data_source_tables.select { |table| table.schema_name == schema_name } schema_memo = data_source.database_memo.schema_memos.find_by!(name: schema_name, linked: true) table_memos = schema_memo.table_memos table_memos.each { |memo| memo.linked = false } if source_tables.empty? schema_memo.linked = false else self.import_table_memos!(source_tables, table_memos) end table_memos.each { |memo| memo.save! if memo.has_changes_to_save? } schema_memo.save! if schema_memo.has_changes_to_save? Rails.logger.info "[Update] #{schema_name} schema" if schema_memo.saved_changes? Rails.logger.info "[Finish] Imported definition" end def self.import_table_memos!(source_tables, table_memos) source_tables.each do |source_table| table_memo = table_memos.find_or_create_by!(name: source_table.table_name) table_memo.update!(linked: true) begin ImportTableDefinitions.import_column_memos!(source_table, table_memo) rescue DataSource::ConnectionBad => e Rails.logger.error e end end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/batches/import_data_source_definitions.rb
app/batches/import_data_source_definitions.rb
class ImportDataSourceDefinitions def self.run(data_source_name) Rails.logger.info "[Start] Import dataset in #{data_source_name}" data_source = DataSource.find_by(name: data_source_name) data_source_tables = data_source.data_source_tables db_memo = DatabaseMemo.find_or_create_by!(name: data_source.name) schema_memos = db_memo.schema_memos linked_schema_names = schema_memos.where(linked: true).pluck(:name) schema_memos.each { |memo| memo.linked = false } all_table_memos = schema_memos.map(&:table_memos).map(&:to_a).flatten all_table_memos.each { |memo| memo.linked = false } data_source_tables.group_by(&:schema_name).each do |schema_name, source_tables| next unless linked_schema_names.include?(schema_name) schema_memo = schema_memos.find { |memo| memo.name == schema_name } next if schema_memo.nil? schema_memo.linked = true begin ImportSchemaDefinitions.import_table_memos!(source_tables, schema_memo.table_memos) rescue DataSource::ConnectionBad => e Rails.logger.error e end end schema_memos.each { |memo| memo.save! if memo.has_changes_to_save? } db_memos.save! if db_memo.has_changes_to_save? Rails.logger.info "[Finish] Imported dataset" end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/app/batches/synchronize_data_sources.rb
app/batches/synchronize_data_sources.rb
class SynchronizeDataSources def self.run Rails.logger.warn 'SynchronizeDataSources is deprecated. Please consider using ImportDataSourceDefinitions instead.' DataSource.all.find_each do |data_source| import_data_source!(data_source) end end def self.import_data_source!(data_source) db_memo = DatabaseMemo.find_or_create_by!(name: data_source.name) schema_memos = db_memo.schema_memos.includes(table_memos: :column_memos).to_a schema_memos.each { |memo| memo.linked = false } all_table_memos = schema_memos.map(&:table_memos).map(&:to_a).flatten all_table_memos.each { |memo| memo.linked = false } data_source_tables = data_source.data_source_tables data_source_tables.group_by(&:schema_name).each do |schema_name, source_tables| schema_memo = schema_memos.find { |memo| memo.name == schema_name } || db_memo.schema_memos.create!(name: schema_name ) schema_memo.linked = true table_memos = all_table_memos.select { |memo| memo.schema_memo_id == schema_memo.id } source_tables.each do |source_table| begin import_table_memo!(schema_memo, table_memos, source_table) rescue DataSource::ConnectionBad => e Rails.logger.error e end end end schema_memos.each { |memo| memo.save! if memo.changed? } all_table_memos.each { |memo| memo.save! if memo.changed? } end def self.import_table_memo!(schema_memo, table_memos, source_table) table_name = source_table.table_name table_memo = table_memos.find { |memo| memo.name == table_name } || schema_memo.table_memos.create!(name: table_name ) table_memo.linked = true column_memos = table_memo.column_memos.to_a columns = source_table.columns import_view_query!(table_memo, source_table) column_names = columns.map(&:name) column_memos.reject { |memo| column_names.include?(memo.name) }.each { |memo| memo.update!(linked: false) } columns.each_with_index do |column, position| column_memo = column_memos.find { |memo| memo.name == column.name } || table_memo.column_memos.build(name: column.name) column_memo.linked = true column_memo.assign_attributes(sql_type: column.sql_type, default: column.default, nullable: column.null, position:) column_memo.save! if column_memo.changed? end table_memo.save! if table_memo.changed? end private_class_method :import_table_memo! def self.import_view_query!(table_memo, source_table) return unless source_table.data_source.adapter.is_a?(DataSourceAdapters::RedshiftAdapter) query = source_table.fetch_view_query if query query_plan = source_table.fetch_view_query_plan ViewMetaDatum.find_or_initialize_by(table_memo_id: table_memo.id) do |meta_data| meta_data.query = query meta_data.explain = query_plan || 'explain error' meta_data.save end end end private_class_method :import_view_query! end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/db/seeds.rb
db/seeds.rb
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first)
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/db/scripts/20160628_add_schema_memos.rb
db/scripts/20160628_add_schema_memos.rb
# Add schema_memos # # - Create table schema_memos # - Drop column table_memos.database_memo_id # - Add column table_memos.schema_memo_id # - Cleanup existing table_memos records con = DatabaseMemo.connection exit if con.table_exists?("schema_memos") con.transaction do con.create_table "schema_memos", force: :cascade do |t| t.integer "database_memo_id", null: false t.string "name", null: false t.text "description", default: "", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end con.add_index "schema_memos", ["database_memo_id", "name"], name: "uniq_schema_name", unique: true, using: :btree con.remove_index "table_memos", name: "uniq_table_name" con.add_column "table_memos", "schema_memo_id", :integer, after: :id DatabaseMemo.find_each do |database_memo| connection = database_memo.data_source.source_base_class.connection table_names = case connection when ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, ActiveRecord::ConnectionAdapters::RedshiftAdapter connection.query(<<~SQL, 'SCHEMA') SELECT schemaname, tablename FROM ( SELECT schemaname, tablename FROM pg_tables WHERE schemaname = ANY (current_schemas(false)) UNION SELECT schemaname, viewname AS tablename FROM pg_views WHERE schemaname = ANY (current_schemas(false)) ) tables ORDER BY schemaname, tablename; SQL else connection.tables.map {|table_name| ["_", table_name] } end TableMemo.where(database_memo_id: database_memo.id).find_each do |table_memo| schema_name, _ = table_names.find {|_, table| table == table_memo.name } # delete unlinked table memo unless connection.table_exists?(table_memo.name) table_memo.destroy! next end schema_memo = database_memo.schema_memos.find_by(name: schema_name) || database_memo.schema_memos.create!(name: schema_name) table_memo.update!(schema_memo_id: schema_memo.id) end end con.change_column "table_memos", "schema_memo_id", :integer, null: false con.remove_column "table_memos", "database_memo_id" con.add_index "table_memos", ["schema_memo_id", "name"], name: "uniq_table_name", unique: true, using: :btree end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/rails_helper.rb
spec/rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'spec_helper' require 'rspec/rails' require 'capybara/rails' require 'capybara/rspec' require "rack_session_access/capybara" # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are # run as spec files by default. This means that files in spec/support that end # in _spec.rb will both be required and run as specs, causing the specs to be # run twice. It is recommended that you do not name files matching this glob to # end with _spec.rb. You can configure this pattern with the --pattern # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. # # The following line is provided for convenience purposes. It has the downside # of increasing the boot-up time by auto-requiring all files in the support # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } RSpec.configure do |config| config.use_transactional_fixtures = false # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and # `post` in specs under `spec/controllers`. # # You can disable this behaviour by removing the line below, and instead # explicitly tag your specs with their type, e.g.: # # RSpec.describe UsersController, :type => :controller do # # ... # end # # The different available types are documented in the features, such as in # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") config.before(:suite) do DatabaseRewinder.clean_all end config.after(:each) do DataSource.all.each do |ds| ds.data_source_adapter.reset! end DatabaseRewinder.clean end end Dir.glob("spec/spec_helpers/*_helper.rb") do |path| require_relative path.sub(%r(^spec/), "") end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/spec_helper.rb
spec/spec_helper.rb
if ENV["COVERAGE"] require "simplecov" SimpleCov.start("rails") end # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause # this file to always be loaded, without a need to explicitly require it in any # files. # # Given that it is always loaded, you are encouraged to keep this file as # light-weight as possible. Requiring heavyweight dependencies from this file # will add to the boot time of your test suite on EVERY test run, even for an # individual file that may not need all of that loaded. Instead, consider making # a separate helper file that requires the additional dependencies and performs # the additional setup, and require it from the spec files that actually need # it. # # The `.rspec` file also contains a few flags that are not defaults but that # users commonly want. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. config.expect_with :rspec do |expectations| # This option will default to `true` in RSpec 4. It makes the `description` # and `failure_message` of custom matchers include text for helper methods # defined using `chain`, e.g.: # be_bigger_than(2).and_smaller_than(4).description # # => "be bigger than 2 and smaller than 4" # ...rather than: # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end # rspec-mocks config goes here. You can use an alternate test double # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| # Prevents you from mocking or stubbing a method that does not exist on # a real object. This is generally recommended, and will default to # `true` in RSpec 4. mocks.verify_partial_doubles = true end # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. =begin # These two settings work together to allow you to limit a spec run # to individual examples or groups you care about by tagging them with # `:focus` metadata. When nothing is tagged with `:focus`, all examples # get run. config.filter_run :focus config.run_all_when_everything_filtered = true # Allows RSpec to persist some state between runs in order to support # the `--only-failures` and `--next-failure` CLI options. We recommend # you configure your source control system to ignore this file. config.example_status_persistence_file_path = "spec/examples.txt" # Limits the available syntax to the non-monkey patched syntax that is # recommended. For more details, see: # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode config.disable_monkey_patching! # Many RSpec users commonly either run the entire suite or an individual # file, and it's useful to allow more verbose output when running an # individual spec file. if config.files_to_run.one? # Use the documentation formatter for detailed output, # unless a formatter has already been configured # (e.g. via a command-line flag). config.default_formatter = 'doc' end # Print the 10 slowest examples and example groups at the # end of the spec run, to help surface which specs are running # particularly slow. config.profile_examples = 10 # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = :random # Seed global randomization in this process using the `--seed` CLI option. # Setting this allows you to use `--seed` to deterministically reproduce # test failures related to randomization by passing the same `--seed` value # as the one that triggered the failure. Kernel.srand config.seed =end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/database_memos_spec.rb
spec/requests/database_memos_spec.rb
require "rails_helper" describe :database_memos, type: :request do let(:database_memo) { FactoryBot.create(:database_memo) } before do login! end describe "#index" do it "redirects" do get database_memos_path expect(response).to redirect_to(root_path) end end describe "#show" do it "shows memo" do get database_memo_path(database_memo.name) expect(response).to render_template("database_memos/show") expect(page).to have_content(database_memo.name) end context "with id param" do it "redirects" do get database_memo_path(database_memo.id) expect(response).to redirect_to(database_memo_path(database_memo.name)) end end end describe "#edit" do it "shows form" do get edit_database_memo_path(database_memo) expect(response).to render_template("database_memos/edit") expect(page).to have_content(database_memo.name) end end describe "#update" do it "updates memo" do patch database_memo_path(database_memo), params: { database_memo: { description: "foo description" } } expect(response).to redirect_to(database_memo_path(database_memo.name)) expect(assigns(:database_memo).description).to eq("foo description") end end describe "#destroy" do it "destroys memo" do delete database_memo_path(database_memo) expect(response).to redirect_to(root_path) expect { DatabaseMemo.find(database_memo.id) }.to raise_error(ActiveRecord::RecordNotFound) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/ignored_tables_spec.rb
spec/requests/ignored_tables_spec.rb
require "rails_helper" describe :ignored_tables, type: :request do let(:user) { FactoryBot.create(:user, admin: true) } before do login!(user:) end describe "#index" do it "redirects" do get ignored_tables_path expect(response).to redirect_to(setting_path) end end describe "#show" do let!(:ignored_table) { FactoryBot.create(:ignored_table) } it "redirects" do get ignored_table_path(ignored_table) expect(response).to redirect_to(setting_path) end end describe "#new" do let!(:data_source) { FactoryBot.create(:data_source) } it "shows form" do get new_ignored_table_path expect(response).to render_template("ignored_tables/new") expect(page).to have_xpath("//option[text()='#{data_source.name}']") end end describe "#create" do let(:data_source) { FactoryBot.create(:data_source) } it "creates ignored_table" do post ignored_tables_path, params: { ignored_table: { data_source_id: data_source.id, pattern: "foo" } } expect(response).to redirect_to(setting_path) expect(assigns(:ignored_table).pattern).to eq("foo") end context "with empty pattern" do it "shows error" do post ignored_tables_path, params: { ignored_table: { data_source_id: data_source.id, pattern: "" } } expect(response).to redirect_to(new_ignored_table_path) expect(flash[:error]).to include("Pattern") end end end describe "#destroy" do let(:ignored_table) { FactoryBot.create(:ignored_table) } it "deletes ignored_table" do delete ignored_table_path(ignored_table) expect(response).to redirect_to(setting_path) expect(IgnoredTable.find_by(id: ignored_table.id)).to eq(nil) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/keyword_logs_spec.rb
spec/requests/keyword_logs_spec.rb
require "rails_helper" describe :keyword_logs, type: :request do let(:memo_log) { FactoryBot.create(:keyword_log) } let(:memo) { memo_log.keyword } before do login! end describe "#index" do it "shows" do get keyword_logs_path(memo.id) expect(response).to render_template("keyword_logs/index") expect(page).to have_content(memo.name) expect(page).to have_content(memo_log.description_diff) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/favorite_tables_spec.rb
spec/requests/favorite_tables_spec.rb
require "rails_helper" describe :favorite_tables, type: :request do let(:user) { FactoryBot.create(:user) } let(:table_memo) { FactoryBot.create(:table_memo) } before do login!(user:) end describe "#create" do it "creates favorite table" do post table_memo_favorite_table_path(table_memo), as: :json expect(response).to render_template("favorite_tables/create") favorite_table = FavoriteTable.find(JSON.parse(response.body)["id"]) expect(favorite_table.user).to eq(user) expect(favorite_table.table_memo).to eq(table_memo) end end describe "#destroy" do before do FactoryBot.create(:favorite_table, user:, table_memo:) end it "destroys favorite table" do delete table_memo_favorite_table_path(table_memo), as: :json expect(response).to render_template("favorite_tables/destroy") expect(FavoriteTable.count).to eq(0) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/schema_memos_spec.rb
spec/requests/schema_memos_spec.rb
require "rails_helper" describe :schema_memos, type: :request do let(:schema_memo) { FactoryBot.create(:schema_memo) } let(:database_memo) { schema_memo.database_memo } before do login! end describe "#show" do context "with multiple schemas" do before do FactoryBot.create(:schema_memo, database_memo:) end it "shows memo" do get database_schema_path(database_memo.name, schema_memo.name) expect(response).to render_template("schema_memos/show") expect(page).to have_content(schema_memo.name) end end context "with single schema" do it "redirects" do get database_schema_path(database_memo.name, schema_memo.name) expect(response).to redirect_to(database_memo_path(database_memo.name)) end end context "with id param" do it "redirects" do get schema_memo_path(schema_memo.id) expect(response).to redirect_to(database_schema_path(database_memo.name, schema_memo.name)) end end end describe "#edit" do it "shows form" do get edit_schema_memo_path(schema_memo) expect(response).to render_template("schema_memos/edit") expect(page).to have_content(schema_memo.name) end end describe "#update" do it "updates memo" do patch schema_memo_path(schema_memo), params: { schema_memo: { description: "foo description" } } expect(response).to redirect_to(database_schema_path(database_memo.name, schema_memo.name)) expect(assigns(:schema_memo).description).to eq("foo description") end end describe "#destroy" do it "destroys memo" do delete schema_memo_path(schema_memo) expect(response).to redirect_to(database_memo_path(schema_memo.database_memo.name)) expect { SchemaMemo.find(schema_memo.id) }.to raise_error(ActiveRecord::RecordNotFound) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/top_spec.rb
spec/requests/top_spec.rb
require "rails_helper" describe :top, type: :request do before do FactoryBot.create(:data_source) SynchronizeDataSources.run login! end describe "#show" do it "shows top page" do get root_path expect(page).to have_content("DatabaseMEMO") expect(page).to have_selector("a[href='/databases/dmemo']") end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/column_memo_logs_spec.rb
spec/requests/column_memo_logs_spec.rb
require "rails_helper" describe :column_memo_logs, type: :request do let(:memo_log) { FactoryBot.create(:column_memo_log) } let(:memo) { memo_log.column_memo } before do login! end describe "#index" do it "shows" do get column_memo_logs_path(memo.id) expect(response).to render_template("column_memo_logs/index") expect(page).to have_content(memo_log.description_diff) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/column_memos_spec.rb
spec/requests/column_memos_spec.rb
require "rails_helper" describe :column_memos, type: :request do let(:column_memo) { FactoryBot.create(:column_memo) } let(:table_memo) { column_memo.table_memo } let(:schema_memo) { table_memo.schema_memo } let(:database_memo) { schema_memo.database_memo } before do login! end describe "#show" do it "redirects table_memo" do get column_memo_path(column_memo) expect(response).to redirect_to(table_memo_path(table_memo)) end end describe "#edit" do it "shows form" do get edit_column_memo_path(column_memo) expect(response).to render_template("column_memos/edit") expect(page).to have_content(column_memo.description) end end describe "#update" do it "updates memo" do patch column_memo_path(column_memo), params: { column_memo: { description: "foo description" } } expect(response).to redirect_to(redirect_to database_schema_table_path(database_memo.name, schema_memo.name, table_memo.name)) expect(assigns(:column_memo).description).to eq("foo description") end end describe "#destroy" do it "destroys memo" do delete column_memo_path(column_memo) expect(response).to redirect_to(table_memo_path(column_memo.table_memo_id)) expect { ColumnMemo.find(column_memo.id) }.to raise_error(ActiveRecord::RecordNotFound) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/data_sources_spec.rb
spec/requests/data_sources_spec.rb
require "rails_helper" describe :data_sources, type: :request do before do login!(admin: true) end describe "#index" do it "redirects" do get data_sources_path expect(response).to redirect_to(setting_path) end end describe "#show" do let(:data_source) { FactoryBot.create(:data_source) } it "redirects" do get data_source_path(data_source) expect(response).to redirect_to(setting_path) end end describe "#new" do it "shows form" do get new_data_source_path expect(response).to render_template("data_sources/new") end end describe "#create" do let(:data_source_param) { { name: "dmemo", description: "", adapter: "postgresql", host: "localhost", port: 5432, dbname: "dmemo_test", user: "postgres" } } it "creates data_source and related memos" do post data_sources_path, params: { data_source: data_source_param } data_source = assigns(:data_source) expect(data_source).to be_present expect(response).to redirect_to(data_sources_path) end context "with empty name" do before do data_source_param[:name] = "" end it "shows error" do post data_sources_path, params: { data_source: data_source_param } expect(response).to redirect_to(new_data_source_path) expect(flash[:error]).to include("Name") end end context "with bigquery adapter" do before do data_source_param[:adapter] = "bigquery" data_source_param[:bigquery_config] = { project_id: "sample", dataset: "public" } end it "creates data_source and bigquery config" do post data_sources_path, params: { data_source: data_source_param } data_source = assigns(:data_source) expect(data_source.bigquery_config).to be_present end end end describe "#edit" do let!(:data_source) { FactoryBot.create(:data_source) } let!(:database_memo) { FactoryBot.create(:database_memo, data_source:, name: "db") } let!(:schema_memo) { FactoryBot.create(:schema_memo, database_memo:, name: "myapp") } it "shows form" do get edit_data_source_path(data_source) expect(response).to render_template("data_sources/edit") expect(page).to have_xpath("//input[@id='data_source_name'][@value='#{data_source.name}']") end end describe "#update" do let(:data_source) { FactoryBot.create(:data_source) } it "updates data_source" do patch data_source_path(data_source.id), params: { data_source: { description: "hello" } } expect(data_source.id).to eq(assigns(:data_source).id) expect(response).to redirect_to(data_sources_path) expect(assigns(:data_source).description).to eq("hello") end context "with empty name" do it "shows error" do patch data_source_path(data_source.id), params: { data_source: { name: "" } } expect(response).to redirect_to(edit_data_source_path(data_source.id)) expect(flash[:error]).to include("Name") end end context "with bigquery adapter" do let(:data_source) { FactoryBot.create(:data_source) } it "creates data_source and bigquery config" do patch data_source_path(data_source.id), params: { data_source: { adapter: "bigquery", bigquery_config: { project_id: "new_project" } } } data_source = assigns(:data_source) expect(data_source.bigquery_config.project_id).to eq "new_project" end end end describe "#destroy" do let(:data_source) { FactoryBot.create(:data_source) } it "deletes data_source" do delete data_source_path(data_source) expect(response).to redirect_to(data_sources_path) expect(DataSource.find_by(id: data_source.id)).to eq(nil) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/users_spec.rb
spec/requests/users_spec.rb
require "rails_helper" describe :users, type: :request do let(:user) { FactoryBot.create(:user) } before do login!(user:) end describe "#index" do it "shows index" do get users_path expect(response).to render_template("users/index") expect(page).to have_text(user.name) end end describe "#edit" do it "shows form" do get edit_user_path(user) expect(response).to render_template("users/edit") expect(page).to have_text(user.name) expect(page).not_to have_css("input#user_admin") end context "with admin" do let(:user) { FactoryBot.create(:user, admin: true) } let(:another_user) { FactoryBot.create(:user) } it "shows another user form" do get edit_user_path(another_user) expect(response).to render_template("users/edit") expect(page).to have_text(user.name) expect(page).to have_css("input#user_admin") end end context "with another user" do let(:user) { FactoryBot.create(:user) } let(:another_user) { FactoryBot.create(:user) } it "returns 401" do get edit_user_path(another_user) expect(response).to have_http_status(401) end end end describe "#update" do it "updates user" do patch user_path(user), params: { user: { name: "foo" } } expect(response).to redirect_to(edit_user_path(user)) expect(user.reload.name).to eq("foo") end context "with admin" do let(:user) { FactoryBot.create(:user, admin: true) } let(:another_user) { FactoryBot.create(:user) } it "updates another user" do patch user_path(another_user), params: { user: { name: "foo", admin: true } } expect(response).to redirect_to(edit_user_path(another_user)) expect(another_user.reload.name).to eq("foo") expect(another_user.admin).to eq(true) end end context "with another user" do let(:user) { FactoryBot.create(:user) } let(:another_user) { FactoryBot.create(:user) } it "returns 401" do patch user_path(another_user), params: { user: { name: "foo" } } expect(response).to have_http_status(401) end end context "with normal user" do let(:user) { FactoryBot.create(:user) } it "cannot update admin column" do patch user_path(user), params: { user: { admin: true } } expect(response).to have_http_status(401) end end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/settings_spec.rb
spec/requests/settings_spec.rb
require "rails_helper" describe :settings, type: :request do let(:user) { FactoryBot.create(:user) } let(:data_source) { FactoryBot.create(:data_source, name: "test_ds") } let!(:ignored_table) { FactoryBot.create(:ignored_table, data_source:) } before do login!(user:) end describe "#show" do it "shows settings" do get setting_path expect(response).to render_template("settings/show") expect(page).to have_xpath("//*[@class='container-data_sources']//*[contains(text(), 'test_ds')]") expect(page).to have_xpath("//*[@class='container-ignored_tables']//*[contains(text(), 'test_ds')]") expect(page).not_to have_xpath("//a[@href='#{data_source_path(data_source)}']") expect(page).not_to have_xpath("//a[@href='#{ignored_table_path(ignored_table)}']") end context "with admin user" do let(:user) { FactoryBot.create(:user, admin: true) } it "shows admin buttons" do get setting_path expect(response).to render_template("settings/show") expect(page).to have_xpath("//*[@class='container-data_sources']//*[contains(text(), 'test_ds')]") expect(page).to have_xpath("//*[@class='container-ignored_tables']//*[contains(text(), 'test_ds')]") expect(page).to have_xpath("//a[@href='#{data_source_path(data_source)}']") expect(page).to have_xpath("//a[@href='#{ignored_table_path(ignored_table)}']") end end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/markdown_previews_spec.rb
spec/requests/markdown_previews_spec.rb
require "rails_helper" describe :markdown_previews, type: :request do describe "#create" do before do login! end it "creates markdown preview" do post markdown_preview_path(md: "**hoge**"), as: :json expect(response).to render_template("markdown_previews/create") data = JSON.parse(response.body) expect(data["html"]).to be_include("<strong>hoge</strong>") end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/sessions_spec.rb
spec/requests/sessions_spec.rb
require "rails_helper" describe :sessions, type: :request do describe "#create" do let(:oauth) { { provider: "google_oauth2", uid: 1, info: { name: "foo", email: "foo@example.com", image: "foo.jpg" } } } before do OmniAuth.config.test_mode = true OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new(oauth) end it "creates user and session" do expect(User.count).to eq(0) get auth_google_oauth2_callback_path expect(response).to redirect_to(root_path) expect(User.find(session[:user_id]).name).to eq(oauth[:info][:name]) end context "with existing user" do let(:user) { FactoryBot.create(:user) } before do oauth[:uid] = user.uid OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new(oauth) end it "creates only session" do expect(User.count).to eq(1) get auth_google_oauth2_callback_path expect(response).to redirect_to(root_path) expect(User.find(session[:user_id]).name).to eq(oauth[:info][:name]) expect(User.count).to eq(1) end end end describe "#destroy" do before do login! end it "destroys session" do expect(session[:user_id]).not_to eq(nil) delete logout_path expect(response).to redirect_to(root_path) expect(session[:user_id]).to eq(nil) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/schema_memo_logs_spec.rb
spec/requests/schema_memo_logs_spec.rb
require "rails_helper" describe :schema_memos, type: :request do let(:memo_log) { FactoryBot.create(:schema_memo_log) } let(:memo) { memo_log.schema_memo } before do login! end describe "#index" do it "shows" do get schema_memo_logs_path(memo.id) expect(response).to render_template("schema_memo_logs/index") expect(page).to have_content(memo.name) expect(page).to have_content(memo_log.description_diff) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/database_memo_logs_spec.rb
spec/requests/database_memo_logs_spec.rb
require "rails_helper" describe :database_memo_logs, type: :request do let(:memo_log) { FactoryBot.create(:database_memo_log) } let(:memo) { memo_log.database_memo } before do login! end describe "#index" do it "shows" do get database_memo_logs_path(memo.id) expect(response).to render_template("database_memo_logs/index") expect(page).to have_content(memo.name) expect(page).to have_content(memo_log.description_diff) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/table_memos_spec.rb
spec/requests/table_memos_spec.rb
require "rails_helper" describe :table_memos, type: :request do let(:table_memo) { FactoryBot.create(:table_memo) } let(:schema_memo) { table_memo.schema_memo } let(:database_memo) { schema_memo.database_memo } before do login! end describe "#show" do let!(:data_source) { FactoryBot.create(:data_source) } let(:database_memo) { data_source.database_memo } let(:schema_memo) { database_memo.schema_memos.take! } let(:table_memo) { schema_memo.table_memos.find_by!(name: "data_sources") } before do SynchronizeDataSources.run end it "shows table memo" do get database_schema_table_path(database_memo.name, schema_memo.name, table_memo.name) expect(response).to render_template("table_memos/show") expect(table_memo).to eq(assigns(:table_memo)) end context "with id param" do it "redirects to named path" do get table_memo_path(table_memo.id) expect(page).to redirect_to(database_schema_table_path(database_memo.name, schema_memo.name, table_memo.name)) end end end describe "#edit" do it "shows table memo form" do get edit_table_memo_path(table_memo) expect(response).to render_template("table_memos/edit") expect(table_memo).to eq(assigns(:table_memo)) end end describe "#update" do it "updates table memo" do patch table_memo_path(table_memo), params: { table_memo: { description: "foo description" } } expect(response).to redirect_to(database_schema_table_path(table_memo.database_memo.name, table_memo.schema_memo.name, table_memo.name)) expect(assigns(:table_memo).description).to eq("foo description") end end describe "#destroy" do it "destroys table memo" do delete table_memo_path(table_memo) expect(response).to redirect_to(database_memo_path(table_memo.database_memo.name)) expect { TableMemo.find(table_memo.id) }.to raise_error(ActiveRecord::RecordNotFound) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/table_memo_logs_spec.rb
spec/requests/table_memo_logs_spec.rb
require "rails_helper" describe :table_memo_logs, type: :request do let(:memo_log) { FactoryBot.create(:table_memo_log) } let(:memo) { memo_log.table_memo } before do login! end describe "#index" do it "shows" do get table_memo_logs_path(memo.id) expect(response).to render_template("table_memo_logs/index") expect(page).to have_content(memo.name) expect(page).to have_content(memo_log.description_diff) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/keywords_spec.rb
spec/requests/keywords_spec.rb
require "rails_helper" describe :keywords, type: :request do before do login! end describe "#index" do before do FactoryBot.create(:keyword, name: "sushi", description: "**delicious**") FactoryBot.create(:keyword, name: "toast", description: "__rice__") end it "shows index" do get keywords_path expect(response).to render_template("keywords/index") # shows keyword links expect(page).to have_xpath("//a[text()='sushi']") expect(page).to have_xpath("//a[text()='toast']") # shows striped plain text description expect(page).to have_xpath("//td[text()='delicious']") expect(page).to have_xpath("//td[text()='rice']") end end describe "#show" do before do FactoryBot.create(:keyword, name: "sushi", description: "**delicious**") end it "shows keyword detail" do get keyword_path("sushi") expect(response).to render_template("keywords/show") expect(page).to have_text("sushi") expect(page).to have_xpath("//strong[text()='delicious']") end end describe "#new" do it "shows new page" do get new_keyword_path expect(response).to render_template("keywords/new") end end describe "#create" do it "creates keyword" do post keywords_path, params: { keyword: { name: "foo", description: "foo description" } } keyword = Keyword.find_by!(name: "foo") expect(response).to redirect_to(keyword) expect(keyword.logs.count).to eq(1) end end describe "#edit" do let(:keyword) { FactoryBot.create(:keyword, name: "sushi", description: "**delicious**") } it "shows edit form" do get edit_keyword_path(keyword) expect(response).to render_template("keywords/edit") expect(page).to have_text("sushi") expect(page).to have_text("delicious") end end describe "#update" do let(:keyword) { FactoryBot.create(:keyword, name: "sushi", description: "sushi 1") } it "updates keyword" do expect(keyword.logs.count).to eq(0) patch keyword_path(keyword), params: { keyword: { description: "sushi 2" } } expect(response).to redirect_to(keyword) expect(keyword.reload.description).to eq("sushi 2") expect(keyword.logs.count).to eq(1) end end describe "#destroy" do let(:keyword) { FactoryBot.create(:keyword, name: "sushi", description: "sushi 1") } it "destroys keyword" do delete keyword_path(keyword) expect(response).to redirect_to(keywords_path) expect(Keyword.count).to eq(0) expect(KeywordLog.count).to eq(0) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/requests/search_results_spec.rb
spec/requests/search_results_spec.rb
require "rails_helper" describe :search_results, type: :request do describe "#show" do let!(:table_memo) { FactoryBot.create(:table_memo, name: "foo_bar_table") } let!(:column_memo) { FactoryBot.create(:column_memo, name: "foo_bar_column") } before do login! end it "shows search result" do get search_results_path, params: { search_result: { keyword: "bar" } } expect(response).to render_template("search_results/show") expect(page).to have_text(table_memo.full_name) expect(page).to have_text(column_memo.full_name) end end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/factories/column_memo_log_factory.rb
spec/factories/column_memo_log_factory.rb
FactoryBot.define do factory :column_memo_log do column_memo sequence(:revision) { |n| n } user description { "# column memo" } description_diff { "+# column memo" } end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/factories/table_memo_factory.rb
spec/factories/table_memo_factory.rb
FactoryBot.define do factory :table_memo do schema_memo sequence(:name) { |n| "table#{n}" } description { "# table memo" } end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/factories/bigquery_config_factory.rb
spec/factories/bigquery_config_factory.rb
FactoryBot.define do factory :bigquery_config do project_id { 'sample-12345' } dataset { 'public' } end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/factories/table_memo_log_factory.rb
spec/factories/table_memo_log_factory.rb
FactoryBot.define do factory :table_memo_log do table_memo sequence(:revision) { |n| n } user description { "# table memo" } description_diff { "+# table memo" } end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false
cookpad/dmemo
https://github.com/cookpad/dmemo/blob/9cf312044a85c02280853d6ab95b82404dbfdeb5/spec/factories/keyword_log_factory.rb
spec/factories/keyword_log_factory.rb
FactoryBot.define do factory :keyword_log do keyword sequence(:revision) { |n| n } user description { "# keyword memo" } description_diff { "+# keyrword memo" } end end
ruby
MIT
9cf312044a85c02280853d6ab95b82404dbfdeb5
2026-01-04T17:49:09.929348Z
false