我正在尝试使用通过Teaspoon运行的Jasmine在Angular中创建一些单元测试.测试正在运行,但是我有一个简单的测试只是为了测试是否存在失败的控制器.我有以下测试设置.
//= require spec_helper
require("angular");
require("angular-mocks");
var app = require("./app");
describe("My App", function() {
describe("App Controllers", function() {
beforeEach(module("app"))
it("Should have created an application controller", inject(function($rootScope, $controller){
var scope = $rootScope.$new();
ctrl = $controller("ApplicationCtrl", { $scope: scope });
}));
})
})
Run Code Online (Sandbox Code Playgroud)
需要的语句由Browserify处理,它处理我的依赖项,但我也可以挂钩我用于规范助手的链接.
在我需要的应用程序内部
require("angular");
var controllers = require("./controllers");
var app = angular.module("app", [
"app.controllers"
]);
exports.app = app;
Run Code Online (Sandbox Code Playgroud)
当我运行此测试时,我得到以下错误
Failure/Error: TypeError: '[object Object]' is not a function (evaluating 'module("aialerts")')
Run Code Online (Sandbox Code Playgroud)
我花了很长时间试图解决这个问题,但我不知道发生了什么.任何帮助赞赏.
我在Rails 4中使用Active Admin.在我的模型中,我有一个字段是Postgres数组类型,当我创建它在后台传递的对象但它没有保存到数据库.那么我需要做什么来通过Active Admin将数组字段保存在数据库中.
谢谢
我目前在亚马逊api的结果遇到问题.
该服务返回一个包含unicode字符的字符串:在Mac上学习Objective\xE2\x80\x93C(学习系列)
使用ruby 1.9.1,甚至无法处理字符串:
REXML::ParseException: #<Encoding::CompatibilityError: incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)>
...
Exception parsing
Line: 1
Position: 1636
Last 80 unconsumed characters:
Learn Objective–C on the Mac (Learn Series)
Run Code Online (Sandbox Code Playgroud) 我想编写一个将app/services
目录添加到Rails应用程序的gem .
由于我想从Gem中添加它,我想出了这个解决方案:
class Railtie < ::Rails::Railtie
config.after_initialize do |app|
::Rails.logger.info "adding #{ActiveService::Configuration.path} to autoload_path"
app.config.autoload_paths = [ActiveService::Configuration.path] + app.config.autoload_paths
end
end
Run Code Online (Sandbox Code Playgroud)
问题是这config.autoload_path
是一个冻结的数组,因此修改它似乎不是一个好主意.
有关如何以更好的方式实现这一目标的任何建议?
我在我的查询中使用带轮胎的geo_distance
过滤器,它工作正常:
search.filter :geo_distance, :distance => "#{request.distance}km", :location => "#{request.lat},#{request.lng}"
Run Code Online (Sandbox Code Playgroud)
我希望结果会以某种方式包含我用于过滤器的地理位置的计算距离.
有没有办法告诉elasticsearch在响应中包含它,以便我不必为每个结果在ruby中计算它?
==更新==
我在谷歌小组中找到了答案:
search.sort do
by "_geo_distance", "location" => "#{request.lat},#{request.lng}", "unit" => "km" if request.with_location?
end
Run Code Online (Sandbox Code Playgroud)
按原样排序_geo_distance
会产生原始结果中的距离.
我正在运行一个在多个子域usergroupXYZ.onruby.de上运行的应用程序,并且还支持任意域作为别名.因此,您可以通过yourusergroup.onruby.de或customdomain.de访问域.
该应用程序通过twitter oauth和github oauth2提供登录.
问题是,我没有找到通过自定义域支持github auth的方法.我总是redirect_uri_mismatch
从github 得到错误.
twitter auth在重定向到其他域时没有问题.
除了为每个自定义域创建一个github应用程序令牌之外,有没有人能解决这个问题?
我一直在与Rails 4进行战斗,试图让它获取我的资产并创建正确的链接.通常,服务器重新启动和硬刷新的组合将使URL正确地通过,但并非总是如此. tmp:clear
并且assetpipeline:clobber
也不适合我.
问题在于image_path方法.我目前在自定义Form对象中,所以我这样做了:
class WalletForm
include ActionView::Helpers::AssetUrlHelper
def give_me_path
image_path("logo.jpg")
end
end
Run Code Online (Sandbox Code Playgroud)
image_path在开发和测试模式下给了我"images/logo.jpg".这应该是"assets/logo.jpg".我在过去已经注意到当rails无法找到图像时,它将使用images/logo.jpg而不是资产.我猜这是因为你把它放在管道之外的public/images文件夹中.但该文件确实存在app/assets/images
,并且位于正确的位置.(我已经复制并粘贴了文件名,我也尝试重命名该文件.我重新启动了Web服务器,重新启动了pow)我甚至预先编译了资产,RAILS_ENV=test
试图验证我的徽标是否被管道拾取, 假设
我不确定还有什么可以研究的.有什么建议?
正如这些问题所指出的,在某些情况下,iOS上的foto上传文件的地理位置和其他EXIF元数据已被删除(在野生动物园中):
https://apple.stackexchange.com/questions/326789/gps-exif-from-iphone-photo-upload-in-safari
截至目前,我还没有找到适当的情况描述。我有2台设备用于测试安装了最新iOS的设备,其中未剥离EXIF元数据。
是否有办法确定(最好是在浏览器中或从上载中)是否已删除元数据以便向用户显示某种信息?
使用delayed_job_active_record
gem版本 4 ,我想延迟对外部 API 的请求。我的工作被添加到数据库中,并rake jobs:work
运行它并将其从数据库中删除。但是,我的实际延迟代码messages_controller.rb
从未执行过。
如果我尝试Delayed::Job.last.invoke_job
在 rails 控制台中,我会收到以下错误:
Delayed::DeserializationError: Job failed to load: allocator undefined for Proc. Handler: "--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/object:MyApp::Zendesk\n client: !ruby/object:ZendeskAPI::Client\n config: !ruby/object:ZendeskAPI::Configuration\n client_options: {}\n cache: !ruby/object:ZendeskAPI::LRUCache\n size: 1000\n store: {}\n lru: []\n url: https://redacted.zendesk.com/api/v2\n username: redacted\n password: redacted\n retry: true\n logger: !ruby/object:Logger\n progname: \n level: 0\n default_formatter: !ruby/object:Logger::Formatter\n datetime_format: \n formatter: \n logdev: !ruby/object:Logger::LogDevice\n shift_size: \n shift_age: \n filename: \n dev: !ruby/object:IO {}\n mutex: !ruby/object:Logger::LogDevice::LogDeviceMutex\n mon_owner: \n mon_count: …
Run Code Online (Sandbox Code Playgroud) 我有一个用户模型=> @user
我想添加新属性current_time
以@user
供临时使用.
不想进行迁移以添加列(仅供临时使用):
@user.current_time = Time.now
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?
NoMethodError (undefined method `current_time=' for #<User:0x007fd6991e1050>):
app/controllers/carts_controller.rb:47:in `block in search_user'
app/controllers/carts_controller.rb:45:in `search_user'
Run Code Online (Sandbox Code Playgroud) 我正在用RSpec测试我的观点.由于一些变化,现在url_for
在视图中调用了我为show
动作编写的所有规范都失败了:
No route matches {:controller=>"events", :action=>"show"}
Run Code Online (Sandbox Code Playgroud)
该:id
部分缺失以及由于呼叫失败.
(我知道我可以将那个失败的方法调用存根)
我发现的唯一的东西很旧,看起来像一个糟糕的解决方法.另外,RSpec的文件没有显示什么帮助.
有没有正确的方法告诉RSpec它应该是什么样的events/123
?
更多背景:
在视图中我调用了一个帮助器,如下所示:
def some_helper_method
url_for(only_path: false)} + "something_else"
end
Run Code Online (Sandbox Code Playgroud)
对该方法的调用失败了
Failure/Error: render
ActionView::Template::Error:
No route matches {:controller=>"events", :action=>"show"}
Run Code Online (Sandbox Code Playgroud)
我正在通过对该方法的调用进行存根来修复它 view.stub(some_helper_method: 'SOME_URL')
我试图在辅助模块上编写一个rspec单元测试
我有SessionsController
和SessionsHelper
里面SessionsHelper
我有
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
session.delete(:return_to)
end
Run Code Online (Sandbox Code Playgroud)
我想做一个看起来像这样的测试:
describe "redirect_back_or(default)" do
describe "with stored location" do
before do
helper.request.path = users_path
helper.store_location
end
it do
expect(helper.redirect_back_or(user_path(@user))).to redirect_to(users_url)
helper.session[:return_to].should eq(nil)
end
end
end
Run Code Online (Sandbox Code Playgroud)
但我在Helper方法中得到一个例外
undefined method `redirect_to' for #<#<Class:0x00000006fc9940>:0x00000005322620>
# ./app/helpers/sessions_helper.rb:34:in `redirect_back_or'
# ./spec/helpers/sessions_helper_spec.rb:99:in `block (4 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud) ruby ×5
activeadmin ×1
amazon ×1
angular-mock ×1
angularjs ×1
arrays ×1
delayed-job ×1
encoding ×1
file-upload ×1
gem ×1
geolocation ×1
github-api ×1
ios ×1
load-path ×1
model ×1
multi-tenant ×1
oauth-2.0 ×1
rspec ×1
rspec-rails ×1
ruby-2.0 ×1
teaspoon ×1